emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/textmodes/po.el


From: Kenichi Handa
Subject: [Emacs-diffs] Changes to emacs/lisp/textmodes/po.el
Date: Fri, 26 May 2006 04:47:16 +0000

Index: emacs/lisp/textmodes/po.el
diff -u emacs/lisp/textmodes/po.el:1.13 emacs/lisp/textmodes/po.el:1.14
--- emacs/lisp/textmodes/po.el:1.13     Mon Feb  6 12:12:26 2006
+++ emacs/lisp/textmodes/po.el  Fri May 26 04:47:16 2006
@@ -41,15 +41,21 @@
 Contains canonical charset names that don't correspond to coding systems.")
 
 (defun po-find-charset (filename)
-  "Return PO charset value for FILENAME."
+  "Return PO charset value for FILENAME.
+If FILENAME is a cons, the cdr part is a buffer that already contains
+the PO file (but not yet decoded)."
   (let ((charset-regexp
         "^\"Content-Type:[ \t]*text/plain;[ \t]*charset=\\(.*\\)\\\\n\"")
+       (buf (and (consp filename) (cdr filename)))
        (short-read nil))
+    (when buf
+      (set-buffer buf)
+      (goto-char (point-min)))
     ;; Try the first 4096 bytes.  In case we cannot find the charset value
     ;; within the first 4096 bytes (the PO file might start with a long
     ;; comment) try the next 4096 bytes repeatedly until we'll know for sure
     ;; we've checked the empty header entry entirely.
-    (while (not (or short-read (re-search-forward "^msgid" nil t)))
+    (while (not (or short-read (re-search-forward "^msgid" nil t) buf))
       (save-excursion
         (goto-char (point-max))
        (let ((pair (insert-file-contents-literally filename nil
@@ -57,7 +63,7 @@
                                                    (1- (+ (point) 4096)))))
          (setq short-read (< (nth 1 pair) 4096)))))
     (cond ((re-search-forward charset-regexp nil t) (match-string 1))
-         (short-read nil)
+         ((or short-read buf) nil)
          ;; We've found the first msgid; maybe, only a part of the msgstr
          ;; value was loaded.  Load the next 1024 bytes; if charset still
          ;; isn't available, give up.
@@ -71,10 +77,13 @@
 
 (defun po-find-file-coding-system-guts (operation filename)
   "Return a (DECODING . ENCODING) pair for OPERATION on PO file FILENAME.
-Do so according to FILENAME's declared charset."
+Do so according to FILENAME's declared charset.
+FILENAME may be a cons (NAME . BUFFER).  In that case, detect charset
+in BUFFER."
   (and
    (eq operation 'insert-file-contents)
-   (file-exists-p filename)
+   (or (if (consp filename) (buffer-live-p (cdr filename)))
+       (file-exists-p filename))
    (with-temp-buffer
      (let* ((coding-system-for-read 'no-conversion)
            (charset (or (po-find-charset filename) "ascii"))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]