summaryrefslogtreecommitdiffstats
path: root/lisp/bandali-org.el
blob: 76b5c6ce6b4db9ebada79a55de7eb43b0a6a0541 (plain) (blame)
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
;;; bandali-org.el --- bandali's Org setup           -*- lexical-binding: t; -*-

;; Copyright (C) 2018-2020  Amin Bandali

;; Author: Amin Bandali <bandali@gnu.org>
;; Keywords: calendar, data, docs, hypermedia, outlines

;; 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 <https://www.gnu.org/licenses/>.

;;; Commentary:

;; My set up for Org (org-mode) and all things Org.

;;; Code:

(use-package org
  :config
  (setq org-src-tab-acts-natively t
        org-src-preserve-indentation nil
        org-edit-src-content-indentation 0
        org-link-email-description-format "Email %c: %s" ; %.30s
        org-highlight-latex-and-related '(entities)
        org-use-speed-commands t
        org-startup-folded 'content
        org-catch-invisible-edits 'show-and-error
        org-log-done 'time)
  (add-to-list 'org-structure-template-alist '("L" . "src emacs-lisp") t)
  (add-to-list 'org-modules 'org-habit)
  :bind
  (("C-c a o a" . org-agenda)
   :map org-mode-map
   ("M-L" . org-insert-last-stored-link)
   ("M-O" . org-toggle-link-display))
  :hook ((org-mode . org-indent-mode)
         (org-mode . auto-fill-mode)
         (org-mode . flyspell-mode))
  :custom
  (org-pretty-entities t)
  (org-agenda-files '("~/usr/org/todos/personal.org"
                      "~/usr/org/todos/habits.org"
                      "~/src/git/masters-thesis/todo.org"))
  (org-agenda-start-on-weekday 0)
  (org-agenda-time-leading-zero t)
  (org-habit-graph-column 44)
  (org-latex-packages-alist '(("" "listings") ("" "color")))
  :custom-face
  '(org-block-begin-line ((t (:foreground "#5a5b5a" :background "#1d1f21"))))
  '(org-block ((t (:background "#1d1f21"))))
  '(org-latex-and-related ((t (:foreground "#b294bb")))))

(use-package ox-latex
  :after ox
  :config
  (setq org-latex-listings 'listings
        ;; org-latex-prefer-user-labels t
        )
  (add-to-list 'org-latex-classes
               '("IEEEtran" "\\documentclass[11pt]{IEEEtran}"
                 ("\\section{%s}"       . "\\section*{%s}")
                 ("\\subsection{%s}"    . "\\subsection*{%s}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                 ("\\paragraph{%s}"     . "\\paragraph*{%s}")
                 ("\\subparagraph{%s}"  . "\\subparagraph*{%s}"))
               t)
  (require 'ox-beamer))

(use-package ox-extra
  :config
  (ox-extras-activate '(latex-header-blocks ignore-headlines)))

;; asynchronous tangle, using emacs-async to asynchronously tangle an
;; org file.  closely inspired by
;; https://github.com/dieggsy/dotfiles/tree/cc10edf7701958eff1cd94d4081da544d882a28c/emacs.d#dotfiles
(with-eval-after-load 'org
  (defvar b/show-async-tangle-results nil
    "Keep *emacs* async buffers around for later inspection.")

  (defvar b/show-async-tangle-time nil
    "Show the time spent tangling the file.")

  (defun b/async-babel-tangle ()
    "Tangle org file asynchronously."
    (interactive)
    (let* ((file-tangle-start-time (current-time))
           (file (buffer-file-name))
           (file-nodir (file-name-nondirectory file))
           ;; (async-quiet-switch "-q")
           (file-noext (file-name-sans-extension file)))
      (async-start
       `(lambda ()
          (require 'org)
          (org-babel-tangle-file ,file))
       (unless b/show-async-tangle-results
         `(lambda (result)
            (if result
                (message "Tangled %s%s"
                         ,file-nodir
                         (if b/show-async-tangle-time
                             (format " (%.3fs)"
                                     (float-time (time-subtract (current-time)
                                                                ',file-tangle-start-time)))
                           ""))
              (message "Tangling %s failed" ,file-nodir))))))))

(add-to-list
 'safe-local-variable-values
 '(eval add-hook 'after-save-hook #'b/async-babel-tangle 'append 'local))

(use-package org-tanglesync
  :hook (org-mode . org-tanglesync-mode))

(provide 'bandali-org)
;;; bandali-org.el ends here