]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer settings from ~/.mailcap over system and Emacs settings
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 13 Apr 2018 17:08:16 +0000 (19:08 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 13 Apr 2018 17:08:16 +0000 (19:08 +0200)
* doc/misc/emacs-mime.texi (mailcap): Document the variable and
how mailcap chooses which viewer to use.

* lisp/net/mailcap.el (mailcap-prefer-mailcap-viewers): New variable.
(mailcap-mime-info): Use it.

doc/misc/emacs-mime.texi
etc/NEWS
lisp/net/mailcap.el

index c0b16f30c4db77525dc15645166a6611d87520fc..db9ed8dda76ad64bab4eaacd11e1abc644252dd5 100644 (file)
@@ -1845,11 +1845,23 @@ Interface functions:
 @table @code
 @item mailcap-parse-mailcaps
 @findex mailcap-parse-mailcaps
+@vindex mailcap-prefer-mailcap-viewers
 Parse the @file{~/.mailcap} file.
 
 @item mailcap-mime-info
 Takes a @acronym{MIME} type as its argument and returns the matching viewer.
 
+The @code{mailcap-prefer-mailcap-viewers} variable controls which
+viewer is chosen.  The default non-@code{nil} value means that
+settings from @file{~/.mailcap} is preferred over system-wide or
+Emacs-provided viewer settings.
+
+If @code{nil}, Emacs-provided viewer settings have precedence.  Next,
+the most specific viewer has precedence over less specific settings,
+no matter if they're system-provided or private, so @string{image/gif}
+in @file{/etc/mailcap} will ``win'' over a @string{image/*} setting in
+@file{~/.mailcap}.
+
 @end table
 
 
index 88deb779848961be21fdbd5e233ad18b940dd61e..e8383b7c241357a6cda2ca8994cb94d3ac757b30 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -526,11 +526,23 @@ does not fit in a machine integer (Bug#30408).
 'json-insert', 'json-parse-string', and 'json-parse-buffer'.  These
 are implemented in C using the Jansson library.
 
+** Mailcap
+
 ---
-** The new function `mailcap-file-name-to-mime-type' has been added.
+*** The new function `mailcap-file-name-to-mime-type' has been added.
 It's a simple convenience function for looking up MIME types based on
 file name extensions.
 
+*** The default way the list of possible external viewers for MIME
+types is sorted and chosen has changed.  Earlier, the most specific
+viewer was chosen, even if there was a general override in ~/.mailcap.
+For instance, if /etc/mailcap has an entry for image/gif, that one
+will be chosen even if you have an entry for image/* in your
+~/.mailcap file.  But with the new method, entries from ~/.mailcap
+overrides all system and Emacs-provided defaults.  To get the old
+method back, set `mailcap-prefer-mailcap-viewers' to nil
+
+
 +++
 ** The new function 'read-answer' accepts either long or short answers
 depending on the new customizable variable 'read-answer-short'.
index 4ec00450f4e449e1462e1bc8caa7944cad5ccac6..414ba0fd852ad63225657c07edd973dc4844e7c6 100644 (file)
   :version "21.1"
   :group 'mime)
 
+(defcustom mailcap-prefer-mailcap-viewers t
+  "If non-nil, prefer viewers specified in ~/.mailcap.
+If nil, the most specific viewer will be chosen, even if there is
+a general override in ~/.mailcap.  For instance, if /etc/mailcap
+has an entry for \"image/gif\", that one will be chosen even if
+you have an entry for \"image/*\" in your ~/.mailcap file."
+  :type 'boolean)
+
 (defvar mailcap-parse-args-syntax-table
   (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
     (modify-syntax-entry ?' "\"" table)
@@ -784,18 +792,23 @@ If NO-DECODE is non-nil, don't decode STRING."
           (setq passed (list viewer))
         ;; None found, so heuristically select some applicable viewer
         ;; from `mailcap-mime-data'.
+        (mailcap-parse-mailcaps)
         (setq major (split-string (car ctl) "/"))
         (setq minor (cadr major)
               major (car major))
         (when (setq major-info (cdr (assoc major mailcap-mime-data)))
           (when (setq viewers (mailcap-possible-viewers major-info minor))
-            (setq info (mapcar (lambda (a) (cons (symbol-name (car a))
-                                            (cdr a)))
+            (setq info (mapcar (lambda (a)
+                                 (cons (symbol-name (car a)) (cdr a)))
                                (cdr ctl)))
             (dolist (entry viewers)
               (when (mailcap-viewer-passes-test entry info)
                 (push entry passed)))
-            (setq passed (sort passed 'mailcap-viewer-lessp))
+            ;; The data is in "logical" order; entries from ~/.mailcap
+            ;; are first, so we don't need to do any sorting if the
+            ;; user wants ~/.mailcap to be preferred.
+            (unless mailcap-prefer-mailcap-viewers
+              (setq passed (sort passed 'mailcap-viewer-lessp)))
             (setq viewer (car passed))))
         (when (and (stringp (cdr (assq 'viewer viewer)))
                    passed)