aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2006-05-26 04:47:16 +0000
committerKenichi Handa2006-05-26 04:47:16 +0000
commiteb286ca8bb2a7dc617ad24573bf1c7a31e56e39b (patch)
treeb22fb5adb7c53f3a88d9b6486832c3a6ea1b19d5
parent4d687160ec47448124bc93ab3aec2b24d49544c0 (diff)
downloademacs-eb286ca8bb2a7dc617ad24573bf1c7a31e56e39b.tar.gz
emacs-eb286ca8bb2a7dc617ad24573bf1c7a31e56e39b.zip
(po-find-charset): Pay attention to the case
FILENAME is a cons (NAME . BUFFER). (po-find-file-coding-system-guts): Likewise.
-rw-r--r--lisp/textmodes/po.el19
1 files changed, 14 insertions, 5 deletions
diff --git a/lisp/textmodes/po.el b/lisp/textmodes/po.el
index 07b9ba1a2b1..eac1cb94105 100644
--- a/lisp/textmodes/po.el
+++ b/lisp/textmodes/po.el
@@ -41,15 +41,21 @@
41Contains canonical charset names that don't correspond to coding systems.") 41Contains canonical charset names that don't correspond to coding systems.")
42 42
43(defun po-find-charset (filename) 43(defun po-find-charset (filename)
44 "Return PO charset value for FILENAME." 44 "Return PO charset value for FILENAME.
45If FILENAME is a cons, the cdr part is a buffer that already contains
46the PO file (but not yet decoded)."
45 (let ((charset-regexp 47 (let ((charset-regexp
46 "^\"Content-Type:[ \t]*text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") 48 "^\"Content-Type:[ \t]*text/plain;[ \t]*charset=\\(.*\\)\\\\n\"")
49 (buf (and (consp filename) (cdr filename)))
47 (short-read nil)) 50 (short-read nil))
51 (when buf
52 (set-buffer buf)
53 (goto-char (point-min)))
48 ;; Try the first 4096 bytes. In case we cannot find the charset value 54 ;; Try the first 4096 bytes. In case we cannot find the charset value
49 ;; within the first 4096 bytes (the PO file might start with a long 55 ;; within the first 4096 bytes (the PO file might start with a long
50 ;; comment) try the next 4096 bytes repeatedly until we'll know for sure 56 ;; comment) try the next 4096 bytes repeatedly until we'll know for sure
51 ;; we've checked the empty header entry entirely. 57 ;; we've checked the empty header entry entirely.
52 (while (not (or short-read (re-search-forward "^msgid" nil t))) 58 (while (not (or short-read (re-search-forward "^msgid" nil t) buf))
53 (save-excursion 59 (save-excursion
54 (goto-char (point-max)) 60 (goto-char (point-max))
55 (let ((pair (insert-file-contents-literally filename nil 61 (let ((pair (insert-file-contents-literally filename nil
@@ -57,7 +63,7 @@ Contains canonical charset names that don't correspond to coding systems.")
57 (1- (+ (point) 4096))))) 63 (1- (+ (point) 4096)))))
58 (setq short-read (< (nth 1 pair) 4096))))) 64 (setq short-read (< (nth 1 pair) 4096)))))
59 (cond ((re-search-forward charset-regexp nil t) (match-string 1)) 65 (cond ((re-search-forward charset-regexp nil t) (match-string 1))
60 (short-read nil) 66 ((or short-read buf) nil)
61 ;; We've found the first msgid; maybe, only a part of the msgstr 67 ;; We've found the first msgid; maybe, only a part of the msgstr
62 ;; value was loaded. Load the next 1024 bytes; if charset still 68 ;; value was loaded. Load the next 1024 bytes; if charset still
63 ;; isn't available, give up. 69 ;; isn't available, give up.
@@ -71,10 +77,13 @@ Contains canonical charset names that don't correspond to coding systems.")
71 77
72(defun po-find-file-coding-system-guts (operation filename) 78(defun po-find-file-coding-system-guts (operation filename)
73 "Return a (DECODING . ENCODING) pair for OPERATION on PO file FILENAME. 79 "Return a (DECODING . ENCODING) pair for OPERATION on PO file FILENAME.
74Do so according to FILENAME's declared charset." 80Do so according to FILENAME's declared charset.
81FILENAME may be a cons (NAME . BUFFER). In that case, detect charset
82in BUFFER."
75 (and 83 (and
76 (eq operation 'insert-file-contents) 84 (eq operation 'insert-file-contents)
77 (file-exists-p filename) 85 (or (if (consp filename) (buffer-live-p (cdr filename)))
86 (file-exists-p filename))
78 (with-temp-buffer 87 (with-temp-buffer
79 (let* ((coding-system-for-read 'no-conversion) 88 (let* ((coding-system-for-read 'no-conversion)
80 (charset (or (po-find-charset filename) "ascii")) 89 (charset (or (po-find-charset filename) "ascii"))