PageRenderTime 62ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/site-start.d/70-org.el

https://bitbucket.org/heikkil/emacs.d
Emacs Lisp | 408 lines | 224 code | 88 blank | 96 comment | 9 complexity | 7866cdc7d2e2e3435ab3ed52cf4edab2 MD5 | raw file
  1. ;;
  2. ;; Heikki Lehvaslaiho
  3. ;; Time-stamp: <2013-09-21 18:43:35 heikki>
  4. ;;
  5. ;;
  6. ;; org
  7. ;;
  8. ;; hack to get capture working
  9. (add-to-list 'load-path "~/.emacs.d/elpa/org")
  10. ;; set the org auto mode
  11. (require 'org)
  12. (add-to-list 'auto-mode-alist '("\\.\\([o][r][g]\\)\\'" . org-mode))
  13. ;; org-cua-dwim package installed
  14. ;;(require 'org-cua-dwim)
  15. ;;(org-cua-dwim-activate)
  16. ;; add timestamp to TODO items
  17. (setq org-log-done 'time)
  18. ;; locate external jars
  19. (setq org-ditaa-jar-path "~/src/org-mode/contrib/scripts/ditaa.jar")
  20. (setq org-plantuml-jar-path
  21. (expand-file-name "~/.emacs.d/bin/plantuml.jar"))
  22. ;; Use fundamental mode when editing plantuml blocks with C-c '
  23. (add-to-list 'org-src-lang-modes (quote ("plantuml" . fundamental)))
  24. (add-hook 'org-babel-after-execute-hook 'bh/display-inline-images 'append)
  25. (defun bh/display-inline-images ()
  26. (condition-case nil
  27. (org-display-inline-images)
  28. (error nil)))
  29. (org-babel-do-load-languages
  30. 'org-babel-load-languages
  31. '( (perl . t)
  32. (clojure . t)
  33. (R . t)
  34. (ruby . t)
  35. (sh . t)
  36. (python . t)
  37. (emacs-lisp . t)
  38. (ditaa . t)
  39. (plantuml . t)
  40. (dot . t)
  41. (lilypond nil)
  42. (latex . t)
  43. (sql . t)
  44. (sqlite . t)
  45. (org . t)
  46. ))
  47. ;; font colorization according to language
  48. (setq org-src-fontify-natively t)
  49. ;; run code without confimation
  50. (setq org-confirm-babel-evaluate nil)
  51. ;;
  52. ;; latex export from org
  53. ;;
  54. (require 'ox-latex)
  55. (require 'ox-beamer)
  56. ;; * My Headline
  57. ;; In section [[My Headline]] we discuss ...
  58. (setq org-latex-hyperref-format "\\ref{%s}")
  59. ;; syntax lighlighting with minted
  60. ;; needs pygments installed
  61. ;; http://praveen.kumar.in/2012/03/10/org-mode-latex-and-minted-syntax-highlighting/
  62. (setq org-latex-listings 'minted)
  63. (add-to-list 'org-latex-packages-alist '("" "minted"))
  64. (setq texcmd "latexmk -interaction=nonstopmode -interaction=nonstopmode -shell-escape -pdflatex=xelatex -gg -f -pdf %f")
  65. (add-to-list 'org-latex-classes
  66. '("fu-org-article"
  67. "\\documentclass[11pt,a4paper]{article}
  68. \\usepackage[T1]{fontenc}
  69. \\usepackage{xunicode} % for XeTex
  70. \\usepackage{fontspec} % for XeTex
  71. \\usepackage{xltxtra} % for XeTex
  72. \\usepackage{url} % for XeTex to break long URLs at line ending
  73. \\usepackage[english]{babel} % for XeTex
  74. \\usepackage{libertine}
  75. \\usepackage{graphicx}
  76. \\usepackage{minted}
  77. \\usepackage{hypernat}
  78. \\usepackage[round]{natbib}
  79. \\usepackage{paralist}
  80. \\let\\itemize\\compactitem
  81. \\let\\description\\compactdesc
  82. \\let\\enumerate\\compactenum
  83. \\defaultfontfeatures{Mapping=tex-text}
  84. \\setromanfont[Mapping=tex-text, Numbers=OldStyle]{Linux Libertine O}
  85. \\usepackage[a4paper, textheight=10in,
  86. marginparsep=7pt, marginparwidth=.6in]{geometry}
  87. \\usepackage[colorlinks=true,urlcolor=black,linkcolor=black,citecolor=blue]{hyperref}
  88. \\let\\nofiles\\relax % Void the \\nofiles command
  89. \\pagestyle{plain}
  90. \\title{}
  91. [NO-DEFAULT-PACKAGES]
  92. [NO-PACKAGES]"
  93. ("\\section{%s}" . "\\section*{%s}")
  94. ("\\subsection{%s}" . "\\subsection*{%s}")
  95. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  96. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  97. ("\\subparagraph{%s}" . "\\subparagraph*{%s}")
  98. )
  99. )
  100. (setq org-latex-pdf-process
  101. '("/usr/texbin/latexmk -interaction=nonstopmode -shell-escape -pdflatex=/usr/texbin/xelatex -f -pdf %f"))
  102. ;;
  103. ;; end of latex export
  104. ;;
  105. ;; Skeletons
  106. ;;
  107. ;; sblk - Generic block #+BEGIN_SRC FOO .. #+END_SRC
  108. (define-skeleton skel-org-block
  109. "Insert an org block, querying for type."
  110. "Type: "
  111. "#+BEGIN_SRC " str "\n"
  112. _ -
  113. "\n#+END_SRC\n")
  114. ;; pblk - Perl block #+BEGIN_SRC perl .. #+END_SRC
  115. (define-skeleton skel-org-block-perl
  116. "Insert an org perl block with results in the output."
  117. ""
  118. "#+HEADERS: :results output :exports both :shebang \"#!/usr/bin/env perl\"\n#+BEGIN_SRC perl :tangle yes\n"
  119. _ -
  120. "\n#+END_SRC\n")
  121. (define-abbrev org-mode-abbrev-table "pblk" "" 'skel-org-block-perl)
  122. ;; rblk - R block #+BEGIN_SRC R .. #+END_SRC
  123. ;; for optimised for inline graphics
  124. (define-skeleton skel-org-block-r
  125. "Insert an org R block with results in the output."
  126. ""
  127. "#+HEADER: :session *R* :cache yes :results output graphics :exports both :tangle yes\n#+BEGIN_SRC R :file a.png :width 500 :height 500\n"
  128. _ -
  129. "\n#+END_SRC\n")
  130. (define-abbrev org-mode-abbrev-table "rblk" "" 'skel-org-block-r)
  131. ;; splantuml - PlantUML Source block
  132. (define-skeleton skel-org-block-plantuml
  133. "Insert a org plantuml block, querying for filename."
  134. "File (no extension): "
  135. "#+BEGIN_SRC plantuml :file " str ".png\n"
  136. _ -
  137. "\n#+END_SRC\n")
  138. (define-abbrev org-mode-abbrev-table "splantuml" "" 'skel-org-block-plantuml)
  139. ;; sdot - Graphviz DOT block
  140. (define-skeleton skel-org-block-dot
  141. "Insert a org graphviz dot block, querying for filename."
  142. "File (no extension): "
  143. "#+BEGIN_SRC dot :file " str ".png :cmdline -Kdot -Tpng\n"
  144. "graph G {\n"
  145. _ - \n
  146. "}"
  147. "\n#+END_SRC\n")
  148. (define-abbrev org-mode-abbrev-table "sdot" "" 'skel-org-block-dot)
  149. ;; sditaa - Ditaa source block
  150. (define-skeleton skel-org-block-ditaa
  151. "Insert a org ditaa block, querying for filename."
  152. "File (no extension): "
  153. "#+BEGIN_SRC ditaa :file " str ".png :cmdline -r\n"
  154. _ -
  155. "\n#+END_SRC\n")
  156. (define-abbrev org-mode-abbrev-table "sditaa" "" 'skel-org-block-ditaa)
  157. ;; lblk - Emacs Lisp source block
  158. (define-skeleton skel-org-block-elisp
  159. "Insert a org emacs-lisp block"
  160. ""
  161. "#+BEGIN_SRC emacs-lisp\n"
  162. _ -
  163. "\n#+END_SRC\n")
  164. (define-abbrev org-mode-abbrev-table "lblk" "" 'skel-org-block-elisp)
  165. ;
  166. ; RefTex mode configuration
  167. ;
  168. (setq reftex-default-bibliography
  169. (quote
  170. ("/Users/heikki/Documents/latex/all.bib")))
  171. (defun org-mode-reftex-setup ()
  172. (load-library "reftex")
  173. (and (buffer-file-name) (file-exists-p (buffer-file-name))
  174. (progn
  175. ;enable auto-revert-mode to update reftex when bibtex file changes
  176. (global-auto-revert-mode t)
  177. (reftex-parse-all))
  178. (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
  179. (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search))
  180. )
  181. (add-hook 'org-mode-hook 'org-mode-reftex-setup)
  182. ;; Add these two lines to the end of the document.
  183. ;; Change bibfilename to bib file name
  184. ;; natbib ref: http://merkel.zoneo.net/Latex/natbib.php
  185. ;;.
  186. ;;\bibliographystyle{natbib}{}
  187. ;;\bibliography{bibfilename}
  188. ;; obiblio - bibliography creation block
  189. (define-skeleton skel-org-block-bibl
  190. "Insert a org/lisp bibliography block"
  191. ""
  192. "\n\\bibliographystyle{plainnat}\n\\bibliography{/Users/heikki/Documents/latex/all}\n"
  193. _ -
  194. "")
  195. (define-abbrev org-mode-abbrev-table "obiblio" "" 'skel-org-block-bibl)
  196. ;;
  197. ;; capture
  198. ;;
  199. ;; see http://doc.norang.ca/org-mode.html#Capture
  200. (setq org-directory "~/Dropbox/org")
  201. (setq org-default-notes-file "~/Dropbox/org/refile.org")
  202. ;(setq org-default-notes-file (concat org-directory "~/Dropbox/org/notes.org"))
  203. (define-key global-map "\C-cc" 'org-capture)
  204. ;; Capture templates for: TODO tasks, Notes, appointments, phone calls, and org-protocol
  205. (setq org-capture-templates
  206. (quote (("t" "todo" entry (file "~/Dropbox/org/refile.org")
  207. "* TODO %?\n%U\n%a\n" :clock-in t :clock-resume t)
  208. ("r" "respond" entry (file "~/Dropbox/org/refile.org")
  209. "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
  210. ("n" "note" entry (file "~/Dropbox/org/refile.org")
  211. "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
  212. ("j" "journal" entry (file+datetree "~/Dropbox/org/journal.org")
  213. "* %?\n%U\n" :clock-in t :clock-resume t)
  214. ("f" "reFerence" entry (file+datetree "~/Dropbox/org/reference.org")
  215. "* %?\nEntered on %U\n %i") ; '\n %a' removed as unnecessary
  216. ("p" "Phone call" entry (file "~/Dropbox/org/refile.org")
  217. "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
  218. ("h" "Habit" entry (file "~/Dropbox/org/refile.org")
  219. "* NEXT %?\n%U\n%a\nSCHEDULED: %(format-time-string \"<%Y-%m-%d %a .+1d/3d>\")\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n"))))
  220. ;; Remove empty LOGBOOK drawers on clock out
  221. (defun bh/remove-empty-drawer-on-clock-out ()
  222. (interactive)
  223. (save-excursion
  224. (beginning-of-line 0)
  225. (org-remove-empty-drawer-at "LOGBOOK" (point))))
  226. (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
  227. ;;
  228. ;; refile
  229. ;;
  230. ;; Targets include this file and any file contributing to the agenda - up to 9 levels deep
  231. (setq org-refile-targets (quote ((nil :maxlevel . 9)
  232. (org-agenda-files :maxlevel . 9))))
  233. ;; Use full outline paths for refile targets - we file directly with IDO
  234. (setq org-refile-use-outline-path t)
  235. ;; Targets complete directly with IDO
  236. (setq org-outline-path-complete-in-steps nil)
  237. ;; Allow refile to create parent tasks with confirmation
  238. (setq org-refile-allow-creating-parent-nodes (quote confirm))
  239. ;; Use IDO for both buffer and file completion and ido-everywhere to t
  240. (setq org-completion-use-ido t)
  241. (setq ido-everywhere t)
  242. (setq ido-max-directory-size 100000)
  243. (ido-mode (quote both))
  244. ;; Refile settings
  245. ;; Exclude DONE state tasks from refile targets
  246. ;;(defun bh/verify-refile-target ()
  247. ;; "Exclude todo keywords with a done state from refile targets"
  248. ;; (not (member (nth 2 (org-heading-components)) org-done-keywords)))
  249. ;;
  250. ;;(setq org-refile-target-verify-function 'bh/verify-refile-target)
  251. ;;
  252. ;; agenda
  253. ;;
  254. ;;
  255. ;; Files to search using agenda commands
  256. ;;
  257. ;;(setq org-agenda-files '("~/Dropbox/org")) ; all files in the directory
  258. ;;'(org-agenda-files (quote ("~/Dropbox/org/actions.org" "~/Dropbox/org/reference.org")))
  259. ;;
  260. ;; search only reference.org
  261. ;; I am not using other files/templates at the moment
  262. '(org-agenda-files (quote ("~/Dropbox/org/reference.org")))
  263. (setq org-agenda-include-diary t)
  264. (setq org-agenda-start-on-weekday 7)
  265. (setq org-tag-alist (quote (("BITCOIN" . ?a)
  266. ("BIO" . ?b)
  267. ("COMP" . ?c)
  268. ("EMACS" . ?e)
  269. ("PHOTO" . ?f)
  270. ("GIT" . ?g)
  271. ("HOME" . ?h)
  272. ("LATEX" . ?l)
  273. ("MAP" . ?m)
  274. ("ORG" . ?o)
  275. ("PERL" . ?p)
  276. ("WORK" . ?w)
  277. ("PYTHON" . ?y)
  278. ("ZSH" . ?z)
  279. )))
  280. (global-set-key "\C-cl" 'org-store-link) ; store current position (copy); use C-c C-l
  281. (global-set-key "\C-ca" 'org-agenda)
  282. ;;
  283. ;; Access org-mode info with: C-c o
  284. ;;
  285. ;; Caveat: links to builtin (old) org docs
  286. ;;
  287. (defvar fp-org-distribution "~/src/org-mode")
  288. (defun fp-org-info ()
  289. (interactive)
  290. (require 'info)
  291. (let ((Info-directory-list (cons (concat fp-org-distribution "/doc")
  292. Info-directory-list)))
  293. (org-info)))
  294. (global-set-key "\C-co" 'fp-org-info)
  295. ;; reveal export mode
  296. ;; https://github.com/yjwen/org-reveal/blob/master/Readme.org
  297. ;; cd ~/src/
  298. ;; git clone https://github.com/yjwen/org-reveal.git
  299. (require 'ox-reveal)
  300. (setq org-reveal-root "file:///Users/heikki/src/reveal.js")
  301. ;; org-mode asks for a master file when opening the first org file in emacs
  302. ;; discussion and fix at:
  303. ;; http://lists.gnu.org/archive/html/emacs-orgmode/2012-02/msg00759.html
  304. (setq TeX-auto-save t)
  305. (setq TeX-parse-self t)
  306. (setq-default TeX-master nil)
  307. (make-variable-buffer-local 'TeX-master) ;; I think this is need because the variable is not buffer local until Auctex is active
  308. (defun org-mode-reftex-setup ()
  309. (setq TeX-master t)
  310. (load-library "reftex")
  311. (and (buffer-file-name)
  312. (file-exists-p (buffer-file-name))
  313. (progn
  314. (reftex-parse-all)
  315. (reftex-set-cite-format "[[cite:%l][%l]]")))
  316. (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
  317. (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search))
  318. (add-hook 'org-mode-hook 'org-mode-reftex-setup)
  319. ;;
  320. ;; End of org