branch: elpa/elfeed
commit 8b6f058c360c64d130ac8447faec664141ac3e9f
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>

    elfeed-search--prompt-tags: Use completing-read-multiple
    
    elfeed-search-tag/untag/toggle-all accept multiple tag arguments now.
---
 elfeed-search.el | 55 +++++++++++++++++++++++++++++++------------------------
 elfeed-show.el   | 12 ++++++------
 2 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/elfeed-search.el b/elfeed-search.el
index d76513137b..3d3e1ee6bc 100644
--- a/elfeed-search.el
+++ b/elfeed-search.el
@@ -941,38 +941,45 @@ the browser defined by 
`browse-url-secondary-browser-function'."
       (mapc #'elfeed-search-update-entry entries)
       (elfeed-search--after-action 'yank))))
 
-(defun elfeed-search--prompt-tag ()
-  "Prompt for tag in the minibuffer."
-  (let ((tag (read-from-minibuffer "Tag: ")))
-    (when (equal tag "") (user-error "No tag given!"))
-    (intern tag)))
-
-(defun elfeed-search-tag-all (tag)
-  "Apply TAG to all selected entries."
-  (interactive (list (elfeed-search--prompt-tag)) elfeed-search-mode)
+(defun elfeed-search--prompt-tags (prompt &optional tags)
+  "Prompt for tags in the minibuffer.
+PROMPT is the prompt string and TAGS is an optional tags list to
+restrict completion."
+  (setq tags (completing-read-multiple
+              prompt
+              (mapcar #'symbol-name (or tags (elfeed-db-get-all-tags)))
+              nil (consp tags)))
+  (unless tags (user-error "No tags given!"))
+  (mapcar #'intern tags))
+
+(defun elfeed-search-tag-all (&rest tags)
+  "Apply TAGS to all selected entries."
+  (interactive (elfeed-search--prompt-tags "Tag: ") elfeed-search-mode)
   (let ((entries (elfeed-search-selected)))
-    (elfeed-tag entries tag)
+    (apply #'elfeed-tag entries tags)
     (mapc #'elfeed-search-update-entry entries)
     (elfeed-search--after-action 'tag)))
 
-(defun elfeed-search-untag-all (tag)
-  "Remove TAG from all selected entries."
-  (interactive (list (elfeed-search--prompt-tag)) elfeed-search-mode)
+(defun elfeed-search-untag-all (&rest tags)
+  "Remove TAGS from all selected entries."
+  (interactive (elfeed-search--prompt-tags "Untag: ") elfeed-search-mode)
   (let ((entries (elfeed-search-selected)))
-    (elfeed-untag entries tag)
+    (apply #'elfeed-untag entries tags)
     (mapc #'elfeed-search-update-entry entries)
     (elfeed-search--after-action 'tag)))
 
-(defun elfeed-search-toggle-all (tag)
-  "Toggle TAG on all selected entries."
-  (interactive (list (elfeed-search--prompt-tag)) elfeed-search-mode)
-  (let ((entries (elfeed-search-selected)) entries-tag entries-untag)
-    (cl-loop for entry in entries
-             when (elfeed-tagged-p tag entry)
-             do (push entry entries-untag)
-             else do (push entry entries-tag))
-    (elfeed-tag entries-tag tag)
-    (elfeed-untag entries-untag tag)
+(defun elfeed-search-toggle-all (&rest tags)
+  "Toggle TAGS on all selected entries."
+  (interactive (elfeed-search--prompt-tags "Toggle: ") elfeed-search-mode)
+  (let ((entries (elfeed-search-selected)))
+    (dolist (tag tags)
+      (let (entries-tag entries-untag)
+        (cl-loop for entry in entries
+                 when (elfeed-tagged-p tag entry)
+                 do (push entry entries-untag)
+                 else do (push entry entries-tag))
+        (elfeed-tag entries-tag tag)
+        (elfeed-untag entries-untag tag)))
     (mapc #'elfeed-search-update-entry entries)
     (elfeed-search--after-action 'tag)))
 
diff --git a/elfeed-show.el b/elfeed-show.el
index 2aa9f17e85..0592eb3dae 100644
--- a/elfeed-show.el
+++ b/elfeed-show.el
@@ -329,7 +329,7 @@ the browser defined by 
`browse-url-secondary-browser-function'."
 
 (defun elfeed-show-tag (&rest tags)
   "Add TAGS to the displayed entry."
-  (interactive (list (elfeed-search--prompt-tag)) elfeed-show-mode)
+  (interactive (elfeed-search--prompt-tags "Tag: ") elfeed-show-mode)
   (let ((entry elfeed-show-entry))
     (apply #'elfeed-tag entry tags)
     (with-current-buffer (elfeed-search-buffer)
@@ -338,11 +338,11 @@ the browser defined by 
`browse-url-secondary-browser-function'."
 
 (defun elfeed-show-untag (&rest tags)
   "Remove TAGS from the displayed entry."
-  (interactive (let* ((tags (elfeed-entry-tags elfeed-show-entry))
-                      (names (mapcar #'symbol-name tags))
-                      (select (completing-read "Untag: " names nil :match)))
-                 (list (intern select)))
-               elfeed-show-mode)
+  (interactive
+   (elfeed-search--prompt-tags "Untag: "
+                               (or (elfeed-entry-tags elfeed-show-entry)
+                                   (user-error "Entry does not have tags")))
+   elfeed-show-mode)
   (let ((entry elfeed-show-entry))
     (apply #'elfeed-untag entry tags)
     (with-current-buffer (elfeed-search-buffer)

Reply via email to