]> rtime.felk.cvut.cz Git - notmuch.git/commitdiff
emacs: Allow part preferences to depend on message content.
authorDavid Edmondson <dme@dme.org>
Sun, 3 Apr 2016 16:04:38 +0000 (17:04 +0100)
committerDavid Bremner <david@tethera.net>
Sat, 9 Apr 2016 19:17:20 +0000 (16:17 -0300)
Currently the preference for which sub-part of a multipart/alternative
part is shown is global. Allow to the user to override the settings on a
per-message basis by providing the ability to call a function that has
access to the message to return the discouraged type list.

The original approach is retained as the default.

emacs/notmuch-lib.el
emacs/notmuch-show.el

index 75a3706fa9aae99b309d8ba8f0aafd1392a25ce0..eca837d14b01086b26a7b0c11c01d835d19ce40c 100644 (file)
@@ -520,11 +520,23 @@ This replaces spaces, percents, and double quotes in STR with
     "multipart/related"
     ))
 
-(defun notmuch-multipart/alternative-choose (types)
-  "Return a list of preferred types from the given list of types"
+(defun notmuch-multipart/alternative-determine-discouraged (msg)
+  "Return the discouraged alternatives for the specified message."
+  ;; If a function, return the result of calling it.
+  (if (functionp notmuch-multipart/alternative-discouraged)
+      (funcall notmuch-multipart/alternative-discouraged msg)
+    ;; Otherwise simply return the value of the variable, which is
+    ;; assumed to be a list of discouraged alternatives. This is the
+    ;; default behaviour.
+    notmuch-multipart/alternative-discouraged))
+
+(defun notmuch-multipart/alternative-choose (msg types)
+  "Return a list of preferred types from the given list of types
+for this message, if present."
   ;; Based on `mm-preferred-alternative-precedence'.
-  (let ((seq types))
-    (dolist (pref (reverse notmuch-multipart/alternative-discouraged))
+  (let ((discouraged (notmuch-multipart/alternative-determine-discouraged msg))
+       (seq types))
+    (dolist (pref (reverse discouraged))
       (dolist (elem (copy-sequence seq))
        (when (string-match pref elem)
          (setq seq (nconc (delete elem seq) (list elem))))))
index 7c3444931c0e6f96fca8e4200bf6f21e19860e2f..f6a21e4702b04bbb33456bab7946212f16da597e 100644 (file)
@@ -607,7 +607,7 @@ will return nil if the CID is unknown or cannot be retrieved."
          (plist-get part :content)))
 
 (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)
-  (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
+  (let ((chosen-type (car (notmuch-multipart/alternative-choose msg (notmuch-show-multipart/*-to-list part))))
        (inner-parts (plist-get part :content))
        (start (point)))
     ;; This inserts all parts of the chosen type rather than just one,