emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote ced969aecf 2/2: Make denote-keywords-remove use


From: ELPA Syncer
Subject: [elpa] externals/denote ced969aecf 2/2: Make denote-keywords-remove use completing-read-multiple
Date: Sat, 15 Oct 2022 08:57:29 -0400 (EDT)

branch: externals/denote
commit ced969aecf711b109856a7a8b51a68d166411090
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Make denote-keywords-remove use completing-read-multiple
    
    This makes the interface consistent with denote-keywords-add and, by
    extension, with every command that leverages the denote-keywords-prompt.
---
 README.org |  5 +++--
 denote.el  | 27 +++++++++++++++++++++------
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/README.org b/README.org
index d47a7c71b9..ef3736f83a 100644
--- a/README.org
+++ b/README.org
@@ -477,8 +477,9 @@ The ~denote-keywords-add~ asks for keywords using the 
familiar
 minibuffer prompt ([[#h:6a92a8b5-d766-42cc-8e5b-8dc255466a23][Standard note 
creation]]).  It then renames the file
 ([[#h:3ab08ff4-81fa-4d24-99cb-79f97c13a373][Rename a single file based on its 
front matter]]).
 
-Similarly, the ~denote-keywords-remove~ removes a keyword from the list
-of existing keywords and then renames the file accordingly.
+Similarly, the ~denote-keywords-remove~ removes one or more keywords
+from the list of existing keywords and then renames the file
+accordingly.
 
 ** Create note using Org capture
 :PROPERTIES:
diff --git a/denote.el b/denote.el
index 49dc085b24..5ae0905573 100644
--- a/denote.el
+++ b/denote.el
@@ -703,11 +703,13 @@ existing notes and combine them into a list with
 (defvar denote--keyword-history nil
   "Minibuffer history of inputted keywords.")
 
-(defun denote--keywords-crm (keywords)
-  "Use `completing-read-multiple' for KEYWORDS."
+(defun denote--keywords-crm (keywords &optional prompt)
+  "Use `completing-read-multiple' for KEYWORDS.
+With optional PROMPT, use it instead of a generic text for file
+keywords."
   (delete-dups
    (completing-read-multiple
-    "File keyword: " keywords
+    (or prompt "File keyword: ") keywords
     nil nil nil 'denote--keyword-history)))
 
 (defun denote-keywords-prompt ()
@@ -1594,9 +1596,19 @@ the new front matter, per 
`denote-rename-file-using-front-matter'."
         (denote-rename-file-using-front-matter file t))
     (message "Buffer not visiting a Denote file")))
 
+(defun denote--keywords-delete-prompt (keywords)
+  "Prompt for one or more KEYWORDS.
+In the case of multiple entries, those are separated by the
+`crm-sepator', which typically is a comma.  In such a case, the
+output is sorted with `string-lessp'."
+  (let ((choice (denote--keywords-crm keywords "Keyword to remove: ")))
+    (if denote-sort-keywords
+        (sort choice #'string-lessp)
+      choice)))
+
 ;;;###autoload
 (defun denote-keywords-remove ()
-  "Prompt for a keyword in current note and remove it.
+  "Prompt for keywords in current note and remove them.
 Keywords are retrieved from the file's front matter.
 
 Rename the file without further prompt so that its name reflects
@@ -1608,8 +1620,11 @@ the new front matter, per 
`denote-rename-file-using-front-matter'."
             (file-type (denote-filetype-heuristics file)))
       (when-let* ((cur-keywords (denote-retrieve-keywords-value file 
file-type))
                   ((or (listp cur-keywords) (not (string-blank-p 
cur-keywords))))
-                  (del-keyword (completing-read "Keyword to remove: " 
cur-keywords nil t)))
-        (denote--rewrite-keywords file (delete del-keyword cur-keywords) 
file-type)
+                  (del-keyword (denote--keywords-delete-prompt cur-keywords)))
+        (denote--rewrite-keywords
+         file
+         (seq-difference cur-keywords del-keyword)
+         file-type)
         (denote-rename-file-using-front-matter file t))
     (message "Buffer not visiting a Denote file")))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]