diff options
| author | Kenichi Handa | 2009-01-27 04:39:30 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2009-01-27 04:39:30 +0000 |
| commit | be7ca04425ef610dc0b00b0d97c5a97410f2327a (patch) | |
| tree | fa989ee4ff792299ae197ddbb0a827ba78dea538 | |
| parent | f143d380fc0f7f169033076c000e83908f770e26 (diff) | |
| download | emacs-be7ca04425ef610dc0b00b0d97c5a97410f2327a.tar.gz emacs-be7ca04425ef610dc0b00b0d97c5a97410f2327a.zip | |
(canonicalize-coding-system-name)
(coding-system-from-name): New functions.
| -rw-r--r-- | etc/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/international/mule-cmds.el | 38 |
2 files changed, 42 insertions, 0 deletions
diff --git a/etc/ChangeLog b/etc/ChangeLog index 0114da8a9e4..06118d95ac1 100644 --- a/etc/ChangeLog +++ b/etc/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2009-01-27 Kenichi Handa <handa@m17n.org> | ||
| 2 | |||
| 3 | * NEWS: New function `coding-sytem-from-name'. | ||
| 4 | |||
| 1 | 2009-01-25 Carsten Dominik <dominik@science.uva.nl> | 5 | 2009-01-25 Carsten Dominik <dominik@science.uva.nl> |
| 2 | 6 | ||
| 3 | * refcards/orgcard.tex: New year and version number. | 7 | * refcards/orgcard.tex: New year and version number. |
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index a354a10850e..cbed1e3659e 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el | |||
| @@ -243,6 +243,44 @@ how text is formatted automatically while decoding." | |||
| 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 | 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))))))))) | ||
| 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. |