From 9160a3d77301505e11793f863c0f96b4c846a407 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 2 Apr 2024 16:47:23 +0300 Subject: gnosis-tag-prompt: Rewrite Since we are not using gnosis-tag-prompt to input tags for notes, this was due for a rewrite. This function will be used to select tags, which could be used to output a note-id collection for specified tags. --- gnosis.el | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/gnosis.el b/gnosis.el index c6cdfc2..6d97171 100644 --- a/gnosis.el +++ b/gnosis.el @@ -919,30 +919,25 @@ DATE is a list of the form (year month day)." (time-date (encode-time 0 0 0 (nth 2 date) (nth 1 date) (nth 0 date)))) (not (time-less-p time-now time-date)))) - -(cl-defun gnosis-tag-prompt (&key (prompt "Selected tags") (match nil) (due nil)) +(cl-defun gnosis-tag-prompt (&key (prompt "Selected tags:") (due nil)) "PROMPT user to select tags, until they enter `q'. -Prompt user to select tags, generated from `gnosis-get-tags--unique'. +Prompt user to select tags, generated from `gnosis-get-tags--unique'. PROMPT: Prompt string value MATCH: Require match, t or nil value -DUE: if t, return tags for due notes from `gnosis-due-tags'. -Returns a list of unique tags." - (let* ((tags '()) - (tag "") - (use-prev (when gnosis-previous-note-tags - (y-or-n-p (format "Use tags from previous note %s?" gnosis-previous-note-tags))))) - (if use-prev - (setf tags gnosis-previous-note-tags) - (while (not (string= tag "q")) - (setf tag (funcall gnosis-completing-read-function (concat prompt (format " %s (q for quit): " tags)) - (cons "q" (if due (gnosis-review-get-due-tags) - (gnosis-get-tags--unique))) - nil match)) - (unless (or (string= tag "q") (member tag tags)) - (push tag tags)))) - (setf gnosis-previous-note-tags (if use-prev tags (reverse tags))) - (reverse tags))) +DUE: if t, return tags for due notes from `gnosis-due-tags'." + (let ((tags '())) + (cond ((and due (null (gnosis-review-get-due-notes))) + (message "No due notes.")) + (t (cl-loop for tag = (completing-read + (concat prompt (format " (%s) (q for quit): " (mapconcat #'identity tags " "))) + (cons "q" (if due (gnosis-review-get-due-tags) + (gnosis-get-tags--unique))) + nil t) + until (string= tag "q") + unless (member tag tags) + do (push tag tags)) + tags)))) (defun gnosis-hint-prompt (previous-hint &optional prompt) "Prompt user for hint. -- cgit v1.2.3