From 7e47d44da4b54c518c5e09b4f3d58dafdd43033d Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 13 Apr 2018 19:08:16 +0200 Subject: [PATCH] Prefer settings from ~/.mailcap over system and Emacs settings * 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 | 12 ++++++++++++ etc/NEWS | 14 +++++++++++++- lisp/net/mailcap.el | 19 ++++++++++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi index c0b16f30c4d..db9ed8dda76 100644 --- a/doc/misc/emacs-mime.texi +++ b/doc/misc/emacs-mime.texi @@ -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 diff --git a/etc/NEWS b/etc/NEWS index 88deb779848..e8383b7c241 100644 --- 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'. diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 4ec00450f4e..414ba0fd852 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -36,6 +36,14 @@ :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) -- 2.39.5