add rudimentary completion support for retag action

This adds a variable mu4e-action-tags-completion-list, that contains a
list of commonly used tags to suggest as completion terms during a retag
actions.

Along the way, the retag action accepts as argument a comma-separated
list of +tag and -tag keywords, instead of a space-separated one,
removing the need to quote tags with spaces in them, and making it
consistent with the behaviour of completing-read-multiple.
This commit is contained in:
Abdo Roig-Maranges 2014-10-30 14:08:14 +01:00
parent 2507933176
commit cba2e0c21c
1 changed files with 20 additions and 5 deletions

View File

@ -240,6 +240,10 @@ bother asking for the git tree again (useful for bulk actions)."
this setting on already tagged messages can lead to messages this setting on already tagged messages can lead to messages
with multiple tags headers.") with multiple tags headers.")
(defvar mu4e-action-tags-completion-list '()
"List of tags to show for autocompletion in
`mu4e-action-retag-message'.")
(defun mu4e~contains-line-matching (regexp path) (defun mu4e~contains-line-matching (regexp path)
"Determine whether the file at path contains a line matching "Determine whether the file at path contains a line matching
the given regexp." the given regexp."
@ -262,12 +266,23 @@ bother asking for the git tree again (useful for bulk actions)."
(replace-match to-string nil nil))))) (replace-match to-string nil nil)))))
(defun mu4e-action-retag-message (msg &optional retag-arg) (defun mu4e-action-retag-message (msg &optional retag-arg)
"Change tags of a message. Example: +tag \"+long tag\" -oldtag "Change tags of a message. Accepts a comma-separated list of
adds 'tag' and 'long tag', and removes oldtag." additions and removals.
(let* ((retag (or retag-arg (read-string "Tags: ")))
(path (mu4e-message-field msg :path)) Example: +tag,+long tag,-oldtag
would add 'tag' and 'long tag', and remove 'oldtag'."
(let* (
(path (mu4e-message-field msg :path))
(maildir (mu4e-message-field msg :maildir)) (maildir (mu4e-message-field msg :maildir))
(oldtags (mu4e-message-field msg :tags)) (oldtags (mu4e-message-field msg :tags))
(tags-completion (append
mu4e-action-tags-completion-list
(mapcar (lambda (tag) (format "+%s" tag)) mu4e-action-tags-completion-list)
(mapcar (lambda (tag) (format "-%s" tag)) oldtags)))
(retag (if retag-arg
(split-string retag-arg ",")
(completing-read-multiple "Tags: " tags-completion)))
(header mu4e-action-tags-header) (header mu4e-action-tags-header)
(sep (cond ((string= header "Keywords") ", ") (sep (cond ((string= header "Keywords") ", ")
((string= header "X-Label") " ") ((string= header "X-Label") " ")
@ -275,7 +290,7 @@ bother asking for the git tree again (useful for bulk actions)."
(t ", "))) (t ", ")))
(taglist (if oldtags (copy-sequence oldtags) '())) (taglist (if oldtags (copy-sequence oldtags) '()))
tagstr) tagstr)
(dolist (tag (split-string-and-unquote retag) taglist) (dolist (tag retag taglist)
(cond (cond
((string-match "^\\+\\(.+\\)" tag) ((string-match "^\\+\\(.+\\)" tag)
(setq taglist (push (match-string 1 tag) taglist))) (setq taglist (push (match-string 1 tag) taglist)))