Last active
November 13, 2023 10:29
-
-
Save Nidish96/fbaeb37b616d7566dec38070e93369c8 to your computer and use it in GitHub Desktop.
An Org-capture template to enable maintaining a directory-local notes file for notes that can be shared/version controlled with a project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(setq org-default-notes-file (concat org-directory "/notes.org")) | |
(defvar org-local-notes-file) | |
(defun my/org-local-get-target () | |
(if (boundp 'org-local-notes-file) | |
(expand-file-name org-local-notes-file) | |
(if (y-or-n-p "A local org note doesn't exist. Create/choose one? ") | |
(progn | |
(add-dir-local-variable | |
nil 'org-local-notes-file | |
(read-file-name "Create/choose local org notes file:")) | |
(save-buffer) (kill-buffer) | |
(hack-dir-local-variables-non-file-buffer) | |
(when (y-or-n-p "Add it to global agenda?") | |
(add-to-list 'org-agenda-files org-local-notes-file)) | |
org-local-notes-file) | |
org-default-notes-file))) | |
;; Create the template | |
(setq org-capture-templates | |
'(("t" "Todo" entry (file+headline "~/org/notes.org" "Tasks") | |
"* TODO %?\n Dated: %u\n Location: %a") | |
("j" "Journal" entry (file+datetree "~/org/journal.org") | |
"* %?\nEntered on %U\n %i\n Location: %a") | |
("l" "Local Tasks" entry (file+headline my/org-local-get-target | |
"Local") | |
"* TODO %?\n Dated: %u\n Location: %a") | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The usage is simple:
While in a file within some repository, if you wanted to create a "local" note, you launch org-capture (default keybinding:
C-c c
) and choose the "Local Tasks" template usingl
.my/org-local-get-target
checks if there is a dir-local variable calledorg-local-notes-file
already defined.org-agenda-files
). It is added if yes. If not, the file is just created.