Skip to content

Commit

Permalink
update zetteldeft.org to include rapid id creation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias Storms committed Dec 14, 2021
1 parent 9897983 commit 639b619
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions zetteldeft.org
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Check out the Github [[https://github.com/EFLS/zetteldeft][repository]] to get t
Read on for an introduction and some documentation.

Latest additions:
- *14 Dec*: Refine =zetteldeft-generate-id= to allow rapid ID creation (thanks to localauthor)
- *19 Aug*: Update =zetteldeft-browse= to handle more keys
- *01 Aug*: Automated [[#list-links][list of links]] with =zetteldeft-insert-list-links-block=
- *13 Jul*: Where backlinks go is now customizable with =zetteldeft-backlink-location-function=
Expand Down Expand Up @@ -564,9 +565,8 @@ For good measure: I advise creating new notes in the =zetteldeft= system with =z
Next up, a function to generate an ID string.
By default, the above time-based format will be used, unless a custom ID generator function is specified: to override the way an ID is generated, point =zetteldeft-custom-id-function= to a custom function.

The above function performs a rudimentory check to ensure that the generated ID is indeed available (i.e., not yet used in a filename).
The current response to such a duplicate is to throw an error.
With the default, time-based IDs, this happens when notes are created in quick succession.
We need to ensure the generated ID is available (i.e., if the ID string is not already used in another filename).
If it is, we simply increase its number by one.

#+BEGIN_SRC emacs-lisp
(defun zetteldeft-generate-id (title &optional filename)
Expand All @@ -578,19 +578,19 @@ that function is used and TITLE and FILENAME are passed to it."
(if-let ((f zetteldeft-custom-id-function))
(funcall f title filename)
(format-time-string zetteldeft-id-format))))
(if (zetteldeft--id-available-p id)
id
(error "Generated ID %s is not unique." id))))
(while (zetteldeft--id-unavailable-p id)
(setq id (number-to-string (1+ (string-to-number id)))))
id))
#+END_SRC

The check whether an ID is available is performed by a separate function.
To achieve this, we need a check to ensure the ID is available.

#+BEGIN_SRC emacs-lisp
(defun zetteldeft--id-available-p (str)
"Return t only if provided string STR is unique among Zetteldeft filenames."
(defun zetteldeft--id-unavailable-p (str)
"Return t if provided string STR occurs among Zetteldeft filenames."
(let ((deft-filter-only-filenames t))
(deft-filter str t))
(eq 0 (length deft-current-files)))
(not (eq 0 (length deft-current-files))))
#+END_SRC

**** =zetteldeft-custom-id-function= for fine-grained control over ID formatting
Expand Down

0 comments on commit 639b619

Please sign in to comment.