]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Don't insert a header entry if there is already one outside the narrowed
authorBruno Haible <bruno@clisp.org>
Sat, 30 Jun 2007 20:53:26 +0000 (20:53 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:58 +0000 (12:14 +0200)
region.

gettext-tools/misc/ChangeLog
gettext-tools/misc/po-mode.el

index 88a510accd2ce0160bb106996de998046431c0c3..0abe3a5ef2457a1c9390adfc6b2da349529ba087 100644 (file)
@@ -1,3 +1,9 @@
+2007-06-30  Bruno Haible  <bruno@clisp.org>
+
+       * po-mode.el (po-check-file-header): Use save-restriction.
+       Report and patch by Sven Joachim <sven_joachim@web.de> in
+       <http://lists.gnu.org/archive/html/bug-gnu-utils/2006-08/msg00110.html>.
+
 2007-06-30  Bruno Haible  <bruno@clisp.org>
 
        * po-mode.el (po-team-name-to-code): Add a few more entries.
index 3c0c8cfbfad39d7035c18fde30e7a670afe03b9d..1f909acbab12a4da18cd8b83e34ac72552b0bac7 100644 (file)
@@ -1339,38 +1339,40 @@ Position %d/%d; %d translated, %d fuzzy, %d untranslated, %d obsolete")
 (defun po-check-file-header ()
   "Create a missing PO mode file header, or replace an oldish one."
   (save-excursion
-    (let ((buffer-read-only po-read-only)
-          insert-flag end-of-header)
-      (goto-char (point-min))
-      (if (re-search-forward po-any-msgstr-regexp nil t)
-          (progn
-            ;; There is at least one entry.
-            (goto-char (match-beginning 0))
-            (previous-line 1)
-            (setq end-of-header (match-end 0))
-            (if (looking-at "msgid \"\"\n")
-                ;; There is indeed a PO file header.
-                (if (re-search-forward "\n\"PO-Revision-Date: "
-                                       end-of-header t)
-                    nil
-                  ;; This is an oldish header.  Replace it all.
-                  (goto-char end-of-header)
-                  (while (> (point) (point-min))
-                    (previous-line 1)
-                    (insert "#~ ")
-                    (beginning-of-line))
-                  (beginning-of-line)
-                  (setq insert-flag t))
-              ;; The first entry is not a PO file header, insert one.
-              (setq insert-flag t)))
-        ;; Not a single entry found.
-        (setq insert-flag t))
-      (goto-char (point-min))
-      (if insert-flag
-          (progn
-            (insert po-default-file-header)
-            (if (not (eobp))
-                (insert "\n")))))))
+    (save-restriction
+      (widen) ; in case of a narrowed view to the buffer
+      (let ((buffer-read-only po-read-only)
+            insert-flag end-of-header)
+        (goto-char (point-min))
+        (if (re-search-forward po-any-msgstr-regexp nil t)
+            (progn
+              ;; There is at least one entry.
+              (goto-char (match-beginning 0))
+              (previous-line 1)
+              (setq end-of-header (match-end 0))
+              (if (looking-at "msgid \"\"\n")
+                  ;; There is indeed a PO file header.
+                  (if (re-search-forward "\n\"PO-Revision-Date: "
+                                         end-of-header t)
+                      nil
+                    ;; This is an oldish header.  Replace it all.
+                    (goto-char end-of-header)
+                    (while (> (point) (point-min))
+                      (previous-line 1)
+                      (insert "#~ ")
+                      (beginning-of-line))
+                    (beginning-of-line)
+                    (setq insert-flag t))
+                ;; The first entry is not a PO file header, insert one.
+                (setq insert-flag t)))
+          ;; Not a single entry found.
+          (setq insert-flag t))
+        (goto-char (point-min))
+        (if insert-flag
+            (progn
+              (insert po-default-file-header)
+              (if (not (eobp))
+                  (insert "\n"))))))))
 
 (defun po-replace-revision-date ()
   "Replace the revision date by current time in the PO file header."