summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2023-08-07 00:13:43 -0400
committerKyle Meyer <kyle@kyleam.com>2024-01-22 00:02:53 -0500
commit11b66c57ff48fbfd7ab1df3423b2289a7673347d (patch)
treea13f83db143c0eb5159775de0f206d9cdde44ceb /lisp
parent68f7291a812d86f04ed38656019467f9a470abd0 (diff)
downloademacs.d-11b66c57ff48fbfd7ab1df3423b2289a7673347d.tar.gz
denote: Add custom command to find file at point
Diffstat (limited to 'lisp')
-rw-r--r--lisp/km-denote.el17
1 files changed, 17 insertions, 0 deletions
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