From edc4b2173b1aa915a89a1a3983f9e1965244c054 Mon Sep 17 00:00:00 2001 From: Elias Oltmanns Date: Thu, 12 Jun 2014 10:15:01 +0200 Subject: Fix handling of test clauses in mailcap entries * mailcap.el (mailcap-mailcap-entry-passes-test): - Consider mailcap entries with needsterminal or needsx11 attributes but no test clause. - Test clauses checking for the DISPLAY environment variable may consist of additional follow-up checks; so, do not jump to conclusions. (mailcap-viewer-passes-test): Check whether there is anything to test before consulting and possibly updating the cache. Otherwise, preevaluated, failed tests lead to an entry (nil nil) in the cache and all mailcap entries without a test clause are disregarded from then on. --- lisp/mailcap.el | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lisp/mailcap.el b/lisp/mailcap.el index 4f1bdf4..1040500 100644 --- a/lisp/mailcap.el +++ b/lisp/mailcap.el @@ -555,20 +555,26 @@ Also return non-nil if no test clause is present." (assoc "needsterminal" info) (assoc "needsx11" info)) (not (getenv "DISPLAY"))) - (setq status nil) + (if test + (setq status nil) + (nconc info (list (cons 'test nil)))) (cond ((and (equal (nth 0 status) "test") (equal (nth 1 status) "-n") (or (equal (nth 2 status) "$DISPLAY") (equal (nth 2 status) "\"$DISPLAY\""))) - (setq status (if (getenv "DISPLAY") t nil))) + (if (not (getenv "DISPLAY")) + (setq status nil) + (unless (nth 3 status) + (setq status t)))) ((and (equal (nth 0 status) "test") (equal (nth 1 status) "-z") (or (equal (nth 2 status) "$DISPLAY") (equal (nth 2 status) "\"$DISPLAY\""))) - (setq status (if (getenv "DISPLAY") nil t))) - (test nil) - (t nil))) + (if (getenv "DISPLAY") + (setq status nil) + (unless (nth 3 status) + (setq status t)))))) (and test (listp test) (setcdr test status)))) ;;; @@ -648,15 +654,15 @@ to supply to the test." (viewer (cdr (assoc 'viewer viewer-info))) (default-directory (expand-file-name "~/")) status parsed-test cache result) - (cond ((setq cache (assoc test mailcap-viewer-test-cache)) + (cond ((not test-info) t) ; No test clause + ((not test) nil) ; Already failed test + ((eq test t) t) ; Already passed test + ((setq cache (assoc test mailcap-viewer-test-cache)) (cadr cache)) - ((not test-info) t) ; No test clause (t (setq result (cond - ((not test) nil) ; Already failed test - ((eq test t) t) ; Already passed test ((functionp test) ; Lisp function as test (funcall test type-info)) ((and (symbolp test) ; Lisp variable as test