bug-gnu-utils
[Top][All Lists]
Advanced

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

[PATCH] (auto-)deletion of previous msgids on po-mode


From: Kobayashi Noritada
Subject: [PATCH] (auto-)deletion of previous msgids on po-mode
Date: Sat, 31 May 2008 14:21:33 +0900 (JST)

Hi,

Recent msgmerge have an option '--previous' to keep previous msgids as
a previous-msgid field beginning with "#|" for entries getting fuzzy,
but current po-mode does not have any support for such a field.  Since
it would be better to delete them when unfuzzying entries including
them, I have created a patch to support (auto-)deletion of previous
msgids on po-mode.  Could you please review and apply a patch attached
to this message?

Many thanks,

-nori
Index: gettext/gettext-tools/misc/po-mode.el
===================================================================
--- gettext.orig/gettext-tools/misc/po-mode.el  2008-05-29 21:52:06.000000000 
+0900
+++ gettext/gettext-tools/misc/po-mode.el       2008-05-31 09:42:23.000000000 
+0900
@@ -129,6 +129,13 @@
                  (const ask))
   :group 'po)
 
+(defcustom po-auto-delete-previous-msgid t
+  "*Automatically delete previous msgid when unfuzzying msgstr.  Value is nil, 
t, or ask."
+  :type '(choice (const nil)
+                 (const t)
+                 (const ask))
+  :group 'po)
+
 (defcustom po-default-file-header "\
 # SOME DESCRIPTIVE TITLE.
 # Copyright (C) YEAR Free Software Foundation, Inc.
@@ -685,6 +692,7 @@
 ;; start of keyword lines are START-OF-MSGID and START-OF-MSGSTR.
 ;; ENTRY-TYPE classifies the entry.
 (defvar po-start-of-entry)
+(defvar po-start-of-previous-msgid) ; = po-start-of-msgctxt if there is no 
previous msgid
 (defvar po-start-of-msgctxt) ; = po-start-of-msgid if there is no msgctxt
 (defvar po-start-of-msgid)
 (defvar po-start-of-msgid-plural) ; = po-start-of-msgstr-block if there is no 
msgid_plural
@@ -1001,6 +1009,10 @@
                          (error (_"I do not know how to mail to '%s'") to))))))
   "Function to start composing an electronic message.")
 
+(defvar po-any-previous-msgid-msgctxt-msgid-regexp
+  "\\(\\(^#|.*\n\\)+\\|^\\(#~[ \t]*\\)?msg\\(ctxt\\|id\\).*\n\\(\\(#~[ 
\t]*\\)?\".*\n\\)*\\)"
+  "Regexp matching a whole previous msgid, msgctxt, or msgid field, whether 
obsolete or not.")
+
 (defvar po-any-msgctxt-msgid-regexp
   "^\\(#~[ \t]*\\)?msg\\(ctxt\\|id\\).*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*"
   "Regexp matching a whole msgctxt or msgid field, whether obsolete or not.")
@@ -1161,6 +1173,7 @@
   (setq buffer-read-only t)
 
   (make-local-variable 'po-start-of-entry)
+  (make-local-variable 'po-start-of-previous-msgid)
   (make-local-variable 'po-start-of-msgctxt)
   (make-local-variable 'po-start-of-msgid)
   (make-local-variable 'po-start-of-msgid-plural)
@@ -1459,6 +1472,9 @@
             po-end-of-entry (match-end 0)))
     ;; Find start of msgid and msgid_plural.
     (goto-char po-start-of-entry)
+    (re-search-forward po-any-previous-msgid-msgctxt-msgid-regexp)
+    (setq po-start-of-previous-msgid (match-beginning 0))
+    (goto-char po-start-of-entry)
     (re-search-forward po-any-msgctxt-msgid-regexp)
     (setq po-start-of-msgctxt (match-beginning 0))
     (goto-char po-start-of-entry)
@@ -1715,6 +1731,14 @@
   (interactive)
   (po-previous-entry-with-regexp po-fuzzy-regexp t))
 
+(defun po-delete-previous-msgid ()
+  "Delete the previous msgid field from the current entry."
+  (interactive)
+  (po-find-span-of-entry)
+  (save-excursion
+    (let ((buffer-read-only po-read-only))
+      (delete-region po-start-of-previous-msgid po-start-of-msgctxt))))
+
 (defun po-unfuzzy ()
   "Remove the fuzzy attribute for the current entry."
   (interactive)
@@ -1724,6 +1748,13 @@
          (po-delete-attribute "fuzzy")
          (po-current-entry)
          (po-increase-type-counter)))
+  (if (and (not (eq po-start-of-previous-msgid
+                    po-start-of-msgctxt))
+           (or (eq po-auto-delete-previous-msgid t)
+               (and (eq po-auto-delete-previous-msgid 'ask)
+                    (y-or-n-p (_"May I delete previous msgid? ")))))
+      (po-delete-previous-msgid))
+  (message "")
   (if po-auto-select-on-unfuzzy
       (po-auto-select-entry))
   (po-update-mode-line-string))

reply via email to

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