From: Kenichi Handa Date: Tue, 27 Jan 2009 04:39:30 +0000 (+0000) Subject: (canonicalize-coding-system-name) X-Git-Tag: emacs-pretest-23.0.90~168 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=be7ca04425ef610dc0b00b0d97c5a97410f2327a;p=emacs.git (canonicalize-coding-system-name) (coding-system-from-name): New functions. --- diff --git a/etc/ChangeLog b/etc/ChangeLog index 0114da8a9e4..06118d95ac1 100644 --- a/etc/ChangeLog +++ b/etc/ChangeLog @@ -1,3 +1,7 @@ +2009-01-27 Kenichi Handa + + * NEWS: New function `coding-sytem-from-name'. + 2009-01-25 Carsten Dominik * 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." (if coding coding 'undecided) (if (numberp eol-type) (aref [unix dos mac] eol-type))))) +;; Canonicalize the coding system name NAME by removing some prefixes +;; and delimiter characters. Support function of +;; coding-system-from-name. +(defun canonicalize-coding-system-name (name) + (if (string-match "^iso[-_ ]?[0-9]" name) + ;; "iso-8859-1" -> "8859-1", "iso-2022-jp" ->"2022-jp" + (setq name (substring name (1- (match-end 0))))) + (let ((idx (string-match "[-_ /]" name))) + ;; Delete "-", "_", " ", "/" but do distinguish "16-be" and "16be". + (while idx + (if (and (>= idx 2) + (eq (string-match "16-[lb]e$" name (- idx 2)) + (- idx 2))) + (setq idx (string-match "[-_ /]" name (match-end 0))) + (setq name (concat (substring name 0 idx) (substring name (1+ idx))) + idx (string-match "[-_ /]" name idx)))) + name)) + +(defun coding-system-from-name (name) + "Return a coding system whose name matches with NAME (string or symbol)." + (let (sym) + (if (stringp name) (setq sym (intern name)) + (setq sym name name (symbol-name name))) + (if (coding-system-p sym) + sym + (let ((eol-type + (if (string-match "-\\(unix\\|dos\\|mac\\)$" name) + (prog1 (intern (match-string 1 name)) + (setq name (substring name 0 (match-beginning 0))))))) + (setq name (canonicalize-coding-system-name (downcase name))) + (catch 'tag + (dolist (elt (coding-system-list)) + (if (string= (canonicalize-coding-system-name (symbol-name elt)) + name) + (throw 'tag (if eol-type (coding-system-change-eol-conversion + elt eol-type) + elt))))))))) + (defun toggle-enable-multibyte-characters (&optional arg) "Change whether this buffer uses multibyte characters. With ARG, use multibyte characters if the ARG is positive.