jao-custom-org.el 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. ;; -*- lexical-binding: t -*-
  2. ;;; General configuration
  3. (defvar jao-org-dir (expand-file-name "~/doc/org"))
  4. (use-package org
  5. :ensure t
  6. :demand t
  7. :custom ((org-export-backends '(ascii html latex texinfo)))
  8. :init
  9. (defalias 'jao-open-gnus-frame 'jao-afio-goto-mail)
  10. (setq org-adapt-indentation t
  11. org-catch-invisible-edits 'smart
  12. org-complete-tags-always-offer-all-agenda-tags t
  13. org-cycle-separator-lines 0 ;; no blank lines when all colapsed
  14. org-deadline-warning-days 14
  15. org-directory jao-org-dir
  16. org-default-notes-file (expand-file-name "inbox.org" org-directory)
  17. org-ellipsis " .." ;; ↴
  18. org-email-link-description-format "Email %c: %s"
  19. org-enforce-todo-dependencies t
  20. org-fast-tag-selection-single-key 'expert
  21. org-insert-heading-respect-content nil ;; for C-RET
  22. ;; org-list-demote-modify-bullet '(("+" . "-") ("-" . "+") ("*" . "+"))
  23. org-link-frame-setup
  24. '((gnus . (lambda (&optional x) (jao-open-gnus-frame)))
  25. (file . find-file-other-window))
  26. org-log-done nil
  27. org-modules '(bibtex info eww eshell git-link)
  28. org-odd-levels-only t
  29. org-outline-path-complete-in-steps nil
  30. org-refile-allow-creating-parent-nodes 'confirm
  31. org-refile-targets '((nil :maxlevel . 5)
  32. (org-agenda-files :maxlevel . 5))
  33. org-refile-use-outline-path 'file
  34. org-return-follows-link t
  35. org-reverse-note-order t
  36. org-special-ctrl-a/e t
  37. org-src-fontify-natively t
  38. org-startup-folded t
  39. org-tag-alist nil
  40. org-tags-column -75
  41. org-todo-keywords
  42. '((sequence "TODO(t)" "STARTED(s!)" "|" "DONE(d!)")
  43. (sequence "REPLY(r)" "WAITING(w!)" "|" "DONE(d!)")
  44. (sequence "TOREAD(T)" "READING(R!)" "|" "READ(a!)")
  45. (sequence "|" "CANCELLED(x!)" "SOMEDAY(o!)" "DONE(d!)"))
  46. org-use-fast-todo-selection t
  47. org-use-speed-commands nil ;; t and then ? to see help
  48. org-gnus-prefer-web-links nil))
  49. ;;; Agenda
  50. (setq org-agenda-custom-commands
  51. '(("j" agenda "" ((org-agenda-ndays 14)
  52. (org-agenda-overriding-header " ")))
  53. ("w" todo "WAITING" nil)
  54. ("W" agenda "" ((org-agenda-ndays 21))))
  55. org-agenda-files (mapcar (lambda (f)
  56. (expand-file-name f jao-org-dir))
  57. '("inbox.org" "bigml.org"))
  58. org-agenda-block-separator " "
  59. org-agenda-breadcrumbs-separator "•"
  60. org-agenda-current-time-string "•" ;; "*"
  61. ;; '((daily today require-timed)
  62. ;; (800 1000 1200 1400 1600 1800 2000) "" "·")
  63. org-agenda-hide-tags-regexp ".*"
  64. org-agenda-include-diary t
  65. org-agenda-include-inactive-timestamps t
  66. org-agenda-inhibit-startup nil
  67. org-agenda-restore-windows-after-quit t
  68. org-agenda-show-all-dates t
  69. org-agenda-skip-deadline-if-done t
  70. org-agenda-skip-scheduled-if-done nil
  71. org-agenda-span 14
  72. org-agenda-start-on-weekday nil
  73. org-agenda-time-grid '((daily require-timed) () "" "·")
  74. org-agenda-window-setup 'current-window)
  75. (defun jao-org-agenda ()
  76. (interactive)
  77. (org-agenda nil "j"))
  78. (defun jao-org-agenda-hook ()
  79. (setq-local cursor-in-non-selected-windows nil))
  80. (add-hook 'org-agenda-mode-hook #'jao-org-agenda-hook)
  81. (add-to-list 'display-buffer-alist
  82. '("\\*Org Agenda\\*"
  83. (display-buffer-reuse-window)
  84. (body-function . (lambda (w) (set-window-margins w 2 1)))))
  85. ;;; Capture templates
  86. (setq org-capture-templates
  87. '(("t" "TODO" entry
  88. (file+headline "inbox.org" "Todo")
  89. "* TODO %?\n %i%a" :prepend t)
  90. ("r" "REPLY" entry
  91. (file+headline "inbox.org" "Todo")
  92. "* REPLY %:subject%?\n %t\n %i%a" :prepend t)
  93. ("a" "Appointment" entry
  94. (file+olp "inbox.org" "Appointments")
  95. "* %^T %?\n %a" :time-prompt t)
  96. ("i" "Inbox note" entry (file+headline "inbox.org" "Notes")
  97. "* %a\n %i%?(added on: %u)" :prepend t)))
  98. ;; (org-capture-upgrade-templates org-capture-templates)
  99. ;;; MIME and file apps
  100. (setq org-file-apps
  101. '((system . mailcap)
  102. (".*\\.djvu" . system)
  103. (t . emacs)))
  104. ;;; Appearance
  105. (use-package org-appear
  106. :disabled t
  107. :ensure t
  108. :init (setq org-appear-autolinks nil
  109. org-appear-delay 0.0
  110. org-appear-manual-linger t)
  111. :hook (org-mode . org-appear-mode))
  112. ;;; Images
  113. ;; #+caption: Image caption.
  114. ;; #+attr_org: :width 100
  115. ;; [[file:path/to/image.png]]
  116. (setq org-startup-indented nil
  117. org-pretty-entities nil
  118. org-hide-emphasis-markers t
  119. org-hide-leading-stars t
  120. org-startup-with-inline-images t
  121. org-cycle-inline-images-display t
  122. org-display-remote-inline-images 'download ;; 'skip 'cache
  123. org-image-actual-width '(500))
  124. ;;; LaTeX
  125. (use-package org-fragtog
  126. :after org
  127. :ensure t
  128. :hook ((org-mode . org-fragtog-mode)))
  129. (require 'org-fragtog)
  130. (setq org-format-latex-options
  131. `(:foreground default
  132. :background
  133. ,(if (jao-colors-scheme-dark-p) "black" "white")
  134. :scale 1.25
  135. :html-foreground "black"
  136. :html-background "Transparent"
  137. :html-scale 1.0
  138. :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))
  139. org-preview-latex-image-directory
  140. (expand-file-name "~/.emacs.d/cache/ltximg/")
  141. org-latex-hyperref-template nil
  142. org-highlight-latex-and-related '(latex script entities))
  143. (require 'ox-latex)
  144. ;;; Export (minted and pandoc)
  145. (setq org-latex-listings 'minted
  146. org-latex-packages-alist '(("" "minted"))
  147. org-latex-pdf-process
  148. '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
  149. "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
  150. ;; (use-package ox-pandoc
  151. ;; :after org
  152. ;; :ensure t)
  153. ;;; Babel and literate programming
  154. (setq org-src-window-setup 'other-window) ;; current-window
  155. (require 'org-tempo nil t) ;; <s TAB for 9.2 and later
  156. ;; (use-package ob-prolog
  157. ;; :ensure t
  158. ;; :after org)
  159. (org-babel-do-load-languages
  160. 'org-babel-load-languages
  161. '((calc . t)
  162. (clojure . t)
  163. (emacs-lisp .t)
  164. (gnuplot .t)
  165. (haskell . t)
  166. (makefile . t)
  167. (ocaml . t)
  168. (org . t)
  169. (python . t)
  170. (scheme .t)
  171. (shell . t)
  172. ;; (prolog . t)
  173. ))
  174. ;;; Org cliplink (link from clipboard)
  175. (use-package org-cliplink
  176. :ensure t
  177. :bind (:map org-mode-map ("C-c C-f" . org-cliplink))
  178. :config
  179. (add-to-list 'org-capture-templates
  180. '("k" "Cliplink capture task" entry
  181. (file+headline "inbox.org" "Todo")
  182. "* TODO %(org-cliplink-capture) %?" :prepend t)
  183. t))
  184. ;;; Notes
  185. (use-package jao-org-notes
  186. :commands (jao-org-notes-setup)
  187. :config
  188. (defun jao-org-notes-note-p ()
  189. (string-prefix-p jao-org-notes-dir (buffer-file-name)))
  190. (defun jao-org-notes-recoll ()
  191. "Use consult-recoll to search notes."
  192. (interactive)
  193. (consult-recoll (format "dir:%s " jao-org-notes-dir)))
  194. (jao-transient-major-mode org
  195. ["Notes"
  196. ("c" "open or create note" jao-org-notes-create)
  197. ("/" "find and open note" jao-org-notes-open)
  198. ("\\" "find and open note by tags" jao-org-notes-consult-tags)]
  199. ["Extended search"
  200. ("g" "ripgrep notes" jao-org-notes-consult-ripgrep)
  201. ("r" "recoll notes" jao-org-notes-recoll)]
  202. ["Current note" :if jao-org-notes-note-p
  203. ("i" "insert link" jao-org-notes-insert-link)
  204. ("t" "insert tags" jao-org-notes-insert-tags)
  205. ("v" "show backlinks" jao-org-notes-backlinks)]))
  206. (jao-org-notes-setup "n")
  207. ;;; Links
  208. (require 'ol-eshell nil t)
  209. ;; (require 'ol-bbdb nil t)
  210. (require 'ol-info nil t)
  211. (setq org-link-abbrev-alist '(("jao.io" "https://jao.io/")))
  212. (defun jao-org-link-at-point (&optional copy)
  213. (when (thing-at-point-looking-at "\\[\\[\\([^]]+\\)\\]\\[[^]]+\\]\\]")
  214. (when copy (kill-ring-save (match-beginning 1) (match-end 1)))
  215. (match-string-no-properties 1)))
  216. (defun jao-org-copy-link-at-point ()
  217. (interactive)
  218. (message "%s" (or (jao-org-link-at-point t) "No link at point")))
  219. (defun jao-org-insert-link (url title)
  220. (insert (format "[[%s][%s]]" url title)))
  221. (defun jao-insert-eww-link ()
  222. "Look for last eww buffer and insert an org link to it."
  223. (interactive)
  224. (when-let (b (car (jao-eww-session-eww-buffers)))
  225. (let ((lnk (with-current-buffer b
  226. (format "[[%s][%s]]"
  227. (eww-current-url)
  228. (jao-eww-buffer-title)))))
  229. (insert lnk))))
  230. (use-package jao-org-links
  231. :commands jao-org-links-setup
  232. :bind (("C-c T" . jao-org-insert-doc)))
  233. (jao-org-links-setup jao-sink-dir)
  234. (with-eval-after-load "pdf-view"
  235. (define-key pdf-view-mode-map (kbd "C-c o") #'jao-org-pdf-goto-org)
  236. (define-key pdf-view-mode-map (kbd "C-c O") #'jao-org-pdf-goto-org*))
  237. (with-eval-after-load "doc-view"
  238. (define-key doc-view-mode-map (kbd "C-c o") #'jao-org-pdf-goto-org)
  239. (define-key doc-view-mode-map (kbd "C-c O") #'jao-org-pdf-goto-org*))
  240. ;; eldoc
  241. (defun jao-org-eldoc--hook ()
  242. (set (make-local-variable 'eldoc-documentation-function)
  243. 'jao-org-link-at-point)
  244. (eldoc-mode))
  245. (add-hook 'org-mode-hook 'jao-org-eldoc--hook)
  246. ;;; savedoc
  247. (defun jao-org--show-if-hidden ()
  248. (when (outline-invisible-p)
  249. (save-excursion
  250. (outline-previous-visible-heading 1)
  251. (org-show-subtree))))
  252. (add-hook 'org-mode-hook 'jao-org--show-if-hidden t)
  253. ;;; Keybindings
  254. (define-key mode-specific-map [?a] 'org-agenda)
  255. (define-key org-mode-map "\C-cv" 'jao-org-copy-link-at-point)
  256. (define-key org-mode-map [(control ?c) tab] 'org-force-cycle-archived)
  257. (define-key org-mode-map [(f7)] 'org-archive-to-archive-sibling)
  258. (define-key org-mode-map "\C-cE" 'jao-insert-eww-link)
  259. (define-key org-mode-map "\C-cW" 'jao-insert-eww-link)
  260. (define-key org-mode-map "\C-c'" 'org-edit-src-code)
  261. (define-key org-mode-map "\C-cO" 'outline-hide-other)
  262. (global-set-key "\C-cr" 'org-capture)
  263. (global-set-key "\C-c\C-l" 'org-store-link)
  264. ;; (global-set-key "\C-cL" 'org-insert-link-global)
  265. (global-set-key "\C-cO" 'org-open-at-point-global)
  266. (jao-transient-major-mode+ org
  267. ["Links"
  268. ("le" "insert current eww link" jao-insert-eww-link)
  269. ("lf" "insert link from clipboard" org-cliplink)
  270. ("lc" "copy link at point" jao-org-copy-link-at-point)])
  271. ;;; .
  272. (provide 'jao-custom-org)