diff options
| author | Lars Ingebrigtsen | 2018-04-13 19:08:16 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2018-04-13 19:08:16 +0200 |
| commit | 7e47d44da4b54c518c5e09b4f3d58dafdd43033d (patch) | |
| tree | e86e75908e6fbcd522c91a7ae8b77e0686255676 | |
| parent | 712607b05ac7c28a35e4682269adc53257ab9337 (diff) | |
| download | emacs-7e47d44da4b54c518c5e09b4f3d58dafdd43033d.tar.gz emacs-7e47d44da4b54c518c5e09b4f3d58dafdd43033d.zip | |
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.
| -rw-r--r-- | doc/misc/emacs-mime.texi | 12 | ||||
| -rw-r--r-- | etc/NEWS | 14 | ||||
| -rw-r--r-- | 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: | |||
| 1845 | @table @code | 1845 | @table @code |
| 1846 | @item mailcap-parse-mailcaps | 1846 | @item mailcap-parse-mailcaps |
| 1847 | @findex mailcap-parse-mailcaps | 1847 | @findex mailcap-parse-mailcaps |
| 1848 | @vindex mailcap-prefer-mailcap-viewers | ||
| 1848 | Parse the @file{~/.mailcap} file. | 1849 | Parse the @file{~/.mailcap} file. |
| 1849 | 1850 | ||
| 1850 | @item mailcap-mime-info | 1851 | @item mailcap-mime-info |
| 1851 | Takes a @acronym{MIME} type as its argument and returns the matching viewer. | 1852 | Takes a @acronym{MIME} type as its argument and returns the matching viewer. |
| 1852 | 1853 | ||
| 1854 | The @code{mailcap-prefer-mailcap-viewers} variable controls which | ||
| 1855 | viewer is chosen. The default non-@code{nil} value means that | ||
| 1856 | settings from @file{~/.mailcap} is preferred over system-wide or | ||
| 1857 | Emacs-provided viewer settings. | ||
| 1858 | |||
| 1859 | If @code{nil}, Emacs-provided viewer settings have precedence. Next, | ||
| 1860 | the most specific viewer has precedence over less specific settings, | ||
| 1861 | no matter if they're system-provided or private, so @string{image/gif} | ||
| 1862 | in @file{/etc/mailcap} will ``win'' over a @string{image/*} setting in | ||
| 1863 | @file{~/.mailcap}. | ||
| 1864 | |||
| 1853 | @end table | 1865 | @end table |
| 1854 | 1866 | ||
| 1855 | 1867 | ||
| @@ -526,11 +526,23 @@ does not fit in a machine integer (Bug#30408). | |||
| 526 | 'json-insert', 'json-parse-string', and 'json-parse-buffer'. These | 526 | 'json-insert', 'json-parse-string', and 'json-parse-buffer'. These |
| 527 | are implemented in C using the Jansson library. | 527 | are implemented in C using the Jansson library. |
| 528 | 528 | ||
| 529 | ** Mailcap | ||
| 530 | |||
| 529 | --- | 531 | --- |
| 530 | ** The new function `mailcap-file-name-to-mime-type' has been added. | 532 | *** The new function `mailcap-file-name-to-mime-type' has been added. |
| 531 | It's a simple convenience function for looking up MIME types based on | 533 | It's a simple convenience function for looking up MIME types based on |
| 532 | file name extensions. | 534 | file name extensions. |
| 533 | 535 | ||
| 536 | *** The default way the list of possible external viewers for MIME | ||
| 537 | types is sorted and chosen has changed. Earlier, the most specific | ||
| 538 | viewer was chosen, even if there was a general override in ~/.mailcap. | ||
| 539 | For instance, if /etc/mailcap has an entry for image/gif, that one | ||
| 540 | will be chosen even if you have an entry for image/* in your | ||
| 541 | ~/.mailcap file. But with the new method, entries from ~/.mailcap | ||
| 542 | overrides all system and Emacs-provided defaults. To get the old | ||
| 543 | method back, set `mailcap-prefer-mailcap-viewers' to nil | ||
| 544 | |||
| 545 | |||
| 534 | +++ | 546 | +++ |
| 535 | ** The new function 'read-answer' accepts either long or short answers | 547 | ** The new function 'read-answer' accepts either long or short answers |
| 536 | depending on the new customizable variable 'read-answer-short'. | 548 | 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 @@ | |||
| 36 | :version "21.1" | 36 | :version "21.1" |
| 37 | :group 'mime) | 37 | :group 'mime) |
| 38 | 38 | ||
| 39 | (defcustom mailcap-prefer-mailcap-viewers t | ||
| 40 | "If non-nil, prefer viewers specified in ~/.mailcap. | ||
| 41 | If nil, the most specific viewer will be chosen, even if there is | ||
| 42 | a general override in ~/.mailcap. For instance, if /etc/mailcap | ||
| 43 | has an entry for \"image/gif\", that one will be chosen even if | ||
| 44 | you have an entry for \"image/*\" in your ~/.mailcap file." | ||
| 45 | :type 'boolean) | ||
| 46 | |||
| 39 | (defvar mailcap-parse-args-syntax-table | 47 | (defvar mailcap-parse-args-syntax-table |
| 40 | (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table))) | 48 | (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table))) |
| 41 | (modify-syntax-entry ?' "\"" table) | 49 | (modify-syntax-entry ?' "\"" table) |
| @@ -784,18 +792,23 @@ If NO-DECODE is non-nil, don't decode STRING." | |||
| 784 | (setq passed (list viewer)) | 792 | (setq passed (list viewer)) |
| 785 | ;; None found, so heuristically select some applicable viewer | 793 | ;; None found, so heuristically select some applicable viewer |
| 786 | ;; from `mailcap-mime-data'. | 794 | ;; from `mailcap-mime-data'. |
| 795 | (mailcap-parse-mailcaps) | ||
| 787 | (setq major (split-string (car ctl) "/")) | 796 | (setq major (split-string (car ctl) "/")) |
| 788 | (setq minor (cadr major) | 797 | (setq minor (cadr major) |
| 789 | major (car major)) | 798 | major (car major)) |
| 790 | (when (setq major-info (cdr (assoc major mailcap-mime-data))) | 799 | (when (setq major-info (cdr (assoc major mailcap-mime-data))) |
| 791 | (when (setq viewers (mailcap-possible-viewers major-info minor)) | 800 | (when (setq viewers (mailcap-possible-viewers major-info minor)) |
| 792 | (setq info (mapcar (lambda (a) (cons (symbol-name (car a)) | 801 | (setq info (mapcar (lambda (a) |
| 793 | (cdr a))) | 802 | (cons (symbol-name (car a)) (cdr a))) |
| 794 | (cdr ctl))) | 803 | (cdr ctl))) |
| 795 | (dolist (entry viewers) | 804 | (dolist (entry viewers) |
| 796 | (when (mailcap-viewer-passes-test entry info) | 805 | (when (mailcap-viewer-passes-test entry info) |
| 797 | (push entry passed))) | 806 | (push entry passed))) |
| 798 | (setq passed (sort passed 'mailcap-viewer-lessp)) | 807 | ;; The data is in "logical" order; entries from ~/.mailcap |
| 808 | ;; are first, so we don't need to do any sorting if the | ||
| 809 | ;; user wants ~/.mailcap to be preferred. | ||
| 810 | (unless mailcap-prefer-mailcap-viewers | ||
| 811 | (setq passed (sort passed 'mailcap-viewer-lessp))) | ||
| 799 | (setq viewer (car passed)))) | 812 | (setq viewer (car passed)))) |
| 800 | (when (and (stringp (cdr (assq 'viewer viewer))) | 813 | (when (and (stringp (cdr (assq 'viewer viewer))) |
| 801 | passed) | 814 | passed) |