summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2022-12-26 19:19:30 +0000
committerYann Herklotz <git@yannherklotz.com>2022-12-26 19:19:30 +0000
commitec5ad49bbebbbd1eb0027862dc52811370e2a6d8 (patch)
tree2848ecff4dfe7d2b3d4fdb2bbe938645b96f0ca9
parent74514ec0e2bb06d0a0f87c0a7f8d593231b73e16 (diff)
downloadorg-zettelkasten-ec5ad49bbebbbd1eb0027862dc52811370e2a6d8.tar.gz
org-zettelkasten-ec5ad49bbebbbd1eb0027862dc52811370e2a6d8.zip
Add org-zettelkasten-mapping and direct ID lookup
-rw-r--r--org-zettelkasten.el26
1 files changed, 26 insertions, 0 deletions
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.