From 5fa948014a06e9352c219bee4ef2315f9d32923b Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 25 Jul 2022 18:23:27 +0100 Subject: [PATCH] Add new function to create custom ID --- zettelkasten.el | 28 ++++++++++++++++++++++++---- 1 file 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.