From: Bruno Haible Date: Sat, 30 Jun 2007 20:53:26 +0000 (+0000) Subject: Don't insert a header entry if there is already one outside the narrowed X-Git-Tag: v0.17~307 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf30d1b683e074ae186deddd435cd9cf8a63aafa;p=thirdparty%2Fgettext.git Don't insert a header entry if there is already one outside the narrowed region. --- diff --git a/gettext-tools/misc/ChangeLog b/gettext-tools/misc/ChangeLog index 88a510acc..0abe3a5ef 100644 --- a/gettext-tools/misc/ChangeLog +++ b/gettext-tools/misc/ChangeLog @@ -1,3 +1,9 @@ +2007-06-30 Bruno Haible + + * po-mode.el (po-check-file-header): Use save-restriction. + Report and patch by Sven Joachim in + . + 2007-06-30 Bruno Haible * po-mode.el (po-team-name-to-code): Add a few more entries. diff --git a/gettext-tools/misc/po-mode.el b/gettext-tools/misc/po-mode.el index 3c0c8cfbf..1f909acba 100644 --- a/gettext-tools/misc/po-mode.el +++ b/gettext-tools/misc/po-mode.el @@ -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."