about summary refs log tree commit diff
path: root/users/grfn/emacs.d/org-config.el
blob: b6e5399c0efbd89e227d199e1b44873d50b52d5e (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
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
;;; -*- lexical-binding: t; -*-

(defun +grfn/org-setup ()
  (setq-local truncate-lines -1)
  (display-line-numbers-mode -1)
  (line-number-mode -1))

(add-hook 'org-mode-hook #'+grfn/org-setup)

(defun notes-file (f)
  (concat org-directory (if (string-prefix-p "/" f) "" "/") f))

(defun grfn/org-project-tag->key (tag)
  (s-replace-regexp "^project__" "" tag))

(defun grfn/org-project-tag->name (tag)
  (s-titleized-words
   (s-join " " (s-split "_" (grfn/org-project-tag->key tag)))))

(defun grfn/org-project-tag->keys (tag)
  (s-join "" (cons "p"
                   (-map (lambda (s) (substring-no-properties s 0 1))
                         (s-split "_" (grfn/org-project-tag->key tag))))))

(defun grfn/org-projects->agenda-commands (project-tags)
  (loop for tag in project-tags
        collect `(,(grfn/org-project-tag->keys tag)
                  ,(grfn/org-project-tag->name tag)
                  tags-todo
                  ,tag)))

(defun grfn/org-projects ()
  (loop for (tag) in
        (org-global-tags-completion-table
         (directory-files-recursively "~/notes" "\\.org$"))
        when (s-starts-with-p "project__" tag)
        collect tag))

(comment
 (grfn/org-projects->agenda-commands (grfn/org-projects))
 )

(setq
 org-directory (expand-file-name "~/notes")
 +org-dir (expand-file-name "~/notes")
 org-default-notes-file (concat org-directory "/inbox.org")
 +org-default-todo-file (concat org-directory "/inbox.org")
 org-agenda-files (directory-files-recursively
                   "~/notes" "\\.org$")
 org-refile-targets '((org-agenda-files :maxlevel . 3))
 org-outline-path-complete-in-steps nil
 org-refile-use-outline-path t
 org-file-apps `((auto-mode . emacs)
                 (,(rx (or (and "." (optional "x") (optional "htm") (optional "l") buffer-end)
                           (and buffer-start "http" (optional "s") "://")))
                  . "firefox %s")
                 (,(rx ".pdf" buffer-end) . "apvlv %s")
                 (,(rx "." (or "png"
                               "jpg"
                               "jpeg"
                               "gif"
                               "tif"
                               "tiff")
                       buffer-end)
                  . "feh %s"))
 org-log-done 'time
 org-archive-location "~/notes/trash::* From %s"
 org-cycle-separator-lines 2
 org-hidden-keywords '(title)
 org-tags-column -130
 org-ellipsis "…"
 org-imenu-depth 9
 org-capture-templates
 `(("t" "Todo" entry
    (file +org-default-todo-file)
    "* TODO %?\n%i"
    :kill-buffer t)

   ("w" "Work Todo" entry
    (file+headline ,(notes-file "work.org") "Work Tasks")
    "* TODO %?\n%i")

   ("m" "Email" entry
    (file +org-default-todo-file)
    "* TODO [[%L][%:subject]] :email:\n%i")

   ("n" "Notes" entry
    (file +org-default-todo-file)
    "* %U %?\n%i"
    :prepend t
    :kill-buffer t)

   ("c" "Task note" entry
    (clock)
    "* %U %?\n%i[%l[Context]]\n"
    :kill-buffer t
    :unnarrowed t)

   ("p" "Projects")
   ("px" "Xanthous" entry
    (file+headline ,(notes-file "xanthous.org") "Backlog")
    "* TODO %?\nContext %a\nIn task: %K")
   ("pt" "Tvix" entry
    (file+headline ,(notes-file "tvix.org") "Tvix TODO")
    "* TODO %?\nContext %a\nIn task: %K")
   ("pw" "Windtunnel" entry
    (file+headline ,(notes-file "windtunnel.org") "Tasks")
    "* TODO %i%?\nContext: %a\nIn task: %K")

   ("d" "Data recording")
   )

 org-capture-templates-contexts
 `(("px" ((in-file . "/home/grfn/code/depot/users/grfn/xanthous/.*"))))

 org-deadline-warning-days 1
 org-agenda-skip-scheduled-if-deadline-is-shown 'todo
 org-todo-keywords '((sequence "TODO(t)" "ACTIVE(a)" "|" "DONE(d)" "RUNNING(r)")
                     (sequence "NEXT(n)" "WAITING(w)" "LATER(l)" "|" "CANCELLED(c)"))
 org-agenda-custom-commands
 `(("i" "Inbox" tags "inbox")
   ("r" "Running jobs" todo "RUNNING")
   ("w" "@Work" tags-todo "@work")
   ("n" . "Next...")
   ("nw" "Next @Work" tags-todo "@work&next")
   ("nt" "Next tooling" tags-todo "tooling")

   ("p" . "Project...")
   ,@(grfn/org-projects->agenda-commands (grfn/org-projects)))

 org-agenda-dim-blocked-tasks nil
 org-enforce-todo-dependencies nil

 org-babel-clojure-backend 'cider)


(defun +grfn/insert-work-template ()
  (interactive)
  (goto-char (point-min))
  (forward-line)
  (insert "#+TODO: TODO(t) NEXT(n) ACTIVE(a) | DONE(d) PR(p) RUNNING(r) TESTING(D)
#+TODO: BLOCKED(b) BACKLOG(l) PROPOSED(o) | CANCELLED(c)
#+FILETAGS: @work
#+FILETAGS: @work
#+PROPERTY: Effort_ALL 0 4:00 8:00 12:00 20:00 32:00
#+PROPERTY: ESTIMATE_ALL 0 1 2 3 5 8
#+PROPERTY: STORY-TYPE_ALL Feature Bug Chore
#+PROPERTY: NOBLOCKING t
#+COLUMNS: %TODO %40ITEM(Task) %17EFFORT(Estimated){:} %CLOCKSUM(Time Spent) %17STORY-TYPE(Type) %TAGS"))

(defun +grfn/insert-org-template ()
  (interactive)
  (pcase (buffer-file-name)
    ((s-contains "/work/") (+grfn/insert-work-template))))

;;; TODO: this doesn't work?
(define-auto-insert "\\.org?$" #'grfn/insert-org-template t)

(defun forge--post-submit-around---link-pr-to-org-item
    (orig)
  (let ((cb (funcall orig)))
    (lambda (value headers status req)
      (prog1 (funcall cb value headers status req)
        (grfn/at-org-clocked-in-item
         (let ((url (alist-get 'html_url value))
               (number (alist-get 'number value)))
           (org-set-property
            "pull-request"
            (org-make-link-string
             url
             (format "%s/%s/%d"
                     (->> value
                          (alist-get 'base)
                          (alist-get 'repo)
                          (alist-get 'name))
                     (->> value
                          (alist-get 'base)
                          (alist-get 'repo)
                          (alist-get 'owner)
                          (alist-get 'login))
                     number)))))))))

(advice-add
 #'forge--post-submit-callback
 :around #'forge--post-submit-around---link-pr-to-org-item)

(set-face-foreground 'org-block +solarized-s-base00)
(setq whitespace-global-modes '(not org-mode magit-mode vterm-mode))
(setf (alist-get 'file org-link-frame-setup) 'find-file-other-window)
(set-face-foreground 'org-block +solarized-s-base00)

;; (add-hook! org-mode
;;   (set-company-backend! 'org-mode
;;     '(:separate company-ob-postgresql
;;                 company-dabbrev
;;                 company-yasnippet
;;                 company-ispell)))