X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=emacs%2Fnotmuch-show.el;h=4b1baf38dd2a5bcc3fc64145fb15407943be7bd1;hp=556941a507425f978b325e41ee6e20fbd3e6ca53;hb=417274d698b6718621b9f5dec744ab169499f4e3;hpb=c579c8201f364a04751058b2e1bad2e7f658d3d8 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 556941a5..4b1baf38 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -30,32 +30,52 @@ (require 'notmuch-lib) (require 'notmuch-query) (require 'notmuch-wash) +(require 'notmuch-mua) (declare-function notmuch-call-notmuch-process "notmuch" (&rest args)) -(declare-function notmuch-reply "notmuch" (query-string)) (declare-function notmuch-fontify-headers "notmuch" nil) (declare-function notmuch-select-tag-with-completion "notmuch" (prompt &rest search-terms)) (declare-function notmuch-search-show-thread "notmuch" nil) -(defvar notmuch-show-headers '("Subject" "To" "Cc" "From" "Date") - "Headers that should be shown in a message, in this order. Note -that if this order is changed the headers shown when a message is -collapsed will change.") +(defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date") + "Headers that should be shown in a message, in this order. -(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers) - "A list of functions called to decorate the headers listed in -`notmuch-show-headers'.") +For an open message, all of these headers will be made visible +according to `notmuch-message-headers-visible' or can be toggled +with `notmuch-show-toggle-headers'. For a closed message, only +the first header in the list will be visible." + :group 'notmuch + :type '(repeat string)) -(defvar notmuch-show-hook '(notmuch-show-pretty-hook) - "A list of functions called after populating a -`notmuch-show' buffer.") +(defcustom notmuch-message-headers-visible t + "Should the headers be visible by default? -(defvar notmuch-show-insert-text/plain-hook '(notmuch-wash-text/plain-citations) - "A list of functions called to clean up text/plain body parts.") +If this value is non-nil, then all of the headers defined in +`notmuch-message-headers' will be visible by default in the display +of each message. Otherwise, these headers will be hidden and +`notmuch-show-toggle-headers' can be used to make the visible for +any given message." + :group 'notmuch + :type 'boolean) -(defun notmuch-show-pretty-hook () - (goto-address-mode 1) - (visual-line-mode)) +(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers) + "A list of functions called to decorate the headers listed in +`notmuch-message-headers'.") + +(defcustom notmuch-show-hook nil + "Functions called after populating a `notmuch-show' buffer." + :group 'notmuch + :type 'hook) + +(defcustom notmuch-show-insert-text/plain-hook '(notmuch-wash-excerpt-citations) + "Functions used to improve the display of text/plain parts." + :group 'notmuch + :type 'hook + :options '(notmuch-wash-convert-inline-patch-to-part + notmuch-wash-wrap-long-lines + notmuch-wash-tidy-citations + notmuch-wash-elide-blank-lines + notmuch-wash-excerpt-citations)) (defmacro with-current-notmuch-show-message (&rest body) "Evaluate body with current buffer set to the text of current message" @@ -198,27 +218,46 @@ message at DEPTH in the current thread." (if (and header-value (not (string-equal "" header-value))) (notmuch-show-insert-header header header-value)))) - notmuch-show-headers) + notmuch-message-headers) (save-excursion (save-restriction (narrow-to-region start (point-max)) (run-hooks 'notmuch-show-markup-headers-hook))))) -(defun notmuch-show-insert-part-header (content-type declared-type &optional name) - (let ((start (point))) - ;; XXX dme: Make this a more useful button (save the part, display - ;; external, etc.) - (insert "[ " - (if name (concat name ": ") "") - declared-type - (if (not (string-equal declared-type content-type)) - (concat " (as " content-type ")") - "") - " ]\n") - (overlay-put (make-overlay start (point)) 'face 'bold))) +(define-button-type 'notmuch-show-part-button-type + 'action 'notmuch-show-part-button-action + 'follow-link t + 'face 'message-mml) + +(defun notmuch-show-insert-part-header (nth content-type declared-type &optional name) + (insert-button + (concat "[ " + (if name (concat name ": ") "") + declared-type + (if (not (string-equal declared-type content-type)) + (concat " (as " content-type ")") + "") + " ]\n") + :type 'notmuch-show-part-button-type + :notmuch-part nth + :notmuch-filename name)) ;; Functions handling particular MIME parts. +(defun notmuch-show-save-part (message-id nth &optional filename) + (with-temp-buffer + ;; Always acquires the part via `notmuch part', even if it is + ;; available in the JSON output. + (insert (notmuch-show-get-bodypart-internal message-id nth)) + (let ((file (read-file-name + "Filename to save as: " + (or mailcap-download-directory "~/") + nil nil + filename)) + (require-final-newline nil) + (coding-system-for-write 'no-conversion)) + (write-region (point-min) (point-max) file)))) + (defun notmuch-show-mm-display-part-inline (msg part content-type content) "Use the mm-decode/mm-view functions to display a part in the current buffer, if possible." @@ -239,7 +278,7 @@ current buffer, if possible." ;; If this text/plain part is not the first part in the message, ;; insert a header to make this clear. (if (> nth 1) - (notmuch-show-insert-part-header declared-type content-type (plist-get part :filename))) + (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))) (insert (notmuch-show-get-bodypart-content msg part nth)) (save-excursion (save-restriction @@ -265,7 +304,7 @@ current buffer, if possible." (defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type) ;; This handler _must_ succeed - it is the handler of last resort. - (notmuch-show-insert-part-header content-type declared-type (plist-get part :filename)) + (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename)) (let ((content (notmuch-show-get-bodypart-content msg part nth))) (if content (notmuch-show-mm-display-part-inline msg part content-type content))) @@ -347,6 +386,22 @@ current buffer, if possible." (headers-invis-spec (notmuch-show-make-symbol "header")) (message-invis-spec (notmuch-show-make-symbol "message"))) + ;; Set `buffer-invisibility-spec' to `nil' (a list), otherwise + ;; removing items from `buffer-invisibility-spec' (which is what + ;; `notmuch-show-headers-visible' and + ;; `notmuch-show-message-visible' do) is a no-op and has no + ;; effect. This caused threads with only matching messages to have + ;; those messages hidden initially because + ;; `buffer-invisibility-spec' stayed `t'. + ;; + ;; This needs to be set here (rather than just above the call to + ;; `notmuch-show-headers-visible') because some of the part + ;; rendering or body washing functions + ;; (e.g. `notmuch-wash-text/plain-citations') manipulate + ;; `buffer-invisibility-spec'). + (when (eq buffer-invisibility-spec t) + (setq buffer-invisibility-spec nil)) + (setq message-start (point-marker)) (notmuch-show-insert-headerline headers @@ -397,8 +452,8 @@ current buffer, if possible." ;; the content). (notmuch-show-set-message-properties msg) - ;; Headers are hidden by default. - (notmuch-show-headers-visible msg nil) + ;; Set header visibility. + (notmuch-show-headers-visible msg notmuch-message-headers-visible) ;; Message visibility depends on whether it matched the search ;; criteria. @@ -451,8 +506,8 @@ function is used. " (save-excursion (let* ((basic-args (list thread-id)) (args (if query-context - (append basic-args (list "and (" query-context ")")) - basic-args))) + (append (list "\'") basic-args (list "and (" query-context ")\'")) + (append (list "\'") basic-args (list "\'"))))) (notmuch-show-insert-forest (notmuch-query-get-threads args)) ;; If the query context reduced the results to nothing, run ;; the basic query. @@ -460,6 +515,13 @@ function is used. " query-context) (notmuch-show-insert-forest (notmuch-query-get-threads basic-args)))) + + ;; Enable buttonisation of URLs and email addresses in the + ;; buffer. + (goto-address-mode t) + ;; Act on visual lines rather than logical lines. + (visual-line-mode t) + (run-hooks 'notmuch-show-hook)) ;; Move straight to the first open message @@ -488,7 +550,7 @@ function is used. " (define-key map (kbd "M-TAB") 'notmuch-show-previous-button) (define-key map (kbd "TAB") 'notmuch-show-next-button) (define-key map "s" 'notmuch-search) - (define-key map "m" 'message-mail) + (define-key map "m" 'notmuch-mua-mail) (define-key map "f" 'notmuch-show-forward-message) (define-key map "r" 'notmuch-show-reply) (define-key map "|" 'notmuch-show-pipe-message) @@ -507,6 +569,7 @@ function is used. " (define-key map "p" 'notmuch-show-previous-open-message) (define-key map (kbd "DEL") 'notmuch-show-rewind) (define-key map " " 'notmuch-show-advance-and-archive) + (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all) (define-key map (kbd "RET") 'notmuch-show-toggle-message) map) "Keymap for \"notmuch show\" buffers.") @@ -771,8 +834,8 @@ any effects from previous calls to ;; If a small number of lines from the previous message are ;; visible, realign so that the top of the current message is at ;; the top of the screen. - (if (< (count-lines (window-start) (notmuch-show-message-top)) - next-screen-context-lines) + (if (<= (count-screen-lines (window-start) start-of-message) + next-screen-context-lines) (progn (goto-char (notmuch-show-message-top)) (notmuch-show-message-adjust))) @@ -785,20 +848,22 @@ any effects from previous calls to (defun notmuch-show-reply () "Reply to the current message." (interactive) - (notmuch-reply (notmuch-show-get-message-id))) + (notmuch-mua-reply (notmuch-show-get-message-id))) (defun notmuch-show-forward-message () "Forward the current message." (interactive) (with-current-notmuch-show-message - (message-forward))) + (notmuch-mua-forward-message))) (defun notmuch-show-next-message () "Show the next message." (interactive) - (notmuch-show-goto-message-next) - (notmuch-show-mark-read) - (notmuch-show-message-adjust)) + (if (notmuch-show-goto-message-next) + (progn + (notmuch-show-mark-read) + (notmuch-show-message-adjust)) + (goto-char (point-max)))) (defun notmuch-show-previous-message () "Show the previous message." @@ -810,10 +875,14 @@ any effects from previous calls to (defun notmuch-show-next-open-message () "Show the next message." (interactive) - (while (and (notmuch-show-goto-message-next) - (not (notmuch-show-message-visible-p)))) - (notmuch-show-mark-read) - (notmuch-show-message-adjust)) + (let (r) + (while (and (setq r (notmuch-show-goto-message-next)) + (not (notmuch-show-message-visible-p)))) + (if r + (progn + (notmuch-show-mark-read) + (notmuch-show-message-adjust)) + (goto-char (point-max))))) (defun notmuch-show-previous-open-message () "Show the previous message." @@ -881,6 +950,18 @@ to stdout or stderr will appear in the *Messages* buffer." (not (plist-get props :message-visible)))) (force-window-update)) +(defun notmuch-show-open-or-close-all () + "Set the visibility all of the messages in the current thread. +By default make all of the messages visible. With a prefix +argument, hide all of the messages." + (interactive) + (save-excursion + (goto-char (point-min)) + (loop do (notmuch-show-message-visible (notmuch-show-get-message-properties) + (not current-prefix-arg)) + until (not (notmuch-show-goto-message-next)))) + (force-window-update)) + (defun notmuch-show-next-button () "Advance point to the next button in the buffer." (interactive) @@ -969,6 +1050,15 @@ buffer." (interactive) (notmuch-show-do-stash (notmuch-show-get-to))) +;; Commands typically bound to buttons. + +(defun notmuch-show-part-button-action (button) + (let ((nth (button-get button :notmuch-part))) + (if nth + (notmuch-show-save-part (notmuch-show-get-message-id) nth + (button-get button :notmuch-filename)) + (message "Not a valid part (is it a fake part?).")))) + ;; (provide 'notmuch-show)