X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=emacs%2Fnotmuch-show.el;h=701212544b51d354e3cb639b8c4e625358714aa2;hb=d5e4ff0580c9635740fe745f766ec9d10a94809e;hp=98d25ef4066445287d8ebba104c82f6f3d19e4cf;hpb=4e77148a4ba9f3b217241818ea65f282ec434e56;p=notmuch diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 98d25ef4..70121254 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -21,7 +21,7 @@ ;; Authors: Carl Worth ;; David Edmondson -(require 'cl) +(eval-when-compile (require 'cl)) (require 'mm-view) (require 'message) (require 'mm-decode) @@ -85,10 +85,10 @@ any given message." (defmacro with-current-notmuch-show-message (&rest body) "Evaluate body with current buffer set to the text of current message" `(save-excursion - (let ((filename (notmuch-show-get-filename))) - (let ((buf (generate-new-buffer (concat "*notmuch-msg-" filename "*")))) + (let ((id (notmuch-show-get-message-id))) + (let ((buf (generate-new-buffer (concat "*notmuch-msg-" id "*")))) (with-current-buffer buf - (insert-file-contents filename nil nil nil t) + (call-process notmuch-command nil t nil "show" "--format=raw" id) ,@body) (kill-buffer buf))))) @@ -555,7 +555,7 @@ function is used. " (defvar notmuch-show-mode-map (let ((map (make-sparse-keymap))) (define-key map "?" 'notmuch-help) - (define-key map "q" 'kill-this-buffer) + (define-key map "q" 'notmuch-kill-this-buffer) (define-key map (kbd "") 'widget-backward) (define-key map (kbd "M-TAB") 'notmuch-show-previous-button) (define-key map (kbd "") 'notmuch-show-previous-button) @@ -586,7 +586,6 @@ function is used. " "Keymap for \"notmuch show\" buffers.") (fset 'notmuch-show-mode-map notmuch-show-mode-map) -;;;###autoload (defun notmuch-show-mode () "Major mode for viewing a thread with notmuch. @@ -726,7 +725,7 @@ All currently available key bindings: (defun notmuch-show-get-message-id () "Return the message id of the current message." - (concat "id:" (notmuch-show-get-prop :id))) + (concat "id:\"" (notmuch-show-get-prop :id) "\"")) ;; dme: Would it make sense to use a macro for many of these? @@ -918,7 +917,11 @@ any effects from previous calls to (defun notmuch-show-view-raw-message () "View the file holding the current message." (interactive) - (view-file (notmuch-show-get-filename))) + (let ((id (notmuch-show-get-message-id))) + (let ((buf (get-buffer-create (concat "*notmuch-raw-" id "*")))) + (switch-to-buffer buf) + (save-excursion + (call-process notmuch-command nil t nil "show" "--format=raw" id))))) (defun notmuch-show-pipe-message (entire-thread command) "Pipe the contents of the current message (or thread) to the given command. @@ -934,37 +937,64 @@ than only the current message." (let (shell-command) (if entire-thread (setq shell-command - (concat "notmuch show --format=mbox " + (concat notmuch-command " show --format=mbox " (shell-quote-argument (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR ")) " | " command)) (setq shell-command - (concat command " < " (shell-quote-argument (notmuch-show-get-filename))))) + (concat notmuch-command " show --format=raw " + (shell-quote-argument (notmuch-show-get-message-id)) " | " command))) (start-process-shell-command "notmuch-pipe-command" "*notmuch-pipe*" shell-command))) +(defun notmuch-show-add-tags-worker (current-tags add-tags) + "Add to `current-tags' with any tags from `add-tags' not +currently present and return the result." + (let ((result-tags (copy-sequence current-tags))) + (mapc (lambda (add-tag) + (unless (member add-tag current-tags) + (setq result-tags (push add-tag result-tags)))) + add-tags) + (sort result-tags 'string<))) + +(defun notmuch-show-del-tags-worker (current-tags del-tags) + "Remove any tags in `del-tags' from `current-tags' and return +the result." + (let ((result-tags (copy-sequence current-tags))) + (mapc (lambda (del-tag) + (setq result-tags (delete del-tag result-tags))) + del-tags) + result-tags)) + (defun notmuch-show-add-tag (&rest toadd) "Add a tag to the current message." (interactive (list (notmuch-select-tag-with-completion "Tag to add: "))) - (apply 'notmuch-call-notmuch-process - (append (cons "tag" - (mapcar (lambda (s) (concat "+" s)) toadd)) - (cons (notmuch-show-get-message-id) nil))) - (notmuch-show-set-tags (sort (union toadd (notmuch-show-get-tags) :test 'string=) 'string<))) + + (let* ((current-tags (notmuch-show-get-tags)) + (new-tags (notmuch-show-add-tags-worker current-tags toadd))) + + (unless (equal current-tags new-tags) + (apply 'notmuch-call-notmuch-process + (append (cons "tag" + (mapcar (lambda (s) (concat "+" s)) toadd)) + (cons (notmuch-show-get-message-id) nil))) + (notmuch-show-set-tags new-tags)))) (defun notmuch-show-remove-tag (&rest toremove) "Remove a tag from the current message." (interactive (list (notmuch-select-tag-with-completion "Tag to remove: " (notmuch-show-get-message-id)))) - (let ((tags (notmuch-show-get-tags))) - (if (intersection tags toremove :test 'string=) - (progn - (apply 'notmuch-call-notmuch-process - (append (cons "tag" - (mapcar (lambda (s) (concat "-" s)) toremove)) - (cons (notmuch-show-get-message-id) nil))) - (notmuch-show-set-tags (sort (set-difference tags toremove :test 'string=) 'string<)))))) + + (let* ((current-tags (notmuch-show-get-tags)) + (new-tags (notmuch-show-del-tags-worker current-tags toremove))) + + (unless (equal current-tags new-tags) + (apply 'notmuch-call-notmuch-process + (append (cons "tag" + (mapcar (lambda (s) (concat "-" s)) toremove)) + (cons (notmuch-show-get-message-id) nil))) + (notmuch-show-set-tags new-tags)))) (defun notmuch-show-toggle-headers () "Toggle the visibility of the current message headers." @@ -1013,7 +1043,7 @@ argument, hide all of the messages." until (not (notmuch-show-goto-message-next))) ;; Move to the next item in the search results, if any. (let ((parent-buffer notmuch-show-parent-buffer)) - (kill-this-buffer) + (notmuch-kill-this-buffer) (if parent-buffer (progn (switch-to-buffer parent-buffer)