/[emacs]/emacs/lisp/textmodes/po.el
ViewVC logotype

Diff of /emacs/lisp/textmodes/po.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by eliz, Sat Mar 16 17:28:49 2002 UTC revision 1.5.2.1 by miles, Fri Apr 4 06:20:39 2003 UTC
# Line 33  Line 33 
33  ;;; Code:  ;;; Code:
34    
35  (defconst po-content-type-charset-alist  (defconst po-content-type-charset-alist
36    '(; Note: Emacs 21 doesn't support all encodings, thus the missing entries.    '(("ASCII" . undecided)
     ("ASCII" . undecided)  
37      ("ANSI_X3.4-1968" . undecided)      ("ANSI_X3.4-1968" . undecided)
38      ("US-ASCII" . undecided)      ("US-ASCII" . undecided))
39      ("ISO-8859-1" . iso-8859-1)    "Alist of coding system versus GNU libc/libiconv canonical charset name.
40      ("ISO_8859-1" . iso-8859-1)  Contains canonical charset names that don't correspond to coding systems.")
     ("ISO-8859-2" . iso-8859-2)  
     ("ISO_8859-2" . iso-8859-2)  
     ("ISO-8859-3" . iso-8859-3)  
     ("ISO_8859-3" . iso-8859-3)  
     ("ISO-8859-4" . iso-8859-4)  
     ("ISO_8859-4" . iso-8859-4)  
     ("ISO-8859-5" . iso-8859-5)  
     ("ISO_8859-5" . iso-8859-5)  
     ;("ISO-8859-6" . ??)  
     ;("ISO_8859-6" . ??)  
     ("ISO-8859-7" . iso-8859-7)  
     ("ISO_8859-7" . iso-8859-7)  
     ("ISO-8859-8" . iso-8859-8)  
     ("ISO_8859-8" . iso-8859-8)  
     ("ISO-8859-9" . iso-8859-9)  
     ("ISO_8859-9" . iso-8859-9)  
     ;("ISO-8859-13" . ??)  
     ;("ISO_8859-13" . ??)  
     ("ISO-8859-15" . iso-8859-15) ; requires Emacs 21  
     ("ISO_8859-15" . iso-8859-15) ; requires Emacs 21  
     ("KOI8-R" . koi8-r)  
     ;("KOI8-U" . ??)  
     ("CP437" . cp437) ; requires Emacs 20  
     ("CP775" . cp775) ; requires Emacs 20  
     ("CP850" . cp850) ; requires Emacs 20  
     ("CP852" . cp852) ; requires Emacs 20  
     ("CP855" . cp855) ; requires Emacs 20  
     ;("CP856" . ??)  
     ("CP857" . cp857) ; requires Emacs 20  
     ("CP861" . cp861) ; requires Emacs 20  
     ("CP862" . cp862) ; requires Emacs 20  
     ("CP864" . cp864) ; requires Emacs 20  
     ("CP865" . cp865) ; requires Emacs 20  
     ("CP866" . cp866) ; requires Emacs 21  
     ("CP869" . cp869) ; requires Emacs 20  
     ;("CP874" . ??)  
     ;("CP922" . ??)  
     ;("CP932" . ??)  
     ;("CP943" . ??)  
     ;("CP949" . ??)  
     ;("CP950" . ??)  
     ;("CP1046" . ??)  
     ;("CP1124" . ??)  
     ;("CP1129" . ??)  
     ("CP1250" . cp1250) ; requires Emacs 20  
     ("CP1251" . cp1251) ; requires Emacs 20  
     ("CP1252" . iso-8859-1) ; approximation  
     ("CP1253" . cp1253) ; requires Emacs 20  
     ("CP1254" . iso-8859-9) ; approximation  
     ("CP1255" . iso-8859-8) ; approximation  
     ;("CP1256" . ??)  
     ("CP1257" . cp1257) ; requires Emacs 20  
     ("GB2312" . cn-gb-2312)  ; also named 'gb2312' in XEmacs 21 or Emacs 21  
                            ; also named 'euc-cn' in Emacs 20 or Emacs 21  
     ("EUC-JP" . euc-jp)  
     ("EUC-KR" . euc-kr)  
     ;("EUC-TW" . ??)  
     ("BIG5" . big5)  
     ;("BIG5-HKSCS" . ??)  
     ;("GBK" . ??)  
     ;("GB18030" . ??)  
     ("SHIFT_JIS" . shift_jis)  
     ;("JOHAB" . ??)  
     ("TIS-620" . tis-620)    ; requires Emacs 20 or Emacs 21  
     ("VISCII" . viscii)      ; requires Emacs 20 or Emacs 21  
     ("UTF-8" . utf-8)        ; requires Mule-UCS in Emacs 20, or Emacs 21  
     )  
   "How to convert a GNU libc/libiconv canonical charset name as seen in  
 Content-Type into a Mule coding system.")  
41    
42  (defun po-find-charset (filename)  (defun po-find-charset (filename)
43    "Return PO file charset value."    "Return PO charset value for FILENAME."
   (interactive)  
44    (let ((charset-regexp    (let ((charset-regexp
45           "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"")           "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"")
46          (short-read nil))          (short-read nil))
# Line 140  Content-Type into a Mule coding system." Line 69  Content-Type into a Mule coding system."
69                   (match-string 1))))))                   (match-string 1))))))
70    
71  (defun po-find-file-coding-system-guts (operation filename)  (defun po-find-file-coding-system-guts (operation filename)
72    "\    "Return a (DECODING . ENCODING) pair for OPERATION on PO file FILENAME.
73  Return a Mule (DECODING . ENCODING) pair, according to PO file charset.  Do so according to FILENAME's declared charset."
74  Called through file-coding-system-alist, before the file is visited for real."    (and
75    (and (eq operation 'insert-file-contents)     (eq operation 'insert-file-contents)
76         (file-exists-p filename)     (file-exists-p filename)
77         (with-temp-buffer     (with-temp-buffer
78           (let* ((coding-system-for-read 'no-conversion)       (let* ((coding-system-for-read 'no-conversion)
79                  (charset (or (po-find-charset filename) "ascii"))              (charset (or (po-find-charset filename) "ascii"))
80                  (charset-upper (upcase charset))              assoc)
81                  (charset-lower (downcase charset))         (list (cond
82                  (candidate                ((setq assoc
83                   (cdr (assoc charset-upper po-content-type-charset-alist)))                       (assoc-ignore-case charset
84                  (try (or candidate (intern-soft charset-lower))))                                          po-content-type-charset-alist))
85             (list (cond ((and try (coding-system-p try))                 (cdr assoc))
86                          try)                ((or (setq assoc (assoc-ignore-case charset coding-system-alist))
87                         ((and try                     (setq assoc
88                               (string-match "\\`cp[1-9][0-9][0-9]?\\'"                           (assoc-ignore-case (subst-char-in-string ?_ ?-
89                                             (symbol-name try))                                                                    charset)
90                               (assoc (substring (symbol-name try) 2)                                              coding-system-alist)))
91                                      (cp-supported-codepages)))                 (intern (car assoc)))
92                          (codepage-setup (substring (symbol-name try) 2))                ;; In principle we should also check the `mime-charset'
93                          try)                ;; property of everything in the base coding system
94                         ((and (string-match "\\`cp[1-9][0-9][0-9]?\\'"                ;; list, but there should always be a coding system
95                                             charset-lower)                ;; corresponding to the MIME name.
96                               (assoc (substring charset-lower 2)                ((featurep 'code-pages)
97                                      (cp-supported-codepages)))                 ;; Give up.
98                          (codepage-setup (substring charset-lower 2))                 'raw-text)
99                          (intern charset-lower))                (t
100                         (t                 ;; Try again with code-pages loaded.  Maybe it's best
101                          'no-conversion)))))))                 ;; 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))))))))
110    
111  ;;;###autoload  ;;;###autoload
112  (defun po-find-file-coding-system (arg-list)  (defun po-find-file-coding-system (arg-list)
113    "\    "Return a (DECODING . ENCODING) pair, according to PO file's charset.
114  Return a Mule (DECODING . ENCODING) pair, according to PO file charset.  Called through `file-coding-system-alist', before the file is visited for real."
 Called through file-coding-system-alist, before the file is visited for real."  
115    (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list))))    (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list))))
116  ;; This is for XEmacs.  ;; This is for XEmacs.
117  ;(defun po-find-file-coding-system (operation filename)  ;(defun po-find-file-coding-system (operation filename)
# Line 183  Called through file-coding-system-alist, Line 119  Called through file-coding-system-alist,
119  ;Return a Mule (DECODING . ENCODING) pair, according to PO file charset.  ;Return a Mule (DECODING . ENCODING) pair, according to PO file charset.
120  ;Called through file-coding-system-alist, before the file is visited for real."  ;Called through file-coding-system-alist, before the file is visited for real."
121  ;  (po-find-file-coding-system-guts operation filename))  ;  (po-find-file-coding-system-guts operation filename))
122    
123    (provide 'po)
124    
125    ;;; po.el ends here

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.5.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26