comparison lisp/gnus/mm-util.el @ 100516:0363096dbcf8

Merge from gnus--devo--0 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1505
author Miles Bader <miles@gnu.org>
date Fri, 19 Dec 2008 02:40:25 +0000
parents b8d5bfa98123
children a9dc0e7c3f2b
comparison
equal deleted inserted replaced
100515:ce4ce31aa65a 100516:0363096dbcf8
45 (lambda (elem) 45 (lambda (elem)
46 (let ((nfunc (intern (format "mm-%s" (car elem))))) 46 (let ((nfunc (intern (format "mm-%s" (car elem)))))
47 (if (fboundp (car elem)) 47 (if (fboundp (car elem))
48 (defalias nfunc (car elem)) 48 (defalias nfunc (car elem))
49 (defalias nfunc (cdr elem))))) 49 (defalias nfunc (cdr elem)))))
50 '((coding-system-list . ignore) 50 `((coding-system-list . ignore)
51 (char-int . identity) 51 (char-int . identity)
52 (coding-system-equal . equal) 52 (coding-system-equal . equal)
53 (annotationp . ignore) 53 (annotationp . ignore)
54 (set-buffer-file-coding-system . ignore) 54 (set-buffer-file-coding-system . ignore)
55 (read-charset 55 (read-charset
56 . (lambda (prompt) 56 . ,(lambda (prompt)
57 "Return a charset." 57 "Return a charset."
58 (intern 58 (intern
59 (completing-read 59 (completing-read
60 prompt 60 prompt
61 (mapcar (lambda (e) (list (symbol-name (car e)))) 61 (mapcar (lambda (e) (list (symbol-name (car e))))
62 mm-mime-mule-charset-alist) 62 mm-mime-mule-charset-alist)
63 nil t)))) 63 nil t))))
64 (subst-char-in-string 64 (subst-char-in-string
65 . (lambda (from to string &optional inplace) 65 . ,(lambda (from to string &optional inplace)
66 ;; stolen (and renamed) from nnheader.el 66 ;; stolen (and renamed) from nnheader.el
67 "Replace characters in STRING from FROM to TO. 67 "Replace characters in STRING from FROM to TO.
68 Unless optional argument INPLACE is non-nil, return a new string." 68 Unless optional argument INPLACE is non-nil, return a new string."
69 (let ((string (if inplace string (copy-sequence string))) 69 (let ((string (if inplace string (copy-sequence string)))
70 (len (length string)) 70 (len (length string))
71 (idx 0)) 71 (idx 0))
72 ;; Replace all occurrences of FROM with TO. 72 ;; Replace all occurrences of FROM with TO.
73 (while (< idx len) 73 (while (< idx len)
74 (when (= (aref string idx) from) 74 (when (= (aref string idx) from)
75 (aset string idx to)) 75 (aset string idx to))
76 (setq idx (1+ idx))) 76 (setq idx (1+ idx)))
77 string))) 77 string)))
78 (replace-in-string 78 (replace-in-string
79 . (lambda (string regexp rep &optional literal) 79 . ,(lambda (string regexp rep &optional literal)
80 "See `replace-regexp-in-string', only the order of args differs." 80 "See `replace-regexp-in-string', only the order of args differs."
81 (replace-regexp-in-string regexp rep string nil literal))) 81 (replace-regexp-in-string regexp rep string nil literal)))
82 (string-as-unibyte . identity) 82 (string-as-unibyte . identity)
83 (string-make-unibyte . identity) 83 (string-make-unibyte . identity)
84 ;; string-as-multibyte often doesn't really do what you think it does. 84 ;; string-as-multibyte often doesn't really do what you think it does.
85 ;; Example: 85 ;; Example:
86 ;; (aref (string-as-multibyte "\201") 0) -> 129 (aka ?\201) 86 ;; (aref (string-as-multibyte "\201") 0) -> 129 (aka ?\201)
103 (multibyte-string-p . ignore) 103 (multibyte-string-p . ignore)
104 (insert-byte . insert-char) 104 (insert-byte . insert-char)
105 (multibyte-char-to-unibyte . identity) 105 (multibyte-char-to-unibyte . identity)
106 (set-buffer-multibyte . ignore) 106 (set-buffer-multibyte . ignore)
107 (special-display-p 107 (special-display-p
108 . (lambda (buffer-name) 108 . ,(lambda (buffer-name)
109 "Returns non-nil if a buffer named BUFFER-NAME gets a special frame." 109 "Returns non-nil if a buffer named BUFFER-NAME gets a special frame."
110 (and special-display-function 110 (and special-display-function
111 (or (and (member buffer-name special-display-buffer-names) t) 111 (or (and (member buffer-name special-display-buffer-names) t)
112 (cdr (assoc buffer-name special-display-buffer-names)) 112 (cdr (assoc buffer-name special-display-buffer-names))
113 (catch 'return 113 (catch 'return
114 (dolist (elem special-display-regexps) 114 (dolist (elem special-display-regexps)
115 (and (stringp elem) 115 (and (stringp elem)
116 (string-match elem buffer-name) 116 (string-match elem buffer-name)
117 (throw 'return t)) 117 (throw 'return t))
118 (and (consp elem) 118 (and (consp elem)
119 (stringp (car elem)) 119 (stringp (car elem))
120 (string-match (car elem) buffer-name) 120 (string-match (car elem) buffer-name)
121 (throw 'return (cdr elem)))))))))))) 121 (throw 'return (cdr elem)))))))))
122 (substring-no-properties
123 . ,(lambda (string &optional from to)
124 "Return a substring of STRING, without text properties.
125 It starts at index FROM and ending before TO.
126 TO may be nil or omitted; then the substring runs to the end of STRING.
127 If FROM is nil or omitted, the substring starts at the beginning of STRING.
128 If FROM or TO is negative, it counts from the end.
129
130 With one argument, just copy STRING without its properties."
131 (setq string (substring string (or from 0) to))
132 (set-text-properties 0 (length string) nil string)
133 string)))))
122 134
123 (eval-and-compile 135 (eval-and-compile
124 (if (featurep 'xemacs) 136 (if (featurep 'xemacs)
125 (if (featurep 'file-coding) 137 (if (featurep 'file-coding)
126 ;; Don't modify string if CODING-SYSTEM is nil. 138 ;; Don't modify string if CODING-SYSTEM is nil.
154 'identity) 166 'identity)
155 ((fboundp 'string-to-multibyte) 167 ((fboundp 'string-to-multibyte)
156 'string-to-multibyte) 168 'string-to-multibyte)
157 (t 169 (t
158 (lambda (string) 170 (lambda (string)
159 "Return a multibyte string with the same individual chars as string." 171 "Return a multibyte string with the same individual chars as STRING."
160 (mapconcat 172 (mapconcat
161 (lambda (ch) (mm-string-as-multibyte (char-to-string ch))) 173 (lambda (ch) (mm-string-as-multibyte (char-to-string ch)))
162 string ""))))) 174 string "")))))
163 175
164 (eval-and-compile 176 (eval-and-compile