X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=emacs%2Fnotmuch-show.el;h=5d7e24b20f8b0b84fefbabb77221d137de919760;hb=fd656d7683ee968eedf11268fb41ad5659aab02f;hp=82b70bafcd2bc35d4c67d1d827a602f812c4619c;hpb=15f5fc513d45cb6173c1a319e3c58b724c3da4db;p=notmuch diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 82b70baf..5d7e24b2 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -41,6 +41,9 @@ (declare-function notmuch-search-next-thread "notmuch" nil) (declare-function notmuch-search-previous-thread "notmuch" nil) (declare-function notmuch-search-show-thread "notmuch" nil) +(declare-function notmuch-foreach-mime-part "notmuch" (function mm-handle)) +(declare-function notmuch-count-attachments "notmuch" (mm-handle)) +(declare-function notmuch-save-attachments "notmuch" (mm-handle &optional queryp)) (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date") "Headers that should be shown in a message, in this order. @@ -237,42 +240,6 @@ For example, if you wanted to remove an \"unread\" tag and add a ))) (mm-display-parts (mm-dissect-buffer))))) -(defun notmuch-foreach-mime-part (function mm-handle) - (cond ((stringp (car mm-handle)) - (dolist (part (cdr mm-handle)) - (notmuch-foreach-mime-part function part))) - ((bufferp (car mm-handle)) - (funcall function mm-handle)) - (t (dolist (part mm-handle) - (notmuch-foreach-mime-part function part))))) - -(defun notmuch-count-attachments (mm-handle) - (let ((count 0)) - (notmuch-foreach-mime-part - (lambda (p) - (let ((disposition (mm-handle-disposition p))) - (and (listp disposition) - (or (equal (car disposition) "attachment") - (and (equal (car disposition) "inline") - (assq 'filename disposition))) - (incf count)))) - mm-handle) - count)) - -(defun notmuch-save-attachments (mm-handle &optional queryp) - (notmuch-foreach-mime-part - (lambda (p) - (let ((disposition (mm-handle-disposition p))) - (and (listp disposition) - (or (equal (car disposition) "attachment") - (and (equal (car disposition) "inline") - (assq 'filename disposition))) - (or (not queryp) - (y-or-n-p - (concat "Save '" (cdr (assq 'filename disposition)) "' "))) - (mm-save-part p)))) - mm-handle)) - (defun notmuch-show-save-attachments () "Save all attachments from the current message." (interactive) @@ -503,7 +470,7 @@ message at DEPTH in the current thread." (new-start (button-start button)) (button-label (button-get button :base-label)) (old-point (point)) - (properties (text-properties-at (point))) + (properties (text-properties-at (button-start button))) (inhibit-read-only t)) ;; Toggle the button itself. (button-put button :notmuch-part-hidden (not show)) @@ -621,6 +588,10 @@ message at DEPTH in the current thread." ;; Render the primary part. (notmuch-show-insert-bodypart msg (car inner-parts) depth) + ;; Add hidden buttons for the rest + (mapc (lambda (inner-part) + (notmuch-show-insert-bodypart msg inner-part depth t)) + (cdr inner-parts)) (when notmuch-show-indent-multipart (indent-rigidly start (point) 1))) @@ -877,7 +848,11 @@ message at DEPTH in the current thread." (defun notmuch-show-insert-bodypart (msg part depth &optional hide) "Insert the body part PART at depth DEPTH in the current thread. -If HIDE is non-nil then initially hide this part." +HIDE determines whether to show or hide the part and the button +as follows: If HIDE is nil, show the part and the button. If HIDE +is t, hide the part initially and show the button. If HIDE is +'no-buttons, show the part but do not add any buttons (this is +useful for quoting in replies)." (let* ((content-type (downcase (plist-get part :content-type))) (mime-type (or (and (string= content-type "application/octet-stream") @@ -887,15 +862,19 @@ If HIDE is non-nil then initially hide this part." content-type)) (nth (plist-get part :id)) (beg (point)) - ;; We omit the part button for the first (or only) part if this is text/plain. - (button (unless (and (string= mime-type "text/plain") (<= nth 1)) + ;; Hide the part initially if HIDE is t. + (show-part (not (equal hide t))) + ;; We omit the part button for the first (or only) part if + ;; this is text/plain, or HIDE is 'no-buttons. + (button (unless (or (equal hide 'no-buttons) + (and (string= mime-type "text/plain") (<= nth 1))) (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))) (content-beg (point))) ;; Store the computed mime-type for later use (e.g. by attachment handlers). (plist-put part :computed-type mime-type) - (if (not hide) + (if show-part (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button) (button-put button :notmuch-lazy-part (list msg part mime-type nth depth button))) @@ -908,7 +887,7 @@ If HIDE is non-nil then initially hide this part." (insert "\n")) ;; We do not create the overlay for hidden (lazy) parts until ;; they are inserted. - (if (not hide) + (if show-part (notmuch-show-create-part-overlays button content-beg (point)) (save-excursion (notmuch-show-toggle-part-invisibility button))) @@ -1264,14 +1243,11 @@ reset based on the original query." (defvar notmuch-show-mode-map (let ((map (make-sparse-keymap))) - (define-key map "?" 'notmuch-help) - (define-key map "q" 'notmuch-kill-this-buffer) + (set-keymap-parent map notmuch-common-keymap) (define-key map (kbd "") 'widget-backward) (define-key map (kbd "M-TAB") 'notmuch-show-previous-button) (define-key map (kbd "") 'notmuch-show-previous-button) (define-key map (kbd "TAB") 'notmuch-show-next-button) - (define-key map "s" 'notmuch-search) - (define-key map "m" 'notmuch-mua-new-mail) (define-key map "f" 'notmuch-show-forward-message) (define-key map "r" 'notmuch-show-reply-sender) (define-key map "R" 'notmuch-show-reply) @@ -1279,7 +1255,6 @@ reset based on the original query." (define-key map "w" 'notmuch-show-save-attachments) (define-key map "V" 'notmuch-show-view-raw-message) (define-key map "c" 'notmuch-show-stash-map) - (define-key map "=" 'notmuch-show-refresh-view) (define-key map "h" 'notmuch-show-toggle-visibility-headers) (define-key map "*" 'notmuch-show-tag-all) (define-key map "-" 'notmuch-show-remove-tag) @@ -1338,6 +1313,7 @@ All currently available key bindings: \\{notmuch-show-mode-map}" (interactive) (kill-all-local-variables) + (setq notmuch-buffer-refresh-function #'notmuch-show-refresh-view) (use-local-map notmuch-show-mode-map) (setq major-mode 'notmuch-show-mode mode-name "notmuch-show")