comparison lisp/gnus/mailcap.el @ 94616:7b6b7f6f8539

(mailcap-replace-in-string): New compatibility alias. (mailcap-file-default-commands): Use mailcap-replace-in-string instead of replace-regexp-in-string, and mailcap-delete-duplicates instead of delete-dups. Use [ \t\n]* for whitespace in regexp.
author Juri Linkov <juri@jurta.org>
date Sun, 04 May 2008 23:12:02 +0000
parents 5bdeba83b319
children f42ef85caf91
comparison
equal deleted inserted replaced
94615:a0615a586d39 94616:7b6b7f6f8539
39 (defalias 'mailcap-delete-duplicates 39 (defalias 'mailcap-delete-duplicates
40 (if (fboundp 'delete-dups) 40 (if (fboundp 'delete-dups)
41 'delete-dups 41 'delete-dups
42 (autoload 'mm-delete-duplicates "mm-util") 42 (autoload 'mm-delete-duplicates "mm-util")
43 'mm-delete-duplicates)) 43 'mm-delete-duplicates))
44
45 ;; `mailcap-replace-in-string' is an alias like `gnus-replace-in-string'.
46 (eval-and-compile
47 (cond
48 ((fboundp 'replace-regexp-in-string)
49 (defun mailcap-replace-in-string (string regexp newtext &optional literal)
50 "Replace all matches for REGEXP with NEWTEXT in STRING.
51 If LITERAL is non-nil, insert NEWTEXT literally. Return a new
52 string containing the replacements.
53 This is a compatibility function for different Emacsen."
54 (replace-regexp-in-string regexp newtext string nil literal)))
55 ((fboundp 'replace-in-string)
56 (defalias 'mailcap-replace-in-string 'replace-in-string))))
44 57
45 (defgroup mailcap nil 58 (defgroup mailcap nil
46 "Definition of viewers for MIME types." 59 "Definition of viewers for MIME types."
47 :version "21.1" 60 :version "21.1"
48 :group 'mime) 61 :group 'mime)
1015 "Return a list of default commands for FILES." 1028 "Return a list of default commands for FILES."
1016 (mailcap-parse-mailcaps) 1029 (mailcap-parse-mailcaps)
1017 (mailcap-parse-mimetypes) 1030 (mailcap-parse-mimetypes)
1018 (let* ((all-mime-type 1031 (let* ((all-mime-type
1019 ;; All unique MIME types from file extensions 1032 ;; All unique MIME types from file extensions
1020 (delete-dups (mapcar (lambda (file) 1033 (mailcap-delete-duplicates
1021 (mailcap-extension-to-mime 1034 (mapcar (lambda (file)
1022 (file-name-extension file t))) 1035 (mailcap-extension-to-mime
1023 files))) 1036 (file-name-extension file t)))
1037 files)))
1024 (all-mime-info 1038 (all-mime-info
1025 ;; All MIME info lists 1039 ;; All MIME info lists
1026 (delete-dups (mapcar (lambda (mime-type) 1040 (mailcap-delete-duplicates
1027 (mailcap-mime-info mime-type 'all)) 1041 (mapcar (lambda (mime-type)
1028 all-mime-type))) 1042 (mailcap-mime-info mime-type 'all))
1043 all-mime-type)))
1029 (common-mime-info 1044 (common-mime-info
1030 ;; Intersection of mime-infos from different mime-types; 1045 ;; Intersection of mime-infos from different mime-types;
1031 ;; or just the first MIME info for a single MIME type 1046 ;; or just the first MIME info for a single MIME type
1032 (if (cdr all-mime-info) 1047 (if (cdr all-mime-info)
1033 (delq nil (mapcar (lambda (mi1) 1048 (delq nil (mapcar (lambda (mi1)
1038 mi1)) 1053 mi1))
1039 (car all-mime-info))) 1054 (car all-mime-info)))
1040 (car all-mime-info))) 1055 (car all-mime-info)))
1041 (commands 1056 (commands
1042 ;; Command strings from `viewer' field of the MIME info 1057 ;; Command strings from `viewer' field of the MIME info
1043 (delete-dups 1058 (mailcap-delete-duplicates
1044 (delq nil (mapcar (lambda (mime-info) 1059 (delq nil (mapcar (lambda (mime-info)
1045 (let ((command (cdr (assoc 'viewer mime-info)))) 1060 (let ((command (cdr (assoc 'viewer mime-info))))
1046 (if (stringp command) 1061 (if (stringp command)
1047 (replace-regexp-in-string 1062 (mailcap-replace-in-string
1048 ;; Replace mailcap's `%s' placeholder 1063 ;; Replace mailcap's `%s' placeholder
1049 ;; with dired's `?' placeholder 1064 ;; with dired's `?' placeholder
1050 "%s" "?" 1065 (mailcap-replace-in-string
1051 (replace-regexp-in-string
1052 ;; Remove the final filename placeholder 1066 ;; Remove the final filename placeholder
1053 "\s*\\('\\)?%s\\1?\s*\\'" "" command nil t) 1067 command "[ \t\n]*\\('\\)?%s\\1?[ \t\n]*\\'" "" t)
1054 nil t)))) 1068 "%s" "?" t))))
1055 common-mime-info))))) 1069 common-mime-info)))))
1056 commands)) 1070 commands))
1057 1071
1058 (provide 'mailcap) 1072 (provide 'mailcap)
1059 1073