Merge pull request #911 from aroig/gh/tag-completion

mu4e: add rudimentary completion support for retag action
This commit is contained in:
Dirk-Jan C. Binnema
2016-09-03 11:26:47 +03:00
committed by GitHub

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)))