summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.el3
-rw-r--r--lisp/km-denote.el17
2 files changed, 19 insertions, 1 deletions
diff --git a/init.el b/init.el
index a4a482f..7408dcf 100644
--- a/init.el
+++ b/init.el
@@ -1719,7 +1719,8 @@
:bind (("C-c d d" . denote)
("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 f" . km/find-file-with-denote-naming)
+ ("C-c d ." . km/denote-find-file-at-point))
: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 1a9e622..eade820 100644
--- a/lisp/km-denote.el
+++ b/lisp/km-denote.el
@@ -36,5 +36,22 @@ from the file name."
(denote-retrieve-filename-title fname)
(denote-extract-keywords-from-path fname))))
+;;;###autoload
+(defun km/denote-find-file-at-point ()
+ "Find the file in `denote-directory' for the denote ID at point.
+The file must be tracked in Git."
+ (interactive)
+ (let ((id (save-excursion
+ (let ((case-fold-search nil))
+ (skip-chars-backward "-a-z0-9_T"))
+ (if (looking-at denote-id-regexp)
+ (match-string-no-properties 0)
+ (user-error "No denote ID at point"))))
+ (default-directory denote-directory))
+ (find-file
+ (car (or (process-lines "git" "ls-files" "--" (concat id "--*"))
+ (process-lines "git" "ls-files" "--" (concat "**/" id "--*"))
+ (user-error "No tracked file found for %s" id))))))
+
(provide 'km-denote)
;;; km-denote.el ends here