summaryrefslogtreecommitdiff
path: root/lisp/net
diff options
context:
space:
mode:
authorMark Oteiza <mvoteiza@udel.edu>2017-09-05 16:39:21 -0400
committerMark Oteiza <mvoteiza@udel.edu>2017-09-05 16:45:13 -0400
commit964d672a7fce9ae2091d765ae9eb62559607b858 (patch)
tree4e060095cdfbcca6c06660d7d9f6aa4bd87ddaec /lisp/net
parentdf4940c8dd2b5517fad411a8fb6d23d058eea764 (diff)
downloademacs-964d672a7fce9ae2091d765ae9eb62559607b858.tar.gz
Refactor some loops in mailcap.el
* lisp/net/mailcap.el (mailcap-mime-types): (mailcap-file-default-commands): Convert nested maps to loops.
Diffstat (limited to 'lisp/net')
-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."
(delete-dups
(nconc
(mapcar 'cdr mailcap-mime-extensions)
- (apply
- 'nconc
- (mapcar
- (lambda (l)
- (delq nil
- (mapcar
- (lambda (m)
- (let ((type (cdr (assq 'type (cdr m)))))
- (if (equal (cadr (split-string type "/"))
- "*")
- nil
- type)))
- (cdr l))))
- mailcap-mime-data)))))
+ (let (res type)
+ (dolist (data mailcap-mime-data)
+ (dolist (info (cdr data))
+ (setq type (cdr (assq 'type (cdr info))))
+ (unless (string-match-p "\\*" type)
+ (push type res))))
+ (nreverse res)))))
;;;
;;; Useful supplementary functions
@@ -1047,32 +1040,31 @@ If FORCE, re-parse even if already parsed."
;; Intersection of mime-infos from different mime-types;
;; or just the first MIME info for a single MIME type
(if (cdr all-mime-info)
- (delq nil (mapcar (lambda (mi1)
- (unless (memq nil (mapcar
- (lambda (mi2)
- (member mi1 mi2))
- (cdr all-mime-info)))
- mi1))
- (car all-mime-info)))
- (car all-mime-info)))
- (commands
- ;; Command strings from `viewer' field of the MIME info
- (delete-dups
- (delq nil (mapcar
- (lambda (mime-info)
- (let ((command (cdr (assoc 'viewer mime-info))))
- (if (stringp command)
- (replace-regexp-in-string
- ;; Replace mailcap's `%s' placeholder
- ;; with dired's `?' placeholder
- "%s" "?"
- (replace-regexp-in-string
- ;; Remove the final filename placeholder
- "[ \t\n]*\\('\\)?%s\\1?[ \t\n]*\\'" ""
- command nil t)
- nil t))))
- common-mime-info)))))
- commands))
+ (let (res)
+ (dolist (mi1 (car all-mime-info))
+ (dolist (mi2 (cdr all-mime-info))
+ (when (member mi1 mi2)
+ (push mi1 res))))
+ (nreverse res))
+ (car all-mime-info))))
+ ;; Command strings from `viewer' field of the MIME info
+ (delete-dups
+ (let (res command)
+ (dolist (mime-info common-mime-info)
+ (setq command (cdr (assq 'viewer mime-info)))
+ (when (stringp command)
+ (push
+ (replace-regexp-in-string
+ ;; Replace mailcap's `%s' placeholder
+ ;; with dired's `?' placeholder
+ "%s" "?"
+ (replace-regexp-in-string
+ ;; Remove the final filename placeholder
+ "[ \t\n]*\\('\\)?%s\\1?[ \t\n]*\\'" ""
+ command nil t)
+ nil t)
+ res)))
+ (nreverse res)))))
(defun mailcap-view-mime (type)
"View the data in the current buffer that has MIME type TYPE.