X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=emacs%2Fnotmuch-show.el;h=d8773e65d90dbfeff5ad4e8fda91d4d07c402ca5;hp=105532716c1cf6e5e9a79c2160fe11eb10539e70;hb=128b6259ee327adf9189b81034b3b6962e8b9dbc;hpb=c506e1034b5adb54b3e4f8d3e59086756f2bb126 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 10553271..d8773e65 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -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))))) @@ -381,17 +381,24 @@ current buffer, if possible." (defun notmuch-show-make-symbol (type) (make-symbol (concat "notmuch-show-" type))) +(defun notmuch-show-strip-re (string) + (replace-regexp-in-string "\\([Rr]e: *\\)+" "" string)) + +(defvar notmuch-show-previous-subject "") +(make-variable-buffer-local 'notmuch-show-previous-subject) + (defun notmuch-show-insert-msg (msg depth) "Insert the message MSG at depth DEPTH in the current thread." - (let ((headers (plist-get msg :headers)) - ;; Indentation causes the buffer offset of the start/end - ;; points to move, so we must use markers. - message-start message-end - content-start content-end - headers-start headers-end - body-start body-end - (headers-invis-spec (notmuch-show-make-symbol "header")) - (message-invis-spec (notmuch-show-make-symbol "message"))) + (let* ((headers (plist-get msg :headers)) + ;; Indentation causes the buffer offset of the start/end + ;; points to move, so we must use markers. + message-start message-end + content-start content-end + headers-start headers-end + body-start body-end + (headers-invis-spec (notmuch-show-make-symbol "header")) + (message-invis-spec (notmuch-show-make-symbol "message")) + (bare-subject (notmuch-show-strip-re (plist-get headers :Subject)))) ;; Set `buffer-invisibility-spec' to `nil' (a list), otherwise ;; removing items from `buffer-invisibility-spec' (which is what @@ -428,10 +435,17 @@ current buffer, if possible." (insert "\n") (save-excursion (goto-char content-start) - (forward-line 1) + ;; If the subject of this message is the same as that of the + ;; previous message, don't display it when this message is + ;; collapsed. + (when (not (string= notmuch-show-previous-subject + bare-subject)) + (forward-line 1)) (setq headers-start (point-marker))) (setq headers-end (point-marker)) + (setq notmuch-show-previous-subject bare-subject) + (setq body-start (point-marker)) (notmuch-show-insert-body msg (plist-get msg :body) depth) ;; Ensure that the body ends with a newline. @@ -536,6 +550,10 @@ function is used. " ;; Move straight to the first open message (if (not (notmuch-show-message-visible-p)) (notmuch-show-next-open-message)) + + ;; Set the header line to the subject of the first open message. + (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject))) + (notmuch-show-mark-read))) (defvar notmuch-show-stash-map @@ -555,7 +573,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 +604,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. @@ -918,7 +935,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,18 +955,19 @@ 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-seq current-tags))) + (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)))) @@ -955,7 +977,7 @@ currently present and return the result." (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-seq current-tags))) + (let ((result-tags (copy-sequence current-tags))) (mapc (lambda (del-tag) (setq result-tags (delete del-tag result-tags))) del-tags) @@ -1039,7 +1061,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) @@ -1066,49 +1088,45 @@ buffer." (interactive) (notmuch-show-archive-thread-internal nil)) -(defun notmuch-show-do-stash (text) - (kill-new text) - (message "Saved: %s" text)) - (defun notmuch-show-stash-cc () "Copy CC field of current message to kill-ring." (interactive) - (notmuch-show-do-stash (notmuch-show-get-cc))) + (notmuch-common-do-stash (notmuch-show-get-cc))) (defun notmuch-show-stash-date () "Copy date of current message to kill-ring." (interactive) - (notmuch-show-do-stash (notmuch-show-get-date))) + (notmuch-common-do-stash (notmuch-show-get-date))) (defun notmuch-show-stash-filename () "Copy filename of current message to kill-ring." (interactive) - (notmuch-show-do-stash (notmuch-show-get-filename))) + (notmuch-common-do-stash (notmuch-show-get-filename))) (defun notmuch-show-stash-from () "Copy From address of current message to kill-ring." (interactive) - (notmuch-show-do-stash (notmuch-show-get-from))) + (notmuch-common-do-stash (notmuch-show-get-from))) (defun notmuch-show-stash-message-id () "Copy message ID of current message to kill-ring." (interactive) - (notmuch-show-do-stash (notmuch-show-get-message-id))) + (notmuch-common-do-stash (notmuch-show-get-message-id))) (defun notmuch-show-stash-subject () "Copy Subject field of current message to kill-ring." (interactive) - (notmuch-show-do-stash (notmuch-show-get-subject))) + (notmuch-common-do-stash (notmuch-show-get-subject))) (defun notmuch-show-stash-tags () "Copy tags of current message to kill-ring as a comma separated list." (interactive) - (notmuch-show-do-stash (mapconcat 'identity (notmuch-show-get-tags) ","))) + (notmuch-common-do-stash (mapconcat 'identity (notmuch-show-get-tags) ","))) (defun notmuch-show-stash-to () "Copy To address of current message to kill-ring." (interactive) - (notmuch-show-do-stash (notmuch-show-get-to))) + (notmuch-common-do-stash (notmuch-show-get-to))) ;; Commands typically bound to buttons.