*** mule.el.~1.226.~ 2005-09-29 09:23:59.000000000 +1000 --- mule.el 2005-10-21 06:54:07.785993736 +1000 *************** *** 1586,1592 **** (symbol :tag "Coding system")))) ;; See the bottom of this file for built-in auto coding functions. ! (defcustom auto-coding-functions '(sgml-xml-auto-coding-function sgml-html-meta-auto-coding-function) "A list of functions which attempt to determine a coding system. --- 1586,1593 ---- (symbol :tag "Coding system")))) ;; See the bottom of this file for built-in auto coding functions. ! (defcustom auto-coding-functions '(po-auto-coding-function ! sgml-xml-auto-coding-function sgml-html-meta-auto-coding-function) "A list of functions which attempt to determine a coding system. *************** *** 2203,2208 **** --- 2204,2254 ---- ;;; Built-in auto-coding-functions: + (defconst po-content-type-charset-alist + '(("ASCII" . undecided) + ("ANSI_X3.4-1968" . undecided) + ("US-ASCII" . undecided) + ;; "charset=CHARSET" is generated by xgettext, and may be present before + ;; someone fills in their target charset. `undecided' should be right. + ("CHARSET" . undecided)) + "Alist of coding system versus GNU libc/libiconv canonical charset name. + Contains canonical charset names that don't correspond to coding systems.") + + (defun po-auto-coding-function (size) + "Determine character encoding of a gettext .po or .pot file. + This function is designed for use in `auto-coding-functions'. + + A po file starts with msgstr \"\" which has header information, in + particular \"Content-Type: text/plain; charset=ASCII\\n\" or whatever." + + ;; Skip "#" comment lines and whitespace-only lines, then want + ;; msgstr "" + ;; msgid "" + ;; which, up to the next blank line, is the header info. + ;; + (and (looking-at + "\\(#.*\n\\|[ \t\r]*\n\\)*msgid \"\"[ \t\r]*\nmsgstr \"\"[ \t\r]*\n") + (let ((limit (+ (point) size))) + (save-excursion + (goto-char (match-end 0)) + + ;; Blank line is the end of the header, stop searching there, or + ;; at existing `limit' if the file is a header only. + (setq limit (or (save-excursion + (re-search-forward "\n[ \t\r]*\n" limit t)) + limit)) + + (and (re-search-forward "^\"Content-Type:[ \t]*text/plain;[ \t]*charset=\\(.*\\)\\\\n\"" limit t) + (let ((charset (match-string 1))) + + (or (cdr (assoc-string charset po-content-type-charset-alist + t)) + (locale-charset-to-coding-system charset) + (progn + (message "Warning: unknown coding system \"%s\"" + charset) + nil)))))))) + (defun sgml-xml-auto-coding-function (size) "Determine whether the buffer is XML, and if so, its encoding. This function is intended to be added to `auto-coding-functions'."