44
44
;; - GNU Emacs (version 19) -> no flag.
46
46
(cond ((string-match "XEmacs\\|Lucid" emacs-version)
47
(setq po-EMACS20 nil po-XEMACS t))
48
((and (string-lessp "19" emacs-version) (featurep 'faces))
49
(setq po-EMACS20 t po-XEMACS nil))
50
(t (setq po-EMACS20 nil po-XEMACS nil))))
47
(setq po-EMACS20 nil po-XEMACS t))
48
((and (string-lessp "19" emacs-version) (featurep 'faces))
49
(setq po-EMACS20 t po-XEMACS nil))
50
(t (setq po-EMACS20 nil po-XEMACS nil))))
52
52
;; Handle missing 'with-temp-buffer' function.
57
57
(defmacro po-with-temp-buffer (&rest forms)
58
58
"Create a temporary buffer, and evaluate FORMS there like 'progn'."
59
59
(let ((curr-buffer (make-symbol "curr-buffer"))
60
(temp-buffer (make-symbol "temp-buffer")))
61
`(let ((,curr-buffer (current-buffer))
62
(,temp-buffer (get-buffer-create
63
(generate-new-buffer-name " *po-temp*"))))
66
(set-buffer ,temp-buffer)
68
(set-buffer ,curr-buffer)
69
(and (buffer-name ,temp-buffer)
70
(kill-buffer ,temp-buffer))))))))
60
(temp-buffer (make-symbol "temp-buffer")))
61
`(let ((,curr-buffer (current-buffer))
62
(,temp-buffer (get-buffer-create
63
(generate-new-buffer-name " *po-temp*"))))
66
(set-buffer ,temp-buffer)
68
(set-buffer ,curr-buffer)
69
(and (buffer-name ,temp-buffer)
70
(kill-buffer ,temp-buffer))))))))
72
72
(defconst po-content-type-charset-alist
73
73
'(; Note: Emacs 21 doesn't support all encodings, thus the missing entries.
163
163
(while (not (or short-read (re-search-forward "^msgid" nil t)))
165
165
(goto-char (point-max))
166
(let ((pair (insert-file-contents-literally filename nil
168
(1- (+ (point) 4096)))))
169
(setq short-read (< (nth 1 pair) 4096)))))
166
(let ((pair (insert-file-contents-literally filename nil
168
(1- (+ (point) 4096)))))
169
(setq short-read (< (nth 1 pair) 4096)))))
170
170
(cond ((re-search-forward charset-regexp nil t) (match-string 1))
172
;; We've found the first msgid; maybe, only a part of the msgstr
173
;; value was loaded. Load the next 1024 bytes; if charset still
174
;; isn't available, give up.
176
(goto-char (point-max))
177
(insert-file-contents-literally filename nil
179
(1- (+ (point) 1024))))
180
(if (re-search-forward charset-regexp nil t)
181
(match-string 1))))))
172
;; We've found the first msgid; maybe, only a part of the msgstr
173
;; value was loaded. Load the next 1024 bytes; if charset still
174
;; isn't available, give up.
176
(goto-char (point-max))
177
(insert-file-contents-literally filename nil
179
(1- (+ (point) 1024))))
180
(if (re-search-forward charset-regexp nil t)
181
(match-string 1))))))
183
183
(eval-and-compile
185
185
(defun po-find-file-coding-system-guts (operation filename)
187
187
Return a Mule (DECODING . ENCODING) pair, according to PO file charset.
188
188
Called through file-coding-system-alist, before the file is visited for real."
189
(and (eq operation 'insert-file-contents)
190
(file-exists-p filename)
192
(let* ((coding-system-for-read 'no-conversion)
193
(charset (or (po-find-charset filename) "ascii"))
194
(charset-upper (upcase charset))
195
(charset-lower (downcase charset))
197
(cdr (assoc charset-upper po-content-type-charset-alist)))
198
(try-symbol (or candidate (intern-soft charset-lower)))
200
(if try-symbol (symbol-name try-symbol) charset-lower)))
201
(list (cond ((and try-symbol (coding-system-p try-symbol))
204
(string-match "\\`cp[1-9][0-9][0-9]?\\'"
206
(assoc (substring try-string 2)
207
(cp-supported-codepages)))
208
(codepage-setup (substring try-string 2))
211
'no-conversion))))))))
189
(and (eq operation 'insert-file-contents)
190
(file-exists-p filename)
192
(let* ((coding-system-for-read 'no-conversion)
193
(charset (or (po-find-charset filename) "ascii"))
194
(charset-upper (upcase charset))
195
(charset-lower (downcase charset))
197
(cdr (assoc charset-upper po-content-type-charset-alist)))
198
(try-symbol (or candidate (intern-soft charset-lower)))
200
(if try-symbol (symbol-name try-symbol) charset-lower)))
201
(list (cond ((and try-symbol (coding-system-p try-symbol))
204
(string-match "\\`cp[1-9][0-9][0-9]?\\'"
206
(assoc (substring try-string 2)
207
(cp-supported-codepages)))
208
(codepage-setup (substring try-string 2))
211
'no-conversion))))))))
214
214
(defun po-find-file-coding-system-guts (operation filename)
216
216
Return a Mule (DECODING . ENCODING) pair, according to PO file charset.
217
217
Called through file-coding-system-alist, before the file is visited for real."
218
(and (eq operation 'insert-file-contents)
219
(file-exists-p filename)
221
(let ((coding-system-for-read 'no-conversion))
218
(and (eq operation 'insert-file-contents)
219
(file-exists-p filename)
221
(let ((coding-system-for-read 'no-conversion))
222
222
(let* ((charset (or (po-find-charset filename)
224
224
(charset-upper (upcase charset))
225
225
(charset-lower (intern (downcase charset))))
226
226
(list (or (cdr (assoc charset-upper
233
233
(defun po-find-file-coding-system (arg-list)
235
235
Return a Mule (DECODING . ENCODING) pair, according to PO file charset.
236
236
Called through file-coding-system-alist, before the file is visited for real."
237
(po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list)))))
237
(po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list)))))
240
240
(defun po-find-file-coding-system (operation filename)
242
242
Return a Mule (DECODING . ENCODING) pair, according to PO file charset.
243
243
Called through file-coding-system-alist, before the file is visited for real."
244
(po-find-file-coding-system-guts operation filename)))
244
(po-find-file-coding-system-guts operation filename)))