Skip to content

Commit

Permalink
Add new function to create custom ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ymherklotz committed Jul 25, 2022
1 parent 13f415f commit 5fa9480
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions zettelkasten.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5fa9480

Please # to comment.