[PATCH v5 5/7] emacs/show: Make the insertion of part headers overridable.

Mark Walters markwalters1009 at gmail.com
Sun Feb 14 10:39:57 PST 2016


From: David Edmondson <dme at dme.org>

This allows callers of notmuch-show-insert-bodypart to use a `let'
binding to override the default function for specifying when part
headers should be inserted.
---
 emacs/notmuch-show.el | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index f0bbff0..5654d11 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -943,8 +943,15 @@ will return nil if the CID is unknown or cannot be retrieved."
 	     "text/x-diff")
 	content-type)))
 
+;; The following variable can be overridden by let bindings.
+(defvar notmuch-show-insert-header-p-function 'notmuch-show-insert-header-p
+  "Specify which function decides which part headers get inserted.
+
+The function should take two parameters, PART and HIDE, and
+should return non-NIL if a header button should be inserted for
+this part.")
+
 (defun notmuch-show-insert-header-p (part hide)
-  "Return non-NIL if a header button should be inserted for this part."
   ;; Show all part buttons except for the first part if it is text/plain.
   (let ((mime-type (notmuch-show-mime-type part)))
     (not (and (string= mime-type "text/plain")
@@ -964,7 +971,9 @@ is t, hide the part initially and show the button."
 		    (> notmuch-show-max-text-part-size 0)
 		    (> (length (plist-get part :content)) notmuch-show-max-text-part-size)))
 	 (beg (point))
-	 (button (when (notmuch-show-insert-header-p part hide)
+	 ;; This default header-p function omits the part button for
+	 ;; the first (or only) part if this is text/plain.
+	 (button (when (funcall notmuch-show-insert-header-p-function part hide)
 		   (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))
 	 ;; Hide the part initially if HIDE is t, or if it is too long
 	 ;; and we have a button to allow toggling.
-- 
2.1.4



More information about the notmuch mailing list