summaryrefslogtreecommitdiffhomepage
path: root/org.org
blob: 2f6d773dc008dc3d229f0011fd293c64bc08dfc0 (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#+title: Org (and related) mode configuration

* General configuration
  #+BEGIN_SRC emacs-lisp
    (use-package org
      :ensure t
      :init
      (setq org-catch-invisible-edits 'smart
            org-complete-tags-always-offer-all-agenda-tags t
            org-cycle-separator-lines 0 ;; no blank lines when all colapsed
            org-deadline-warning-days 14
            org-directory jao-org-dir
            org-default-notes-file (expand-file-name "inbox.org" org-directory)
            org-ellipsis " .." ;; ↴
            org-email-link-description-format "Email %c: %s"
            org-enforce-todo-dependencies t
            org-fast-tag-selection-single-key 'expert
            org-hide-emphasis-markers t
            org-hide-leading-stars t
            ;; org-list-demote-modify-bullet '(("+" . "-") ("-" . "+") ("*" . "+"))
            org-link-frame-setup
            '((gnus . (lambda (&optional x) (jao-open-gnus-frame)))
              (file . find-file-other-window))
            org-log-done nil
            org-modules '(bbdb bibtex gnus info w3m)
            org-odd-levels-only t
            org-outline-path-complete-in-steps nil
            org-refile-allow-creating-parent-nodes 'confirm
            org-refile-targets '((nil :maxlevel . 5)
                                 (org-agenda-files :maxlevel . 5))
            org-refile-use-outline-path 'file
            org-return-follows-link t
            org-reverse-note-order t
            org-special-ctrl-a/e t
            org-src-fontify-natively t
            org-startup-folded t
            org-tag-alist nil
            org-tags-column -75
            org-todo-keywords
            '((sequence "TODO(t)" "STARTED(s!)" "|" "DONE(d!)")
              (sequence "REPLY(r)" "WAITING(w!)" "|" "DONE(d!)")
              (sequence "TOREAD(T)" "READING(R!)" "|" "READ(a!)")
              (sequence "|" "CANCELLED(x!)" "SOMEDAY(o!)" "DONE(d!)"))
            org-use-fast-todo-selection t
            org-use-speed-commands nil ;; t and then ? to see help
            org-gnus-prefer-web-links nil))
    (require 'org)
  #+END_SRC
* Agenda
  #+begin_src emacs-lisp
    (setq org-agenda-custom-commands
          '(("w" todo "WAITING" nil)
            ("W" agenda "" ((org-agenda-ndays 21))))
          org-agenda-files (list jao-org-dir)
          org-agenda-include-diary t
          org-agenda-include-inactive-timestamps t
          org-agenda-inhibit-startup nil
          org-agenda-restore-windows-after-quit t
          org-agenda-show-all-dates t
          org-agenda-skip-deadline-if-done t
          org-agenda-skip-scheduled-if-done nil
          org-agenda-span 7
          org-agenda-start-on-weekday nil
          org-agenda-window-setup 'current-window)
  #+end_src
* Capture templates
  #+BEGIN_SRC emacs-lisp
    (setq  org-capture-templates
           '(("t" "TODO" entry
              (file+headline "inbox.org" "Todo")
              "* TODO %?\n  %i%a" :prepend t)
             ("r" "REPLY" entry
              (file+headline "inbox.org" "Todo")
              "* REPLY %:subject%?\n  %t\n %i%a" :prepend t)
             ("a" "Appointment" entry
              (file+olp "inbox.org" "Appointments")
              "* %^T %?\n  %a" :time-prompt t)
             ("w" "Wintermute TODO" entry
              (file+olp "bigml.org" "Wintermute" "Tasks")
              "* TODO %?\n  %i%a" :prepend t)
             ("i" "Inbox note" entry (file+headline "inbox.org" "Notes")
              "* %a\n  %i%?(added on: %u)" :prepend t)
             ("x" "Clipboard" entry (file+headline "inbox.org" "Notes")
              "* %?\n  %a\n  %x\n (added: %u)" :prepend t)))
    ;; (org-capture-upgrade-templates org-capture-templates)
  #+END_SRC
* MIME and file apps
  #+BEGIN_SRC emacs-lisp
    (setq org-file-apps
          '((system . mailcap)
            (".*\\.djvu" . system)
            (t . emacs)))
  #+END_SRC
* Calendar
  #+BEGIN_SRC emacs-lisp
    (setq gnus-icalendar-org-capture-file
          (expand-file-name "inbox.org" org-directory)
          gnus-icalendar-org-capture-headline '("Appointments"))
    (eval-after-load "gnus"
     '(progn (require 'org-agenda)
             (require 'gnus-icalendar)
             (gnus-icalendar-org-setup)))
  #+END_SRC
* LaTeX
  #+begin_src emacs-lisp
    (use-package org-fragtog
      :after org
      :ensure t
      :hook ((org-mode . org-fragtog-mode)))

    (require 'org-fragtog)

    (setq org-format-latex-options
          `(:foreground default
                        :background
                        ,(if (jao-colors-scheme-dark-p) "black" "white")
                        :scale 1.25
                        :html-foreground "black"
                        :html-background "Transparent"
                        :html-scale 1.0
                        :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))
          org-preview-latex-image-directory
          (expand-file-name "~/.emacs.d/cache/ltximg/")
          org-latex-hyperref-template nil
          org-highlight-latex-and-related '(latex script entities))

    (require 'ox-latex)
    (add-to-list 'org-latex-classes
                 '("bmlarticle"
                   "\\documentclass{bmlarticle}\n[NO-DEFAULT-PACKAGES]\n[EXTRA]"
                   ("\\section{%s}" . "\\section*{%s}")
                   ("\\subsection{%s}" . "\\subsection*{%s}")
                   ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                   ("\\paragraph{%s}" . "\\paragraph*{%s}")
                   ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

    (use-package cdlatex
      :ensure t
      :hook ((org-mode . org-cdlatex-mode))
      :diminish ((cdlatex-mode . " £")
                 (org-cdlatex-mode . " £")))

  #+end_src

* Export (minted)

  #+begin_src emacs-lisp
    (setq org-latex-listings 'minted
          org-latex-packages-alist '(("" "minted"))
          org-latex-pdf-process
          '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
            "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
  #+end_src

* Babel
  - [[http://cachestocaches.com/2018/6/org-literate-programming][Literate Programming with Org-mode]]
  - [[http://howardism.org/Technical/Emacs/literate-devops.html][Literate DevOps]]

  #+begin_src emacs-lisp
    (setq org-src-window-setup 'other-window) ;; current-window
    (require 'org-tempo nil t) ;; <s TAB for 9.2 and later

    ;; (use-package ob-elixir
    ;;   :ensure t
    ;;   :after org)

    (use-package ob-prolog
      :ensure t
      :after org)

    (org-babel-do-load-languages
     'org-babel-load-languages
     '((calc . t)
       (clojure . t)
       ;; (elixir . t)
       (emacs-lisp .t)
       (gnuplot .t)
       (haskell . t)
       (makefile . t)
       (ocaml . t)
       (org . t)
       (python . t)
       (scheme .t)
       (shell . t)
       (prolog . t)))
  #+end_src

* Org cliplink (link from clipboard)
  [[https://github.com/rexim/org-cliplink][GitHub - rexim/org-cliplink: Insert org-mode links from clipboard]]

  #+BEGIN_SRC emacs-lisp
    (use-package org-cliplink
      :ensure t
      :bind (:map org-mode-map ("C-c C-f" . org-cliplink))
      :config
      (add-to-list 'org-capture-templates
                   '("k" "Cliplink capture task" entry
                     (file+headline "inbox.org" "Todo")
                     "* TODO %(org-cliplink-capture) %?" :prepend t)
                   t))
  #+END_SRC

* Org download

  #+begin_src emacs-lisp
    (use-package org-download
      :ensure t
      :after org
      :init (setq org-download-screenshot-method "import %s")
      :bind
      (:map org-mode-map
            (("C-c S" . org-download-screenshot)
             ("C-c I" . org-download-yank))))
  #+end_src

* Org roam
  #+begin_src emacs-lisp
    (use-package org-roam
      :ensure t
      :init
      (defun jao-roam--slug (slug) (replace-regexp-in-string "_" "-" slug))

      (defun jao-roam--cat ()
        (let* ((cats (seq-difference (directory-files org-roam-directory)
                                     '("." ".." "attic")))
               (cat (completing-read "Top level cat: " cats)))
          (cond ((file-exists-p (expand-file-name cat org-roam-directory)) cat)
                ((yes-or-no-p "New category, create?") cat)
                (t (jao-roam--cat)))))

      (setq org-roam-capture-templates
            `(("d" "default" plain #'org-roam-capture--get-point
               "%a %i"
               :file-name "%(jao-roam--cat)/%(jao-roam--slug \"${slug}\")"
               :head ,(concat "#+title: ${title}"
                              "\n#+created: %T"
                              "\n#+roam_tags: %?"
                              "\n#+roam_ref: %:url\n\n"))))

      :custom ((org-roam-directory (expand-file-name "~/org/notes"))
               (org-roam-encrypt-files nil)
               (org-roam-buffer-position nil)
               (org-roam-buffer-height nil)
               (org-roam-buffer-window-parameters nil)
               (org-roam-link-use-custom-faces t)
               (org-roam-link-auto-replace t)
               (org-roam-tag-sources '(prop vanilla all-directories))
               (org-roam-file-exclude-regexp ".+/code\\|attic/.*")
               (org-roam-verbose nil))

      :config
      (defvar org-roam-consult-flags
        '("--null" "--ignore-case" "--type=org" "--line-buffered"
          "--color=always" "--max-columns=250" "--no-heading" "--line-number"))

      (defun consult-org-roam ()
        "Search org-roam directory using consult-ripgrep. With live-preview."
        (interactive)
        (let ((consult-ripgrep-command
               (format "rg %s . -e ARG OPTS"
                       (mapconcat 'identity org-roam-consult-flags " "))))
          (consult-ripgrep org-roam-directory)))

      (major-mode-hydra-define+ org-mode ()
        ("Roam"
         (("i" org-roam-insert "insert")
          ("f" org-roam-find-file "find-file")
          ("o" consult-org-roam "consult")
          ("v" org-roam-buffer-toggle-display "toggle backlinks"))))

      (jao-define-attached-buffer (regexp-quote org-roam-buffer) 0.33)

      :hook ((after-init . org-roam-mode))
      :bind (("C-c n" . org-roam-capture)
             ("C-c N" . org-roam-find-file))
      :diminish)
  #+end_src
* Links
  #+begin_src emacs-lisp
    (require 'org-gnus nil t)
    (require 'ol-gnus nil t)
    (require 'ol-w3m nil t)
    (require 'ol-eshell nil t)
    (require 'ol-bbdb nil t)
    (require 'ol-docview nil t)
    (require 'ol-info nil t)

    (setq org-link-abbrev-alist
          '(("jao.io" "https://jao.io/")))
  #+end_src
* jao-org
  #+begin_src emacs-lisp
    (use-package jao-org-utils)

    (use-package jao-org-links
      :commands jao-org-links-setup
      :bind (("C-c T" . jao-org-insert-doc)))

    (jao-org-utils-setup)
    (jao-org-utils-eldoc-setup)
    (jao-org-links-setup jao-sink-dir)

    (with-eval-after-load "pdf-view"
      (define-key pdf-view-mode-map (kbd "C-c o") #'jao-org-pdf-goto-org)
      (define-key pdf-view-mode-map (kbd "C-c O") #'jao-org-pdf-goto-org*))
  #+end_src
* Geiser and org
  #+begin_src emacs-lisp
    (defun jao-org--set-geiser-impl () (setq-local geiser-repl--impl 'guile))
    (add-hook 'org-mode-hook #'jao-org--set-geiser-impl)
  #+end_src
* Keybindings
    #+begin_src emacs-lisp
      (define-key mode-specific-map [?a] 'org-agenda)
      (define-key org-mode-map "\C-cv" 'jao-org-copy-link-at-point)
      (define-key org-mode-map [(control ?c) tab] 'org-force-cycle-archived)
      (define-key org-mode-map [(f7)] 'org-archive-to-archive-sibling)
      (define-key org-mode-map "\C-cW" 'jao-insert-w3m-link)
      (define-key org-mode-map "\C-c'" 'org-edit-src-code)
      (define-key org-mode-map "\C-co" 'outline-hide-other)
      (global-set-key "\C-cr" 'org-capture)
      (global-set-key "\C-c\C-l" 'org-store-link)
      (global-set-key "\C-cL" 'org-insert-link-global)
      (global-set-key "\C-cO" 'org-open-at-point-global)
      (global-set-key "\C-ca" 'org-agenda)
      (global-set-key [(f3)] #'org-capture-goto-last-stored)
     #+end_src