X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=emacs%2Fnotmuch.el;h=c3ed0cdb2b895a694fd5a24c2ba065122eba83d8;hp=dbf269a572755f7b02f19cd090c7c296881057e0;hb=784649561abb627a9d81e4f718656dad0b6b6207;hpb=8a534dc60d5f4bf579eabda9ae482a1982de3e4e diff --git a/emacs/notmuch.el b/emacs/notmuch.el index dbf269a5..c3ed0cdb 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -204,7 +204,7 @@ For a mouse binding, return nil." (define-key map "p" 'notmuch-search-previous-thread) (define-key map "n" 'notmuch-search-next-thread) (define-key map "r" 'notmuch-search-reply-to-thread) - (define-key map "m" 'notmuch-mua-mail) + (define-key map "m" 'notmuch-mua-new-mail) (define-key map "s" 'notmuch-search) (define-key map "o" 'notmuch-search-toggle-order) (define-key map "c" 'notmuch-search-stash-map) @@ -459,6 +459,44 @@ and will also appear in a buffer named \"*Notmuch errors*\"." (error (buffer-substring beg end)) )))))) +(defun notmuch-tag (query &rest tags) + "Add/remove tags in TAGS to messages matching QUERY. + +TAGS should be a list of strings of the form \"+TAG\" or \"-TAG\" and +QUERY should be a string containing the search-query. + +Note: Other code should always use this function alter tags of +messages instead of running (notmuch-call-notmuch-process \"tag\" ..) +directly, so that hooks specified in notmuch-before-tag-hook and +notmuch-after-tag-hook will be run." + (run-hooks 'notmuch-before-tag-hook) + (apply 'notmuch-call-notmuch-process + (append (list "tag") tags (list "--" query))) + (run-hooks 'notmuch-after-tag-hook)) + +(defcustom notmuch-before-tag-hook nil + "Hooks that are run before tags of a message are modified. + +'tags' will contain the tags that are about to be added or removed as +a list of strings of the form \"+TAG\" or \"-TAG\". +'query' will be a string containing the search query that determines +the messages that are about to be tagged" + + :type 'hook + :options '(hl-line-mode) + :group 'notmuch) + +(defcustom notmuch-after-tag-hook nil + "Hooks that are run before tags of a message are modified. + +'tags' will contain the tags that were added or removed as +a list of strings of the form \"+TAG\" or \"-TAG\". +'query' will be a string containing the search query that determines +the messages that were tagged" + :type 'hook + :options '(hl-line-mode) + :group 'notmuch) + (defun notmuch-search-set-tags (tags) (save-excursion (end-of-line) @@ -498,7 +536,7 @@ and will also appear in a buffer named \"*Notmuch errors*\"." (defun notmuch-search-add-tag-region (tag beg end) (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))) - (notmuch-call-notmuch-process "tag" (concat "+" tag) search-id-string) + (notmuch-tag search-id-string (concat "+" tag)) (save-excursion (let ((last-line (line-number-at-pos end)) (max-line (- (line-number-at-pos (point-max)) 2))) @@ -512,7 +550,7 @@ and will also appear in a buffer named \"*Notmuch errors*\"." (defun notmuch-search-remove-tag-region (tag beg end) (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))) - (notmuch-call-notmuch-process "tag" (concat "-" tag) search-id-string) + (notmuch-tag search-id-string (concat "-" tag)) (save-excursion (let ((last-line (line-number-at-pos end)) (max-line (- (line-number-at-pos (point-max)) 2))) @@ -563,6 +601,10 @@ This function advances the next thread when finished." (notmuch-search-remove-tag-thread "inbox") (forward-line)) +(defvar notmuch-search-process-filter-data nil + "Data that has not yet been processed.") +(make-variable-buffer-local 'notmuch-search-process-filter-data) + (defun notmuch-search-process-sentinel (proc msg) "Add a message to let user know when \"notmuch search\" exits" (let ((buffer (process-buffer proc)) @@ -580,6 +622,8 @@ This function advances the next thread when finished." (insert "Incomplete search results (search process was killed).\n")) (if (eq status 'exit) (progn + (if notmuch-search-process-filter-data + (insert (concat "Error: Unexpected output from notmuch search:\n" notmuch-search-process-filter-data))) (insert "End of search results.") (if (not (= exit-status 0)) (insert (format " (process returned %d)" exit-status))) @@ -606,7 +650,7 @@ The attributes defined for matching tags are merged, with later attributes overriding earlier. A message having both \"delete\" and \"unread\" tags with the above settings would have a green foreground and blue background." - :type '(alist :key-type (string) :value-type (list)) + :type '(alist :key-type (string) :value-type (custom-face-edit)) :group 'notmuch) (defun notmuch-search-color-line (start end line-tag-list) @@ -736,10 +780,6 @@ non-authors is found, assume that all of the authors match." do (notmuch-search-insert-field field date count authors subject tags))) (insert "\n")) -(defvar notmuch-search-process-filter-data nil - "Data that has not yet been processed.") -(make-variable-buffer-local 'notmuch-search-process-filter-data) - (defun notmuch-search-process-filter (proc string) "Process and filter the output of \"notmuch search\"" (let ((buffer (process-buffer proc)) @@ -807,8 +847,7 @@ characters as well as `_.+-'. (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words)) (error "Action must be of the form `+thistag -that_tag'")) (setq words (cdr words)))) - (apply 'notmuch-call-notmuch-process "tag" - (append action-split (list notmuch-search-query-string) nil)))) + (apply 'notmuch-tag notmuch-search-query-string action-split))) (defun notmuch-search-buffer-title (query) "Returns the title for a buffer with notmuch search results."