blob: 8e6ed6d6782e211155fc076635d10a6b1c57b87e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
;;; ravi-init-org.el --- org initialization
;; Copyright (C) 2014
;; Author: <ravi@nero>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Org mode initialization
;;; Code:
;; This brings in emacs-zmq, which requires static libstdc++.a
(use-package jupyter
:commands (jupyter-run-server-repl
jupyter-run-repl
jupyter-server-list-kernels))
(defconst ravi/mathjax-v3-file "./MathJax/tex-chtml-full.js"
"MathJax file for v3")
(defconst ravi/mathjax-v2-file "./MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
"MathJax file for v2")
;; https://emacs.stackexchange.com/questions/20574/default-inline-image-background-in-org-mode
(defvar ravi/inline-image-background nil
"The color used as the default background for inline images.
When nil, use the default face background.")
(defun ravi/create-image-with-background-color (args)
"Specify background color of Org-mode inline image through modify `ARGS'."
(let* ((file (car args))
(type (cadr args))
(data-p (caddr args))
(props (cdddr args)))
;; Get this return result style from `create-image'.
(append (list file type data-p)
(list :background (or ravi/inline-image-background (face-background 'default)))
props)))
(advice-add 'create-image :filter-args
#'ravi/create-image-with-background-color)
(use-package org
:mode ("\\.org\\'" . org-mode)
;; The following lines are always needed. Choose your own keys.
:bind (("C-c l" . org-store-link)
("H-o" . org-capture)
("H--" . org-agenda))
:config
(use-package org-contrib)
(use-package htmlize :ensure t)
(use-package ox-reveal
:config
(setq org-reveal-slide-number nil)
(setq org-reveal-theme "night")
(setq org-reveal-transition "linear")
(setq org-reveal-mathjax t)
(setq org-reveal-mathjax-url ravi/mathjax-v3-file))
(use-package ox-rst)
(use-package ox-impress-js :disabled t)
;; Default file locations
(setq org-directory "~/Documents/org")
(defvar ravi/one-org-agenda-file (expand-file-name "agenda.files" org-directory))
(setq org-agenda-files ravi/one-org-agenda-file)
(unless (file-exists-p ravi/one-org-agenda-file)
;; http://stackoverflow.com/a/14072295/1219634
;; touch `ravi/one-org-agenda-file'
(write-region "" :ignore ravi/one-org-agenda-file))
(setq org-default-notes-file (expand-file-name "notes.org" org-directory))
(setq org-refile-targets
'((nil :maxlevel . 3)
(org-agenda-files :maxlevel . 3)))
(setq org-src-fontify-natively t)
(setq org-modules '(ol-bbdb ol-bookmark ol-git-link ol-info ol-man org-id))
(setq org-use-speed-commands t)
;; Respect theme for code block output if enabled
;; https://emacs.stackexchange.com/questions/3374/set-the-background-of-org-exported-code-blocks-according-to-theme
;; Code above was modified to
;; - use hexadecimal color values to avoid color names
;; - modify org-html-head-extra only if colors were not already present; otherwise
;; we end up appending to it on every export
(defvar ravi/org-html-code-block-parameter-set nil
"Set foreground and background for code blocks according to theme")
(defun ravi/org-inline-css-hook (exporter)
"Insert custom inline css to automatically set the
background of code according to theme"
(when (and (eq exporter 'html)
;; To do: only if htmlize is used
ravi/org-html-code-block-parameter-set)
(let* ((converter (lambda (x) (apply #'color-rgb-to-hex
(flatten-list (list (color-name-to-rgb x) 2)))))
(pre-bg (funcall converter (face-background 'default)))
(pre-fg (funcall converter (face-foreground 'default)))
(extra (format "<style type=\"text/css\">\n pre.src {background-color: %s; color: %s;}</style>\n"
pre-bg pre-fg)))
(unless (and org-html-head-extra
(string-match (regexp-quote extra) org-html-head-extra))
(set (make-local-variable 'org-html-head-extra)
(concat org-html-head-extra extra))))))
(add-hook 'org-export-before-processing-hook 'ravi/org-inline-css-hook)
(defun ravi/org-color-customization ()
"Color customization for org mode"
(setq ravi/org-html-code-block-parameter-set t)
(set (make-local-variable 'ravi/inline-image-background) "white"))
(add-hook 'org-mode-hook #'ravi/org-color-customization)
;; don't prompt me to confirm everytime I want to evaluate a block
(setq org-confirm-babel-evaluate nil)
;; display/update images in the buffer after I evaluate
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)
;; Needs java-$VERSION-openjdk or equivalent
(defvar ravi/plantuml-jar-path "/usr/share/java/plantuml.jar"
"Path to plantuml jar file")
(setq org-plantuml-jar-path ravi/plantuml-jar-path)
(defvar ravi/ditaa-jar-path "/usr/share/java/ditaa.jar"
"Path to ditaa jar file")
(setq org-ditaa-jar-path ravi/ditaa-jar-path)
(add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
(org-babel-do-load-languages 'org-babel-load-languages
'((awk . t)
(C . t)
(ditaa . t)
(dot . t)
(emacs-lisp . t)
(latex . t)
(plantuml . t)
(python . t)
(sed . t)
(shell . t)
(jupyter . t))) ; jupyter must be last
(use-package company-org-block
:custom
(company-org-block-edit-style 'auto)
:init
(defun ravi/add-company-org-block-to-org-mode-hook ()
(setq-local company-backends '(company-org-block)))
:hook ((org-mode-hook . ravi/add-company-org-block-to-org-mode-hook)))
)
(use-package org-capture
:defer t
:ensure nil
:config
(when (fboundp 'ravi/setup-org-capture)
(ravi/setup-org-capture)))
(use-package org-static-blog
:commands (org-static-blog-create-new-post org-static-blog-publish)
:config
(defun ravi/org-static-blog-data-file (blog-dir fname)
(with-temp-buffer
(insert-file-contents (expand-file-name (concat "data/" fname) blog-dir))
(buffer-string)))
(defun ravi/org-static-blog-setup (blog-name blog-domain blog-title)
(let ((blog-dir (expand-file-name (concat blog-name "." blog-domain "/") "~/Documents"))
(blog-url (concat "https://" blog-name "." blog-domain ".com")))
(setq org-static-blog-use-preview t
org-static-blog-preview-convert-titles t
org-static-blog-preview-ellipsis "..."
org-static-blog-enable-tags t
org-static-blog-publish-url (concat blog-url "/")
org-static-blog-publish-title blog-title
org-static-blog-posts-directory (expand-file-name "posts/" blog-dir)
org-static-blog-drafts-directory (expand-file-name "drafts/" blog-dir)
org-static-blog-publish-directory (expand-file-name "blog/" blog-dir))
(setq org-static-blog-page-header
(concat
"<meta name=\"author\" content=\"Ravi R Kiran\">"
"<meta name=\"referrer\" content=\"no-referrer\">"
"<link href= \"/static/style.css\" rel=\"stylesheet\"
type=\"text/css\" />"
"<link rel=\"icon\" href=\"static/favicon.ico\">")
org-static-blog-page-preamble
(ravi/org-static-blog-data-file blog-dir "preamble.html")
org-static-blog-page-postamble
(ravi/org-static-blog-data-file blog-dir "postamble.html"))))
(run-hooks 'ravi/org-static-blog-hook)
;; Ensure that generated files are saved in a separate directory
;; shared with published blog directory, i.e.,
;; (expand-file "generated" org-static-blog-posts-directory)
;; (expand-file "generated" org-static-blog-drafts-directory)
;; are symlinks to
;; (expand-file "generated" org-static-blog-publish-directory)
(defun ravi/org-static-blog-generated-files (&rest args)
(save-excursion
(beginning-of-line)
(insert "#+property: header-args:plantuml :output-dir generated/\n")))
(advice-add 'org-static-blog-create-new-post :after #'ravi/org-static-blog-generated-files))
(provide 'ravi-init-org)
;;; ravi-init-org.el ends here
|