-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit-writing.el
More file actions
289 lines (256 loc) · 9.41 KB
/
Copy pathinit-writing.el
File metadata and controls
289 lines (256 loc) · 9.41 KB
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
;; notes
(defvar my-notes-directory (expand-file-name "notes" my-code-directory))
(defvar my-notes-bibliography-file (expand-file-name "reference.bib" my-notes-directory))
(defvar my-notes-attachments-directory (expand-file-name "attachments" my-notes-directory))
(use-package org
:ensure nil
:init
(setq org-directory (expand-file-name "org" my-sync-directory))
:bind
(("C-c a" . org-agenda)
("C-c c" . org-capture)
("C-c l" . org-store-link)
:map org-mode-map
([remap mark-defun] . org-babel-mark-block)
("M-g o" . consult-org-heading)
("C-c C-M-l" . org-toggle-link-display)
("C-M-<return>" . org-insert-subheading))
:custom
(org-use-fast-todo-selection 'expert)
(org-use-sub-superscripts '{})
;; Editing
(org-catch-invisible-edits 'show-and-error)
(org-insert-heading-respect-content t)
(org-special-ctrl-a/e t)
;; Export
(org-export-dispatch-use-expert-ui t)
(org-export-with-sub-superscripts '{})
(org-export-with-toc nil)
;; Styling
(org-ellipsis "…")
(org-hide-emphasis-markers t)
(org-pretty-entities t)
;; Agenda
(org-agenda-files (list org-directory))
(org-agenda-tags-column 0)
;; Capture
(org-capture-templates
`(("t" "To-do" entry
(file "to-dos.org")
,(concat "* TODO %^{Title} %^g\n"
":PROPERTIES:\n"
":CAPTURED: %U\n"
":CUSTOM_ID: h:%(format-time-string \"%Y%m%dT%H%M%S\")\n"
":END:\n\n"
"%?")
:empty-lines-after 1
:prepend t)
("e" "Email" entry ; Also see `org-capture-templates-contexts'
(file "to-dos.org")
,(concat "* TODO %:subject :mail:\n"
":PROPERTIES:\n"
":CAPTURED: %U\n"
":CUSTOM_ID: h:%(format-time-string \"%Y%m%dT%H%M%S\")\n"
":END:\n\n"
"%a")
:immediate-finish t
:empty-lines-after 1
:prepend t)
("j" "Journal" entry
(file+olp+datetree "journal.org")
,(concat "* %^{Title} %^g\n"
":PROPERTIES:\n"
":CAPTURED: %U\n"
":CUSTOM_ID: h:%(format-time-string \"%Y%m%dT%H%M%S\")\n"
":END:"))
))
(org-capture-templates-contexts
'(("e" ((in-mode . "notmuch-search-mode")
(in-mode . "notmuch-show-mode")
(in-mode . "notmuch-tree-mode")))))
;; Code block
(org-edit-src-content-indentation 0)
(org-edit-src-persistent-message nil)
(org-src-preserve-indentation t)
(org-src-window-setup 'current-window)
;; Log
(org-log-into-drawer t)
(org-log-done 'time)
(org-log-redeadline 'note)
(org-log-reschedule 'note)
;; Tag
(org-auto-align-tags nil)
(org-tags-column 0)
:config
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(shell . t)
(ruby . t)
(python . t))))
(use-package org-modern
:after org
:custom
(org-modern-star nil)
(org-modern-table nil)
:config
(global-org-modern-mode))
(use-package ox-hugo
:pin melpa
:after org
:custom
(org-hugo-default-static-subdirectory-for-externals "attachments")
(org-hugo-front-matter-format "yaml"))
(use-package denote-hugo
:ensure nil
:load-path "site-lisp/"
:bind ("C-c n h" . denote-hugo-find-file))
(use-package denote-pi-skills
:ensure nil
:load-path "site-lisp/"
:bind ("C-c n p" . denote-pi-skills-export))
(use-package ox-gfm
:pin melpa
:after org)
(use-package denote
:init
(setq denote-directory my-notes-directory)
:hook (dired-mode . denote-dired-mode)
:bind
(("C-c n n" . denote-open-or-create)
("C-c n N" . denote-open-or-create-with-command)
("C-c n o" . denote-sort-dired)
("C-c n r" . denote-rename-file)
:map text-mode-map
("C-c n i" . denote-link-or-create)
("C-c n I" . denote-add-links)
("C-c n b" . denote-backlinks)
("C-c n R" . denote-rename-file-using-front-matter)
:map dired-mode-map
("C-c C-d C-i" . denote-link-dired-marked-notes)
("C-c C-d C-r" . denote-dired-rename-marked-files)
("C-c C-d C-k" . denote-dired-rename-marked-files-with-keywords)
("C-c C-d C-f" . denote-dired-rename-marked-files-using-front-matter))
:custom
(denote-save-buffers t)
(denote-known-keywords nil)
:config
(denote-rename-buffer-mode 1)
(advice-add 'denote-link-ol-export :around
(lambda (orig-fun link description format)
"Advice for `denote-link-ol-export' that customizes Org link export to Hugo Markdown.
If exporting to markdown ('md') with Hugo backend (`org-export-current-backend' is 'hugo'),
replace export with a relref shortcode referencing either the EXPORT_FILE_NAME or the file basename.
Otherwise, call the original function."
(if (and (eq format 'md)
(eq org-export-current-backend 'hugo))
(let* ((path (denote-get-path-by-id link))
(export-file-name
(or
(when (file-exists-p path)
(with-temp-buffer
(insert-file-contents path)
(goto-char (point-min))
(when (re-search-forward "^#\\+export_file_name: \\(.+\\)" nil t)
(match-string 1))))
(file-name-nondirectory path))))
(format "[%s]({{< relref \"%s\" >}})"
description
export-file-name))
(funcall orig-fun link description format)))))
(use-package denote-org
:after denote
:custom
(denote-org-capture-specifiers "%i\n%?")
:config
(keymap-set org-mode-map "C-c n a" 'my/denote-org-insert-attachment)
(keymap-set org-mode-map "C-c n d l" 'denote-org-dblock-insert-links)
(keymap-set org-mode-map "C-c n d b" 'denote-org-dblock-insert-backlinks)
(defun my/denote-org-insert-attachment (file)
"Process FILE to use as an attachment in the current buffer.
If FILE is already in the attachments directory, simply insert a link to it.
Otherwise, rename it using `denote-rename-file' with a title derived from
the filename, move it to the attachments directory, and insert a link.
The link format used is '[[file:attachments/filename]]', following Org syntax.
This function is ideal for managing referenced files in note-taking workflows."
(interactive (list (read-file-name "File: " my-notes-attachments-directory)))
(let* ((orig-buffer (current-buffer))
(attachments-dir my-notes-attachments-directory))
;; Check if the file is already in the attachments directory
(if (string-prefix-p
(file-name-as-directory attachments-dir)
(expand-file-name file))
;; If already in attachments, just insert the link
(with-current-buffer orig-buffer
(insert (format "[[file:attachments/%s]]" (file-name-nondirectory file))))
;; Otherwise, rename and move the file
(let ((title (denote-sluggify-title (file-name-base file))))
(when-let* ((renamed-file (denote-rename-file file title nil nil nil nil))
(renamed-name (file-name-nondirectory renamed-file))
(final-path (expand-file-name renamed-name attachments-dir)))
(rename-file renamed-file final-path t)
(with-current-buffer orig-buffer
(insert (format "[[file:attachments/%s]]" renamed-name)))))))))
(use-package denote-journal
:bind (("C-c n j" . denote-journal-new-or-existing-entry)
("C-c n J" . denote-journal-new-entry)))
(use-package denote-sequence
:bind
(("C-c n s s" . denote-sequence)
("C-c n s f" . denote-sequence-find)
("C-c n s l" . denote-sequence-link)
("C-c n s d" . denote-sequence-dired)
("C-c n s r" . denote-sequence-reparent)
("C-c n s c" . denote-sequence-convert))
:custom
(denote-sequence-scheme 'alphanumeric))
(use-package consult-denote
:init
(with-eval-after-load 'denote
(consult-denote-mode 1))
:bind
(("C-c n f" . consult-denote-find)
("C-c n g" . consult-denote-grep))
:custom
(consult-denote-find-command #'consult-fd)
(consult-denote-grep-command #'consult-ripgrep))
(use-package denote-explore
:pin melpa
:bind ("C-c n x" . denote-explore-sync-metadata))
(use-package citar-denote
:pin melpa
:init
(with-eval-after-load 'citar
(citar-denote-mode 1))
:bind
(("C-c w n" . citar-create-note)
("C-c w o" . citar-denote-open-note)
("C-c w d" . citar-denote-dwim)
("C-c w e" . citar-denote-open-reference-entry)
("C-c w a" . citar-denote-add-reference)
("C-c w k" . citar-denote-remove-reference)
("C-c w r" . citar-denote-find-reference)
("C-c w l" . citar-denote-link-reference)
("C-c w f" . citar-denote-find-citation)
("C-c w x" . citar-denote-nocite)
("C-c w y" . citar-denote-cite-nocite)
("C-c w z" . citar-denote-nobib)))
(use-package citar
:pin melpa
:bind ("C-c r" . citar-open) ; mnemonic: references
:init
(setq org-cite-global-bibliography `(,my-notes-bibliography-file))
(setq org-cite-insert-processor 'citar)
(setq org-cite-follow-processor 'citar)
(setq org-cite-activate-processor 'citar)
:custom
(citar-bibliography org-cite-global-bibliography)
(citar-at-point-function #'embark-act)
:config
(add-to-list 'citar-file-open-functions (cons "pdf" #'citar-file-open-external)))
(use-package citar-embark
:pin melpa
:after (citar embark)
:config
(citar-embark-mode 1))
(provide 'init-writing)