summary refs log tree commit diff
path: root/emacs/custom/my-org.el
blob: d4b7837e0746990869f3ea006a1c5946e2ceb9f9 (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
125
126
127
128
129
130
131
132
133
134
135
136
;;; my-org.el --- Configure org-mode -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:

(require 'org)
(require 'org-agenda)
(require 'org-capture)
(require 'org-archive)
(require 'org-cliplink)
(require 'ox)
(require 'ox-md)

(defvar my/org-directory
  (if (memq window-system '(mac ns))
      (expand-file-name "~/workspace/notebooks/")
    (expand-file-name "~/documents/notes/")))

(add-hook 'org-mode-hook 'org-indent-mode)
(add-hook 'org-mode-hook 'org-hide-block-all)
(add-hook 'org-mode-hook 'visual-line-mode)
(add-hook 'org-capture-after-finalize-hook 'org-save-all-org-buffers)
(add-hook 'org-capture-prepare-finalize-hook 'org-save-all-org-buffers)

(global-set-key (kbd "C-c c") 'org-capture)
(global-set-key (kbd "C-c a") 'org-agenda)

(defvar load-language-list '((emacs-lisp . t)
                             (python . t)
                             (shell . t)))

(setq org-directory my/org-directory)
(setq org-hide-emphasis-markers t)                ;; hide emphasis markup
(setq org-archive-subtree-add-inherited-tags t)   ;; when archiving, inherit the tags from the parent
(setq org-pretty-entities t)                      ;; display unicode characters
(setq org-log-done 'time)                         ;; log the time of completion
(setq org-log-into-drawer t)                      ;; insert state change in the drawer
(setq org-cycle-separator-lines 0)
(setq org-startup-folded 'content)
(setq org-todo-keywords '((sequence "TODO" "STARTED" "WAITING" "|" "DONE" "CANCELED")))

(setq org-priority-start-cycle-with-default nil) ;; Start one over/under default value.
(setq org-highest-priority ?A)
(setq org-lowest-priority ?D)
(setq org-default-priority ?C)                   ;; Ensures unset tasks have low priority.

(setq org-refile-use-cache nil)
(setq org-refile-targets `((,(expand-file-name "tasks.org" org-directory) :maxlevel . 1)
                           (,(expand-file-name "notes.org" org-directory) :maxlevel . 1)))
(setq org-refile-use-outline-path 'file)
(setq org-outline-path-complete-in-steps nil)
(setq org-refile-allow-creating-parent-nodes 'confirm)

;; org babel related
(setq org-src-fontify-natively t)
(setq org-src-preserve-indentation t)     ;; prevent the conversion of spaces into tabs (necessary for Python code exports)
(setq org-edit-src-content-indentation t)

(setq org-return-follows-link t)          ;; I want to follow links on RET

;; some configurations for exporting document
(setq org-export-with-toc nil)
(setq org-export-with-section-numbers nil)

;; a few abbreviations I use regularly
(setq org-link-abbrev-alist
      '(("src"  . "~/workspace/%s")
        ("jira" . "https://jira.rbx.com/browse/%s")
        ("go"   . "http://go/%s")))

(setq org-blank-before-new-entry (quote ((heading . nil) (plain-list-item . nil))))
(setq org-reverse-note-order t)

(setq org-agenda-files `(,(expand-file-name "inbox.org" org-directory)
                         ,(expand-file-name "notes.org" org-directory)
                         ,(expand-file-name "tasks.org" org-directory)
                         ,(expand-file-name "bookmarks.org" org-directory)
                         ,(expand-file-name "journal.org" org-directory)))
(setq org-agenda-show-all-dates t)
(setq calendar-week-start-day 1)
(setq org-agenda-custom-commands nil)
(setq org-agenda-start-on-weekday 1)

(add-to-list 'org-agenda-custom-commands
             '("A" "Agenda for today"
               ((agenda "" ((org-agenda-span 'day)
                            (org-agenda-start-day (org-today))))
                (todo "TODO"
                      ((org-agenda-overriding-header "To Refile")
                       (org-agenda-files `(,(expand-file-name "inbox.org" org-directory)))))
                (todo "STARTED"
                      ((org-agenda-overriding-header "In Progress")))
                (todo "WAITING"
                      ((org-agenda-overriding-header "Blocked")))
                (todo "TODO"
                      ((org-agenda-overriding-header "Not yet started")
                       (org-agenda-skip-function '(org-agenda-skip-entry-if 'deadline 'scheduled)))))))

(setq org-capture-templates
`(("t" "tasks" entry (file "inbox.org")
   "* TODO [#D] %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n")

  ("T" "TIL" entry (file+headline "til.org" "Today I learnt")
   "* %^{title} :%^{tag}:\n:PROPERTIES:\n:CREATED: %U\n:END:\n%?\nSource: %^C")

  ("n" "note" entry (file "notes.org")
   "* %?\n:PROPERTIES:\n:CREATED: %T\n:END:\n")

  ("f" "feed" entry (file "inbox.org")
   ,(concat "* TODO [#D] %:elfeed-entry-title :feed:\n"
            ":PROPERTIES:\n:CREATED: %T\n:END:\n"
            "%a\n"))

  ("b" "bookmark" entry (file "bookmarks.org")
   ,(concat "* %(org-cliplink-capture) :%^{tag}:\n"
            ":PROPERTIES:\n:CREATED: %T\n:END:%?\n") :prepend t :empty-lines 1)

  ("j" "journal" entry (file+olp+datetree "journal.org")
   "* %?\n:PROPERTIES:\n:CREATED: %T\n:END:\n" :tree-type day)))

;; https://stackoverflow.com/questions/20164918/how-to-untick-checkboxes-in-org-mode-for-the-next-cyclic-repetitive-task
(defun my/org-reset-checkbox-state-maybe ()
  "Reset all checkboxes in an entry if the `RESET_CHECK_BOXES' property is set."
  (interactive "*")
  (if (org-entry-get (point) "RESET_CHECK_BOXES")
      (org-reset-checkbox-state-subtree)))

(defun my/org-reset-checkbox-when-done ()
  "Reset all checkboxes in an entry when the state is DONE."
  (when (member org-state org-done-keywords) ;; org-state dynamically bound in org.el/org-todo
    (my/org-reset-checkbox-state-maybe)))

(add-hook 'org-after-todo-state-change-hook 'my/org-reset-checkbox-when-done)

(provide 'my-org)

;;; my-org.el ends here