diff options
| author | Dave Love | 2002-10-30 19:47:53 +0000 |
|---|---|---|
| committer | Dave Love | 2002-10-30 19:47:53 +0000 |
| commit | 3180897ccc35c27b2718fe89872e89d36af6d1a7 (patch) | |
| tree | adae34a694bac272cfaa2bdc5ae15f1c4b7e598f /lisp/textmodes | |
| parent | cf07d2bdf6171ffeca13f071db7e8a7f883cda40 (diff) | |
| download | emacs-3180897ccc35c27b2718fe89872e89d36af6d1a7.tar.gz emacs-3180897ccc35c27b2718fe89872e89d36af6d1a7.zip | |
(po-content-type-charset-alist): Delete most
entries.
(po-find-charset): Doc fix. Remove interactive spec.
(po): Provide.
(po-find-file-coding-system-guts): Re-written to use
coding-system-alist, and code-pages, not codepage stuff.
Diffstat (limited to 'lisp/textmodes')
| -rw-r--r-- | lisp/textmodes/po.el | 162 |
1 files changed, 49 insertions, 113 deletions
diff --git a/lisp/textmodes/po.el b/lisp/textmodes/po.el index 8324f71fd89..6793d4171b4 100644 --- a/lisp/textmodes/po.el +++ b/lisp/textmodes/po.el | |||
| @@ -33,89 +33,14 @@ | |||
| 33 | ;;; Code: | 33 | ;;; Code: |
| 34 | 34 | ||
| 35 | (defconst po-content-type-charset-alist | 35 | (defconst po-content-type-charset-alist |
| 36 | '(; Note: Emacs 21 doesn't support all encodings, thus the missing entries. | 36 | '(("ASCII" . undecided) |
| 37 | ("ASCII" . undecided) | ||
| 38 | ("ANSI_X3.4-1968" . undecided) | 37 | ("ANSI_X3.4-1968" . undecided) |
| 39 | ("US-ASCII" . undecided) | 38 | ("US-ASCII" . undecided)) |
| 40 | ("ISO-8859-1" . iso-8859-1) | 39 | "Alist of coding system versus GNU libc/libiconv canonical charset name. |
| 41 | ("ISO_8859-1" . iso-8859-1) | 40 | Contains canonical charset names that don't correspond to coding systems.") |
| 42 | ("ISO-8859-2" . iso-8859-2) | ||
| 43 | ("ISO_8859-2" . iso-8859-2) | ||
| 44 | ("ISO-8859-3" . iso-8859-3) | ||
| 45 | ("ISO_8859-3" . iso-8859-3) | ||
| 46 | ("ISO-8859-4" . iso-8859-4) | ||
| 47 | ("ISO_8859-4" . iso-8859-4) | ||
| 48 | ("ISO-8859-5" . iso-8859-5) | ||
| 49 | ("ISO_8859-5" . iso-8859-5) | ||
| 50 | ;("ISO-8859-6" . ??) | ||
| 51 | ;("ISO_8859-6" . ??) | ||
| 52 | ("ISO-8859-7" . iso-8859-7) | ||
| 53 | ("ISO_8859-7" . iso-8859-7) | ||
| 54 | ("ISO-8859-8" . iso-8859-8) | ||
| 55 | ("ISO_8859-8" . iso-8859-8) | ||
| 56 | ("ISO-8859-9" . iso-8859-9) | ||
| 57 | ("ISO_8859-9" . iso-8859-9) | ||
| 58 | ;("ISO-8859-13" . ??) | ||
| 59 | ;("ISO_8859-13" . ??) | ||
| 60 | ;("ISO-8859-14" . ??) | ||
| 61 | ;("ISO_8859-14" . ??) | ||
| 62 | ("ISO-8859-15" . iso-8859-15) ; requires Emacs 21 | ||
| 63 | ("ISO_8859-15" . iso-8859-15) ; requires Emacs 21 | ||
| 64 | ("KOI8-R" . koi8-r) | ||
| 65 | ;("KOI8-U" . ??) | ||
| 66 | ;("KOI8-T" . ??) | ||
| 67 | ("CP437" . cp437) ; requires Emacs 20 | ||
| 68 | ("CP775" . cp775) ; requires Emacs 20 | ||
| 69 | ("CP850" . cp850) ; requires Emacs 20 | ||
| 70 | ("CP852" . cp852) ; requires Emacs 20 | ||
| 71 | ("CP855" . cp855) ; requires Emacs 20 | ||
| 72 | ;("CP856" . ??) | ||
| 73 | ("CP857" . cp857) ; requires Emacs 20 | ||
| 74 | ("CP861" . cp861) ; requires Emacs 20 | ||
| 75 | ("CP862" . cp862) ; requires Emacs 20 | ||
| 76 | ("CP864" . cp864) ; requires Emacs 20 | ||
| 77 | ("CP865" . cp865) ; requires Emacs 20 | ||
| 78 | ("CP866" . cp866) ; requires Emacs 21 | ||
| 79 | ("CP869" . cp869) ; requires Emacs 20 | ||
| 80 | ;("CP874" . ??) | ||
| 81 | ;("CP922" . ??) | ||
| 82 | ;("CP932" . ??) | ||
| 83 | ;("CP943" . ??) | ||
| 84 | ;("CP949" . ??) | ||
| 85 | ;("CP950" . ??) | ||
| 86 | ;("CP1046" . ??) | ||
| 87 | ;("CP1124" . ??) | ||
| 88 | ;("CP1129" . ??) | ||
| 89 | ("CP1250" . cp1250) ; requires Emacs 20 | ||
| 90 | ("CP1251" . cp1251) ; requires Emacs 20 | ||
| 91 | ("CP1252" . iso-8859-1) ; approximation | ||
| 92 | ("CP1253" . cp1253) ; requires Emacs 20 | ||
| 93 | ("CP1254" . iso-8859-9) ; approximation | ||
| 94 | ("CP1255" . iso-8859-8) ; approximation | ||
| 95 | ;("CP1256" . ??) | ||
| 96 | ("CP1257" . cp1257) ; requires Emacs 20 | ||
| 97 | ("GB2312" . cn-gb-2312) ; also named 'gb2312' in XEmacs 21 or Emacs 21 | ||
| 98 | ; also named 'euc-cn' in Emacs 20 or Emacs 21 | ||
| 99 | ("EUC-JP" . euc-jp) | ||
| 100 | ("EUC-KR" . euc-kr) | ||
| 101 | ;("EUC-TW" . ??) | ||
| 102 | ("BIG5" . big5) | ||
| 103 | ;("BIG5-HKSCS" . ??) | ||
| 104 | ;("GBK" . ??) | ||
| 105 | ;("GB18030" . ??) | ||
| 106 | ("SHIFT_JIS" . shift_jis) | ||
| 107 | ;("JOHAB" . ??) | ||
| 108 | ("TIS-620" . tis-620) ; requires Emacs 20 or Emacs 21 | ||
| 109 | ("VISCII" . viscii) ; requires Emacs 20 or Emacs 21 | ||
| 110 | ;("GEORGIAN-PS" . ??) | ||
| 111 | ("UTF-8" . utf-8) ; requires Mule-UCS in Emacs 20, or Emacs 21 | ||
| 112 | ) | ||
| 113 | "How to convert a GNU libc/libiconv canonical charset name as seen in | ||
| 114 | Content-Type into a Mule coding system.") | ||
| 115 | 41 | ||
| 116 | (defun po-find-charset (filename) | 42 | (defun po-find-charset (filename) |
| 117 | "Return PO file charset value." | 43 | "Return PO charset value for FILENAME." |
| 118 | (interactive) | ||
| 119 | (let ((charset-regexp | 44 | (let ((charset-regexp |
| 120 | "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") | 45 | "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") |
| 121 | (short-read nil)) | 46 | (short-read nil)) |
| @@ -144,42 +69,49 @@ Content-Type into a Mule coding system.") | |||
| 144 | (match-string 1)))))) | 69 | (match-string 1)))))) |
| 145 | 70 | ||
| 146 | (defun po-find-file-coding-system-guts (operation filename) | 71 | (defun po-find-file-coding-system-guts (operation filename) |
| 147 | "\ | 72 | "Return a (DECODING . ENCODING) pair for OPERATION on PO file FILENAME. |
| 148 | Return a Mule (DECODING . ENCODING) pair, according to PO file charset. | 73 | Do so according to FILENAME's declared charset." |
| 149 | Called through file-coding-system-alist, before the file is visited for real." | 74 | (and |
| 150 | (and (eq operation 'insert-file-contents) | 75 | (eq operation 'insert-file-contents) |
| 151 | (file-exists-p filename) | 76 | (file-exists-p filename) |
| 152 | (with-temp-buffer | 77 | (with-temp-buffer |
| 153 | (let* ((coding-system-for-read 'no-conversion) | 78 | (let* ((coding-system-for-read 'no-conversion) |
| 154 | (charset (or (po-find-charset filename) "ascii")) | 79 | (charset (or (po-find-charset filename) "ascii")) |
| 155 | (charset-upper (upcase charset)) | 80 | assoc) |
| 156 | (charset-lower (downcase charset)) | 81 | (list (cond |
| 157 | (candidate | 82 | ((setq assoc |
| 158 | (cdr (assoc charset-upper po-content-type-charset-alist))) | 83 | (assoc-ignore-case charset |
| 159 | (try (or candidate (intern-soft charset-lower)))) | 84 | po-content-type-charset-alist)) |
| 160 | (list (cond ((and try (coding-system-p try)) | 85 | (cdr assoc)) |
| 161 | try) | 86 | ((or (setq assoc (assoc-ignore-case charset coding-system-alist)) |
| 162 | ((and try | 87 | (setq assoc |
| 163 | (string-match "\\`cp[1-9][0-9][0-9]?\\'" | 88 | (assoc-ignore-case (subst-char-in-string ?_ ?- |
| 164 | (symbol-name try)) | 89 | charset) |
| 165 | (assoc (substring (symbol-name try) 2) | 90 | coding-system-alist))) |
| 166 | (cp-supported-codepages))) | 91 | (intern (car assoc))) |
| 167 | (codepage-setup (substring (symbol-name try) 2)) | 92 | ;; In principle we should also check the `mime-charset' |
| 168 | try) | 93 | ;; property of everything in the base coding system |
| 169 | ((and (string-match "\\`cp[1-9][0-9][0-9]?\\'" | 94 | ;; list, but there should always be a coding system |
| 170 | charset-lower) | 95 | ;; corresponding to the MIME name. |
| 171 | (assoc (substring charset-lower 2) | 96 | ((featurep 'code-pages) |
| 172 | (cp-supported-codepages))) | 97 | ;; Give up. |
| 173 | (codepage-setup (substring charset-lower 2)) | 98 | 'raw-text) |
| 174 | (intern charset-lower)) | 99 | (t |
| 175 | (t | 100 | ;; Try again with code-pages loaded. Maybe it's best |
| 176 | 'no-conversion))))))) | 101 | ;; to require it initially? |
| 102 | (require 'code-pages nil t) | ||
| 103 | (if (or | ||
| 104 | (setq assoc (assoc-ignore-case charset coding-system-alist)) | ||
| 105 | (setq assoc (assoc-ignore-case (subst-char-in-string | ||
| 106 | ?_ ?- charset) | ||
| 107 | coding-system-alist))) | ||
| 108 | (intern (car assoc)) | ||
| 109 | 'raw-text)))))))) | ||
| 177 | 110 | ||
| 178 | ;;;###autoload | 111 | ;;;###autoload |
| 179 | (defun po-find-file-coding-system (arg-list) | 112 | (defun po-find-file-coding-system (arg-list) |
| 180 | "\ | 113 | "Return a (DECODING . ENCODING) pair, according to PO file's charset. |
| 181 | Return a Mule (DECODING . ENCODING) pair, according to PO file charset. | 114 | Called through `file-coding-system-alist', before the file is visited for real." |
| 182 | Called through file-coding-system-alist, before the file is visited for real." | ||
| 183 | (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list)))) | 115 | (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list)))) |
| 184 | ;; This is for XEmacs. | 116 | ;; This is for XEmacs. |
| 185 | ;(defun po-find-file-coding-system (operation filename) | 117 | ;(defun po-find-file-coding-system (operation filename) |
| @@ -187,3 +119,7 @@ Called through file-coding-system-alist, before the file is visited for real." | |||
| 187 | ;Return a Mule (DECODING . ENCODING) pair, according to PO file charset. | 119 | ;Return a Mule (DECODING . ENCODING) pair, according to PO file charset. |
| 188 | ;Called through file-coding-system-alist, before the file is visited for real." | 120 | ;Called through file-coding-system-alist, before the file is visited for real." |
| 189 | ; (po-find-file-coding-system-guts operation filename)) | 121 | ; (po-find-file-coding-system-guts operation filename)) |
| 122 | |||
| 123 | (provide 'po) | ||
| 124 | |||
| 125 | ;;; po.el ends here | ||