summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2010-09-12 17:52:30 +0000
committerDaiki Ueno <ueno@gnu.org>2013-03-05 12:30:04 +0900
commit72147b5f4e3a71c1fee03c4bd59af78517f6b15a (patch)
treed653b924485bf64672d1e9016b5232d19e43a8b8
parent989529926b0e34126c50f128f4049361c2541eec (diff)
downloadexternal_gettext-72147b5f4e3a71c1fee03c4bd59af78517f6b15a.zip
external_gettext-72147b5f4e3a71c1fee03c4bd59af78517f6b15a.tar.gz
external_gettext-72147b5f4e3a71c1fee03c4bd59af78517f6b15a.tar.bz2
po-mode: make (po-check-file-header) optional (bug #30835)
po-mode would always overwrite the PO Header Entry when editing *.po files. This isn't always desired behavior as noted in bug #30835 so it's now customizable. It can be customized through the po-auto-update-file-header variable, which can be t, nil or 'ask. It's t by default to preserve the old default behavior. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
-rw-r--r--gettext-tools/misc/ChangeLog5
-rw-r--r--gettext-tools/misc/po-mode.el84
2 files changed, 53 insertions, 36 deletions
diff --git a/gettext-tools/misc/ChangeLog b/gettext-tools/misc/ChangeLog
index 9a9aac1..a9b3c30 100644
--- a/gettext-tools/misc/ChangeLog
+++ b/gettext-tools/misc/ChangeLog
@@ -1,3 +1,8 @@
+2013-03-05 Ævar Arnfjörð Bjarmason <avarab@gmail.com> (tiny change)
+
+ * po-mode.el (po-auto-update-file-header): New user option.
+ (po-check-file-header): Respect 'po-auto-update-file-header'.
+
2013-03-04 Daiki Ueno <ueno@gnu.org>
* autopoint.in: Handle macro directories specified in configure.ac.
diff --git a/gettext-tools/misc/po-mode.el b/gettext-tools/misc/po-mode.el
index 0e6ef99..94ddb07 100644
--- a/gettext-tools/misc/po-mode.el
+++ b/gettext-tools/misc/po-mode.el
@@ -130,6 +130,13 @@ Value is nil, t, or ask."
:type 'boolean
:group 'po)
+(defcustom po-auto-update-file-header t
+ "*Automatically revise headers. Value is nil, t, or ask."
+ :type '(choice (const nil)
+ (const t)
+ (const ask))
+ :group 'po)
+
(defcustom po-auto-replace-revision-date t
"*Automatically revise date in headers. Value is nil, t, or ask."
:type '(choice (const nil)
@@ -1356,42 +1363,47 @@ Position %d/%d; %d translated, %d fuzzy, %d untranslated, %d obsolete")
;;; Processing the PO file header entry.
(defun po-check-file-header ()
- "Create a missing PO mode file header, or replace an oldish one."
- (save-excursion
- (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-block-regexp nil t)
- (progn
- ;; There is at least one entry.
- (goto-char (match-beginning 0))
- (forward-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))
- (forward-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"))))))))
+ "Create a missing PO mode file header, or replace an oldish one.
+Can be customized with the `po-auto-update-file-header' variable."
+ (if (or (eq po-auto-update-file-header t)
+ (and (eq po-auto-update-file-header 'ask)
+ (y-or-n-p (_"May I update the PO Header Entry? "))))
+ (save-excursion
+ (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-block-regexp nil t)
+ (progn
+ ;; There is at least one entry.
+ (goto-char (match-beginning 0))
+ (forward-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))
+ (forward-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")))))))
+ (message (_"PO Header Entry was not updated..."))))
(defun po-replace-revision-date ()
"Replace the revision date by current time in the PO file header."