summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2023-11-18 23:22:26 -0500
committerKyle Meyer <kyle@kyleam.com>2024-01-22 00:02:53 -0500
commit8c71aff19ebf41103b367a367f5fd75bd014957f (patch)
tree8f62ef64772cbd757b5a153e3281e24df16efba5
parent11b66c57ff48fbfd7ab1df3423b2289a7673347d (diff)
downloademacs.d-8c71aff19ebf41103b367a367f5fd75bd014957f.tar.gz
denote: Add custom command for inserting denote ID
-rw-r--r--init.el3
-rw-r--r--lisp/km-denote.el13
2 files changed, 15 insertions, 1 deletions
diff --git a/init.el b/init.el
index 7408dcf..669dc32 100644
--- a/init.el
+++ b/init.el
@@ -1720,7 +1720,8 @@
("C-c d D" . denote-date)
("C-c d t" . denote-type)
("C-c d f" . km/find-file-with-denote-naming)
- ("C-c d ." . km/denote-find-file-at-point))
+ ("C-c d ." . km/denote-find-file-at-point)
+ ("C-c d i" . km/denote-insert-id))
:config
(setq denote-directory (expand-file-name "~/notes"))
(setq denote-dired-directories (list denote-directory))
diff --git a/lisp/km-denote.el b/lisp/km-denote.el
index eade820..24e98d2 100644
--- a/lisp/km-denote.el
+++ b/lisp/km-denote.el
@@ -53,5 +53,18 @@ The file must be tracked in Git."
(process-lines "git" "ls-files" "--" (concat "**/" id "--*"))
(user-error "No tracked file found for %s" id))))))
+(defun km/denote-insert-id (&optional with-prefix)
+ "Insert ID of tracked file in `denote-directory'.
+When WITH-PREFIX is non-nil, prepend \"denote:\" to the inserted
+ID."
+ (interactive "P")
+ (let* ((default-directory denote-directory)
+ (id (or (denote-extract-id-from-string
+ (completing-read
+ "Note: "
+ (process-lines "git" "ls-files" "--" "*--*")))
+ (error "Could not determine ID"))))
+ (insert (concat (and with-prefix "denote:") id))))
+
(provide 'km-denote)
;;; km-denote.el ends here