Mercurial > emacs
comparison lisp/international/mule-cmds.el @ 101547:aa2338088b49
(canonicalize-coding-system-name)
(coding-system-from-name): New functions.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 27 Jan 2009 04:36:35 +0000 |
parents | b79970a15daa |
children | b6da45c113db |
comparison
equal
deleted
inserted
replaced
101546:83a2261dc0ed | 101547:aa2338088b49 |
---|---|
240 how text is formatted automatically while decoding." | 240 how text is formatted automatically while decoding." |
241 (let ((eol-type (coding-system-eol-type coding-system))) | 241 (let ((eol-type (coding-system-eol-type coding-system))) |
242 (coding-system-change-eol-conversion | 242 (coding-system-change-eol-conversion |
243 (if coding coding 'undecided) | 243 (if coding coding 'undecided) |
244 (if (numberp eol-type) (aref [unix dos mac] eol-type))))) | 244 (if (numberp eol-type) (aref [unix dos mac] eol-type))))) |
245 | |
246 ;; Canonicalize the coding system name NAME by removing some prefixes | |
247 ;; and delimiter characters. Support function of | |
248 ;; coding-system-from-name. | |
249 (defun canonicalize-coding-system-name (name) | |
250 (if (string-match "^iso[-_ ]?[0-9]" name) | |
251 ;; "iso-8859-1" -> "8859-1", "iso-2022-jp" ->"2022-jp" | |
252 (setq name (substring name (1- (match-end 0))))) | |
253 (let ((idx (string-match "[-_ /]" name))) | |
254 ;; Delete "-", "_", " ", "/" but do distinguish "16-be" and "16be". | |
255 (while idx | |
256 (if (and (>= idx 2) | |
257 (eq (string-match "16-[lb]e$" name (- idx 2)) | |
258 (- idx 2))) | |
259 (setq idx (string-match "[-_ /]" name (match-end 0))) | |
260 (setq name (concat (substring name 0 idx) (substring name (1+ idx))) | |
261 idx (string-match "[-_ /]" name idx)))) | |
262 name)) | |
263 | |
264 (defun coding-system-from-name (name) | |
265 "Return a coding system whose name matches with NAME (string or symbol)." | |
266 (let (sym) | |
267 (if (stringp name) (setq sym (intern name)) | |
268 (setq sym name name (symbol-name name))) | |
269 (if (coding-system-p sym) | |
270 sym | |
271 (let ((eol-type | |
272 (if (string-match "-\\(unix\\|dos\\|mac\\)$" name) | |
273 (prog1 (intern (match-string 1 name)) | |
274 (setq name (substring name 0 (match-beginning 0))))))) | |
275 (setq name (canonicalize-coding-system-name (downcase name))) | |
276 (catch 'tag | |
277 (dolist (elt (coding-system-list)) | |
278 (if (string= (canonicalize-coding-system-name (symbol-name elt)) | |
279 name) | |
280 (throw 'tag (if eol-type (coding-system-change-eol-conversion | |
281 elt eol-type) | |
282 elt))))))))) | |
245 | 283 |
246 (defun toggle-enable-multibyte-characters (&optional arg) | 284 (defun toggle-enable-multibyte-characters (&optional arg) |
247 "Change whether this buffer uses multibyte characters. | 285 "Change whether this buffer uses multibyte characters. |
248 With ARG, use multibyte characters if the ARG is positive. | 286 With ARG, use multibyte characters if the ARG is positive. |
249 | 287 |