From 9897983cca490e63f2b2c0b1ef774ac5d6bf9049 Mon Sep 17 00:00:00 2001 From: Grant Rosson Date: Sat, 20 Nov 2021 11:16:32 +0200 Subject: [PATCH] Refine zetteldeft-generate-id, for rapid unique ID generation Adds a loop to check if ID is unavailable, incrementing ID until it is unique Avoids error message and the need to wait for time to change in orer to create a unique ID. --- zetteldeft.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/zetteldeft.el b/zetteldeft.el index c56ff8d..19a1438 100644 --- a/zetteldeft.el +++ b/zetteldeft.el @@ -188,15 +188,15 @@ 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)) -(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)))) (defcustom zetteldeft-custom-id-function nil "User-defined function to generate an ID.