]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Get rid of 4096 limit.
authorBruno Haible <bruno@clisp.org>
Mon, 9 Jul 2001 14:08:56 +0000 (14:08 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 9 Jul 2001 14:08:56 +0000 (14:08 +0000)
misc/ChangeLog
misc/po-mode.el

index 5f0fa17959d2071115226934cb3a1530a057841b..b501f884c0af9c603d533f8256b235175fe88df1 100644 (file)
@@ -1,3 +1,10 @@
+2001-07-08  Karl Eichwalder  <ke@suse.de>
+
+       * po-mode.el: Don't recommend to use po-mode for POT files.
+       (po-find-charset): New function.
+       (po-find-file-coding-system-guts): Use it to get rid of the 4096 limit.
+       If no charset found, use "none".
+
 2001-07-07  Karl Eichwalder  <ke@suse.de>
 
        * po-mode.el (po-compute-counters): Don't count the header entry.
index 0f8d33f0e5c9357b3b031510438138a6db63c792..060674a320e23dd1416136a1ed1896b0a78333a1 100644 (file)
 ;;;
 ;;;   (autoload 'po-mode "po-mode"
 ;;;             "Major mode for translators to edit PO files" t)
-;;;   (setq auto-mode-alist (cons '("\\.po[tx]?\\'\\|\\.po\\." . po-mode)
+;;;   (setq auto-mode-alist (cons '("\\.po\\'\\|\\.po\\." . po-mode)
 ;;;                              auto-mode-alist))
 ;;;
 ;;; To automatically use the right coding system under Emacs 20, also add:
 ;;;
 ;;;   (autoload 'po-find-file-coding-system "po-mode")
-;;;   (modify-coding-system-alist 'file "\\.po[tx]?\\'\\|\\.po\\."
+;;;   (modify-coding-system-alist 'file "\\.po\\'\\|\\.po\\."
 ;;;                              'po-find-file-coding-system)
 ;;;
 ;;; You may also adjust some variables, below, by defining them in your
@@ -697,6 +697,30 @@ Content-Type into a Mule coding system.")
 \f
 ;;; Mode activation.
 
+(defun po-find-charset (filename)
+  "Return PO file charset value."
+  (interactive)
+  (let ((po-charset "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\""))
+    ;; 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 (re-search-forward "^msgid" nil t))
+      (save-excursion
+        (goto-char (point-max))
+        (insert-file-contents filename nil (1- (point)) (1- (+ (point) 4096)))))
+    (if (re-search-forward po-charset nil t)
+        (match-string 1)
+      (progn
+        (save-excursion
+          (goto-char (point-max))
+          ;; 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.
+          (insert-file-contents filename nil (point) (+ (point) 1024)))
+        (when (re-search-forward po-charset nil t)
+          (match-string 1))))))
+
 (eval-and-compile
   (if (or po-EMACS20 po-XEMACS)
       (defun po-find-file-coding-system-guts (operation filename)
@@ -705,21 +729,15 @@ Called through file-coding-system-alist, before the file is visited for real."
        (and (eq operation 'insert-file-contents)
             (with-temp-buffer
               (let ((coding-system-for-read 'no-conversion))
-                ;; Is 4096 enough?  FIXME: Retry as needed!
-                (insert-file-contents filename nil 0 4096)
-                (if (re-search-forward
-                     "^\"Content-Type: text/plain;[ \t]*charset=\\([^\\]+\\)"
-                     nil t)
-                    (let* ((charset (buffer-substring
-                                      (match-beginning 1) (match-end 1)))
-                           (charset-upper (intern (upcase charset)))
-                           (charset-lower (intern (downcase charset))))
-                      (list (or (cdr (assq charset-upper
-                                           po-content-type-charset-alist))
-                                (if (memq charset-lower (coding-system-list))
-                                    charset-lower
-                                  'no-conversion))))
-                  '(no-conversion)))))))
+                 (let* ((charset (or (po-find-charset filename)
+                                    "none"))
+                        (charset-upper (intern (upcase charset)))
+                        (charset-lower (intern (downcase charset))))
+                   (list (or (cdr (assq charset-upper
+                                        po-content-type-charset-alist))
+                             (if (memq charset-lower (coding-system-list))
+                                 charset-lower
+                               'no-conversion)))))))))
 
   (if po-EMACS20
       (defun po-find-file-coding-system (arg-list)