aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Oteiza2017-09-05 16:39:21 -0400
committerMark Oteiza2017-09-05 16:45:13 -0400
commit964d672a7fce9ae2091d765ae9eb62559607b858 (patch)
tree4e060095cdfbcca6c06660d7d9f6aa4bd87ddaec
parentdf4940c8dd2b5517fad411a8fb6d23d058eea764 (diff)
downloademacs-964d672a7fce9ae2091d765ae9eb62559607b858.tar.gz
emacs-964d672a7fce9ae2091d765ae9eb62559607b858.zip
Refactor some loops in mailcap.el
* lisp/net/mailcap.el (mailcap-mime-types): (mailcap-file-default-commands): Convert nested maps to loops.
-rw-r--r--lisp/net/mailcap.el72
1 files changed, 32 insertions, 40 deletions
diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el
index 0b79521b7ab..f943015e18a 100644
--- a/lisp/net/mailcap.el
+++ b/lisp/net/mailcap.el
@@ -1007,20 +1007,13 @@ If FORCE, re-parse even if already parsed."
1007 (delete-dups 1007 (delete-dups
1008 (nconc 1008 (nconc
1009 (mapcar 'cdr mailcap-mime-extensions) 1009 (mapcar 'cdr mailcap-mime-extensions)
1010 (apply 1010 (let (res type)
1011 'nconc 1011 (dolist (data mailcap-mime-data)
1012 (mapcar 1012 (dolist (info (cdr data))
1013 (lambda (l) 1013 (setq type (cdr (assq 'type (cdr info))))
1014 (delq nil 1014 (unless (string-match-p "\\*" type)
1015 (mapcar 1015 (push type res))))
1016 (lambda (m) 1016 (nreverse res)))))
1017 (let ((type (cdr (assq 'type (cdr m)))))
1018 (if (equal (cadr (split-string type "/"))
1019 "*")
1020 nil
1021 type)))
1022 (cdr l))))
1023 mailcap-mime-data)))))
1024 1017
1025;;; 1018;;;
1026;;; Useful supplementary functions 1019;;; Useful supplementary functions
@@ -1047,32 +1040,31 @@ If FORCE, re-parse even if already parsed."
1047 ;; Intersection of mime-infos from different mime-types; 1040 ;; Intersection of mime-infos from different mime-types;
1048 ;; or just the first MIME info for a single MIME type 1041 ;; or just the first MIME info for a single MIME type
1049 (if (cdr all-mime-info) 1042 (if (cdr all-mime-info)
1050 (delq nil (mapcar (lambda (mi1) 1043 (let (res)
1051 (unless (memq nil (mapcar 1044 (dolist (mi1 (car all-mime-info))
1052 (lambda (mi2) 1045 (dolist (mi2 (cdr all-mime-info))
1053 (member mi1 mi2)) 1046 (when (member mi1 mi2)
1054 (cdr all-mime-info))) 1047 (push mi1 res))))
1055 mi1)) 1048 (nreverse res))
1056 (car all-mime-info))) 1049 (car all-mime-info))))
1057 (car all-mime-info))) 1050 ;; Command strings from `viewer' field of the MIME info
1058 (commands 1051 (delete-dups
1059 ;; Command strings from `viewer' field of the MIME info 1052 (let (res command)
1060 (delete-dups 1053 (dolist (mime-info common-mime-info)
1061 (delq nil (mapcar 1054 (setq command (cdr (assq 'viewer mime-info)))
1062 (lambda (mime-info) 1055 (when (stringp command)
1063 (let ((command (cdr (assoc 'viewer mime-info)))) 1056 (push
1064 (if (stringp command) 1057 (replace-regexp-in-string
1065 (replace-regexp-in-string 1058 ;; Replace mailcap's `%s' placeholder
1066 ;; Replace mailcap's `%s' placeholder 1059 ;; with dired's `?' placeholder
1067 ;; with dired's `?' placeholder 1060 "%s" "?"
1068 "%s" "?" 1061 (replace-regexp-in-string
1069 (replace-regexp-in-string 1062 ;; Remove the final filename placeholder
1070 ;; Remove the final filename placeholder 1063 "[ \t\n]*\\('\\)?%s\\1?[ \t\n]*\\'" ""
1071 "[ \t\n]*\\('\\)?%s\\1?[ \t\n]*\\'" "" 1064 command nil t)
1072 command nil t) 1065 nil t)
1073 nil t)))) 1066 res)))
1074 common-mime-info))))) 1067 (nreverse res)))))
1075 commands))
1076 1068
1077(defun mailcap-view-mime (type) 1069(defun mailcap-view-mime (type)
1078 "View the data in the current buffer that has MIME type TYPE. 1070 "View the data in the current buffer that has MIME type TYPE.