aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2022-07-25 18:23:27 +0100
committerYann Herklotz <git@yannherklotz.com>2022-07-25 18:23:27 +0100
commit5fa948014a06e9352c219bee4ef2315f9d32923b (patch)
treeb7eefc402638d9f235aa4e1f92a1e7dc44b1aade
parent13f415f95ba792f112c0f92cddf3dda24903a0b8 (diff)
downloademacs-zettelkasten-custom-id-support.tar.gz
emacs-zettelkasten-custom-id-support.zip
Add new function to create custom IDcustom-id-support
-rw-r--r--zettelkasten.el28
1 files changed, 24 insertions, 4 deletions
diff --git a/zettelkasten.el b/zettelkasten.el
index 2f8090c..cad3b8b 100644
--- a/zettelkasten.el
+++ b/zettelkasten.el
@@ -12,7 +12,7 @@
;;; License:
-;; Copyright (C) 2020-2021 Yann Herklotz
+;; Copyright (C) 2020-2022 Yann Herklotz
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -211,12 +211,15 @@ This is deprecated in favour for `zettelkasten-list-notes'."
(goto-char (point-max))
(insert "\n" (zettelkasten--format-link note))))
-(defun zettelkasten--create-new-note-ni (title &optional parent)
+(defun zettelkasten--create-new-note-ni (title &optional parent custom-id)
"Create a new note based on the TITLE and it's optional PARENT note.
-If PARENT is nil, it will not add a link from a PARENT."
+If PARENT is nil, it will not add a link from a PARENT.
+
+If CUSTOM-ID is not nil, will not generate a time-based ID but
+will use that instead."
(let* ((note (zettelkasten--find-new-note-name
- (format-time-string zettelkasten-file-format)))
+ (or custom-id (format-time-string zettelkasten-file-format))))
(filename (zettelkasten--make-filename note)))
(with-temp-buffer
(set-visited-file-name filename)
@@ -404,6 +407,23 @@ Also see `zettelkasten--create-new-note-ni' for more information."
(unless (or prefix (not notes))
(completing-read "Parent note: " notes nil 'match)))))
+(defun zettelkasten-create-new-custom-note (prefix)
+ "Create a new zettelkasten.
+
+If PREFIX is used, or if the `zettelkasten-directory' is empty,
+does not create a parent.
+
+Also see `zettelkasten--create-new-note-ni' for more information."
+ (interactive "P")
+ (let ((title (read-string "Note title: "))
+ (notes (zettelkasten--list-notes)))
+ (zettelkasten--create-new-note-ni
+ title
+ (unless (or prefix (not notes))
+ (completing-read "Parent note: " notes nil 'match))
+ (let ((id (read-string "Note ID: ")))
+ (if (string= id "") nil id)))))
+
(defun zettelkasten-open-parent (&optional note)
"Find the parent notes to the NOTE that is given.