From ec5ad49bbebbbd1eb0027862dc52811370e2a6d8 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 26 Dec 2022 19:19:30 +0000 Subject: Add org-zettelkasten-mapping and direct ID lookup --- org-zettelkasten.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/org-zettelkasten.el b/org-zettelkasten.el index 90a6d94..b94afb5 100644 --- a/org-zettelkasten.el +++ b/org-zettelkasten.el @@ -43,6 +43,12 @@ :type 'string :group 'org-zettelkasten) +(defcustom org-zettelkasten-mapping nil + "Main zettelkasten directory." + :type '(alist :key-type (natnum :tag "Value") + :value-type (string :tag "File name")) + :group 'org-zettelkasten) + (defcustom org-zettelkasten-prefix [(control ?c) ?y] "Prefix key to use for Zettelkasten commands in Zettelkasten minor mode. The value of this variable is checked as part of loading Zettelkasten mode. @@ -50,6 +56,26 @@ After that, changing the prefix key requires manipulating keymaps." :type 'key-sequence :group 'org-zettelkasten) +(defun org-zettelkasten-abs-file (file) + "Return FILE name relative to `org-zettelkasten-directory'." + (expand-file-name file org-zettelkasten-directory)) + +(defun org-zettelkasten-prefix (ident) + "Return the prefix identifier for IDENT. + +This function assumes that IDs will start with a number." + (when (string-match "^\\([0-9]*\\)" ident) + (string-to-number (match-string 1 ident)))) + +(defun org-zettelkasten-goto-id (id) + "Go to an ID automatically." + (interactive "sID: #") + (let ((file (alist-get (org-zettelkasten-prefix id) + org-zettelkasten-mapping))) + (org-link-open-from-string + (concat "[[file:" (org-zettelkasten-abs-file file) + "::#" id "]]")))) + (defun org-zettelkasten-incr-id (ident) "Simple function to increment any IDENT. -- cgit