>From d706ce71b207e0fa1d00e1eff2e26a9b72e1a585 Mon Sep 17 00:00:00 2001 From: Eliza Velasquez Date: Sat, 15 Jul 2023 03:38:17 -0700 Subject: [PATCH 1/2] po-mode.el: Update minimum version to Emacs 23 --- gettext-tools/emacs/po-compat.el | 199 -------------- gettext-tools/emacs/po-mode.el | 429 +++++++++++-------------------- gettext-tools/emacs/start-po.el | 12 +- 3 files changed, 153 insertions(+), 487 deletions(-) delete mode 100644 gettext-tools/emacs/po-compat.el diff --git a/gettext-tools/emacs/po-compat.el b/gettext-tools/emacs/po-compat.el deleted file mode 100644 index 438318e7f..000000000 --- a/gettext-tools/emacs/po-compat.el +++ /dev/null @@ -1,199 +0,0 @@ -;;; po-compat.el --- basic support of PO translation files -*- coding: latin-1; -*- - -;; Copyright (C) 1995-2002, 2010, 2016, 2019 Free Software Foundation, Inc. - -;; Authors: François Pinard , -;; Greg McGary , -;; Bruno Haible . -;; Keywords: i18n, files - -;; This file is part of GNU gettext. - -;; GNU gettext is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) -;; any later version. - -;; GNU gettext is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, see -;; . - -;;; Commentary: - -;; Emacs 21.2 and newer already contain this file, under the name po.el, -;; and without portability hassles. - -;; This package makes sure visiting PO files decodes them correctly, -;; according to the Charset= header in the PO file. For more support -;; for editing PO files, see po-mode.el. - -;;; Code: - -;;; Emacs portability matters. - -(defconst po-content-type-charset-alist - '(; Note: Emacs 21 doesn't support all encodings, thus the missing entries. - ("ASCII" . undecided) - ("ANSI_X3.4-1968" . undecided) - ("US-ASCII" . undecided) - ("ISO-8859-1" . iso-8859-1) - ("ISO_8859-1" . iso-8859-1) - ("ISO-8859-2" . iso-8859-2) - ("ISO_8859-2" . iso-8859-2) - ("ISO-8859-3" . iso-8859-3) - ("ISO_8859-3" . iso-8859-3) - ("ISO-8859-4" . iso-8859-4) - ("ISO_8859-4" . iso-8859-4) - ("ISO-8859-5" . iso-8859-5) - ("ISO_8859-5" . iso-8859-5) - ;("ISO-8859-6" . ??) - ;("ISO_8859-6" . ??) - ("ISO-8859-7" . iso-8859-7) - ("ISO_8859-7" . iso-8859-7) - ("ISO-8859-8" . iso-8859-8) - ("ISO_8859-8" . iso-8859-8) - ("ISO-8859-9" . iso-8859-9) - ("ISO_8859-9" . iso-8859-9) - ;("ISO-8859-13" . ??) - ;("ISO_8859-13" . ??) - ;("ISO-8859-14" . ??) - ;("ISO_8859-14" . ??) - ("ISO-8859-15" . iso-8859-15) - ("ISO_8859-15" . iso-8859-15) - ("KOI8-R" . koi8-r) - ;("KOI8-U" . ??) - ;("KOI8-T" . ??) - ("CP437" . cp437) - ("CP775" . cp775) - ("CP850" . cp850) - ("CP852" . cp852) - ("CP855" . cp855) - ;("CP856" . ??) - ("CP857" . cp857) - ("CP861" . cp861) - ("CP862" . cp862) - ("CP864" . cp864) - ("CP865" . cp865) - ("CP866" . cp866) - ("CP869" . cp869) - ;("CP874" . ??) - ;("CP922" . ??) - ;("CP932" . ??) - ;("CP943" . ??) - ;("CP949" . ??) - ;("CP950" . ??) - ;("CP1046" . ??) - ;("CP1124" . ??) - ;("CP1129" . ??) - ("CP1250" . cp1250) - ("CP1251" . cp1251) - ("CP1252" . iso-8859-1) ; approximation - ("CP1253" . cp1253) - ("CP1254" . iso-8859-9) ; approximation - ("CP1255" . iso-8859-8) ; approximation - ;("CP1256" . ??) - ("CP1257" . cp1257) - ("GB2312" . cn-gb-2312) ; also named 'gb2312' and 'euc-cn' - ("EUC-JP" . euc-jp) - ("EUC-KR" . euc-kr) - ;("EUC-TW" . ??) - ("BIG5" . big5) - ;("BIG5-HKSCS" . ??) - ;("GBK" . ??) - ;("GB18030" . ??) - ("SHIFT_JIS" . shift_jis) - ;("JOHAB" . ??) - ("TIS-620" . tis-620) - ("VISCII" . viscii) - ;("GEORGIAN-PS" . ??) - ("UTF-8" . utf-8) - ) - "How to convert a GNU libc/libiconv canonical charset name as seen in -Content-Type into a Mule coding system.") - -(defun po-find-charset (filename) - "Return PO file charset value." - (interactive) - (let ((charset-regexp - "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") - (short-read nil)) - ;; 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 (or short-read (re-search-forward "^msgid" nil t))) - (save-excursion - (goto-char (point-max)) - (let ((pair (insert-file-contents-literally filename nil - (1- (point)) - (1- (+ (point) 4096))))) - (setq short-read (< (nth 1 pair) 4096))))) - (cond ((re-search-forward charset-regexp nil t) (match-string 1)) - (short-read nil) - ;; 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. - (t (save-excursion - (goto-char (point-max)) - (insert-file-contents-literally filename nil - (1- (point)) - (1- (+ (point) 1024)))) - (if (re-search-forward charset-regexp nil t) - (match-string 1)))))) - -;;;###autoload (autoload 'po-find-file-coding-system "po-compat") - -(defun po-find-file-coding-system-guts (operation filename) - "\ -Return a Mule (DECODING . ENCODING) pair, according to PO file charset. -Called through file-coding-system-alist, before the file is visited for real." - (and (eq operation 'insert-file-contents) - (file-exists-p filename) - (po-with-temp-buffer - (let* ((coding-system-for-read 'no-conversion) - (charset (or (po-find-charset filename) "ascii")) - (charset-upper (upcase charset)) - (charset-lower (downcase charset)) - (candidate - (cdr (assoc charset-upper po-content-type-charset-alist))) - (try-symbol (or candidate (intern-soft charset-lower))) - (try-string - (if try-symbol (symbol-name try-symbol) charset-lower))) - (list (cond ((and try-symbol (coding-system-p try-symbol)) - try-symbol) - ((and (not (string-lessp "23" emacs-version)) - (string-match "\\`cp[1-9][0-9][0-9]?\\'" - try-string) - (assoc (substring try-string 2) - (cp-supported-codepages))) - (codepage-setup (substring try-string 2)) - (intern try-string)) - (t - 'no-conversion))))))) - -(defun po-find-file-coding-system (arg-list) - "\ -Return a Mule (DECODING . ENCODING) pair, according to PO file charset. -Called through file-coding-system-alist, before the file is visited for real." - (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list)))) - -(provide 'po-compat) - -;;; Testing this file: - -;; For each pofile in { -;; cs.po ; gettext/po/cs.el, charset=ISO-8859-2 -;; cs-modified.po ; gettext/po/cs.el, charset=ISO_8859-2 -;; de.po ; gettext/po/de.el, charset=UTF-8, if $emacsimpl = emacs -;; } do -;; Start $emacsimpl -;; M-x load-file po-compat.el RET -;; C-x C-f $pofile RET -;; Verify charset marker in status line ('2' = ISO-8859-2, 'u' = UTF-8). - -;;; po-compat.el ends here diff --git a/gettext-tools/emacs/po-mode.el b/gettext-tools/emacs/po-mode.el index 78e8d11be..6f79e963d 100644 --- a/gettext-tools/emacs/po-mode.el +++ b/gettext-tools/emacs/po-mode.el @@ -6,6 +6,8 @@ ;; Greg McGary ;; Keywords: i18n gettext ;; Created: 1995 +;; Version: 2.28 +;; URL: https://www.gnu.org/software/gettext/ ;; This file is part of GNU gettext. @@ -46,6 +48,8 @@ ;; You may also adjust some variables, below, by defining them in your ;; '.emacs' file, either directly or through command 'M-x customize'. +;; This package requires Emacs 23.1 or later. + ;; TODO: ;; Plural form editing: ;; - When in edit mode, currently it highlights (in green) the msgid; @@ -76,18 +80,6 @@ Version number of this version of po-mode.el.") (defsubst translate-string (string) string))) (defsubst _ (string) (translate-string string)) (defsubst N_ (string) string) - -;; Handle missing 'customs' package. -(eval-and-compile - (condition-case () - (require 'custom) - (error nil)) - (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) - nil - (defmacro defgroup (&rest args) - nil) - (defmacro defcustom (var value doc &rest args) - `(defvar ,var ,value ,doc)))) ;;; Customisation. @@ -483,72 +475,20 @@ or remove the -m if you are not using the GNU version of 'uuencode'." ;;; Emacs portability matters - part II. -;;; Many portability matters are addressed in this page. The few remaining -;;; cases, elsewhere, all involve 'eval-and-compile', 'boundp' or 'fboundp'. - -;; Protect string comparisons from text properties if possible. -(eval-and-compile - (fset 'po-buffer-substring - (symbol-function (if (fboundp 'buffer-substring-no-properties) - 'buffer-substring-no-properties - 'buffer-substring))) - - (if (fboundp 'match-string-no-properties) - (fset 'po-match-string (symbol-function 'match-string-no-properties)) - (defun po-match-string (number) - "Return string of text matched by last search." - (po-buffer-substring (match-beginning number) (match-end number))))) - -;; Handle missing 'with-temp-buffer' function. -(eval-and-compile - (if (fboundp 'with-temp-buffer) - (fset 'po-with-temp-buffer (symbol-function 'with-temp-buffer)) - - (defmacro po-with-temp-buffer (&rest forms) - "Create a temporary buffer, and evaluate FORMS there like 'progn'." - (let ((curr-buffer (make-symbol "curr-buffer")) - (temp-buffer (make-symbol "temp-buffer"))) - `(let ((,curr-buffer (current-buffer)) - (,temp-buffer (get-buffer-create - (generate-new-buffer-name " *po-temp*")))) - (unwind-protect - (progn - (set-buffer ,temp-buffer) - ,@forms) - (set-buffer ,curr-buffer) - (and (buffer-name ,temp-buffer) - (kill-buffer ,temp-buffer)))))))) +;;; The remaining portability matters are addressed in this page. -;; Handle missing 'kill-new' function. +;; Handle missing `defvar-local'. (eval-and-compile - (if (fboundp 'kill-new) - (fset 'po-kill-new (symbol-function 'kill-new)) - - (defun po-kill-new (string) - "Push STRING onto the kill ring, for Emacs 18 where kill-new is missing." - (po-with-temp-buffer - (insert string) - (kill-region (point-min) (point-max)))))) - -;; Handle missing 'read-event' function. -(eval-and-compile - (fset 'po-read-event - (cond ((fboundp 'read-event) - ;; GNU Emacs. - 'read-event) - (t - ;; Older Emacses. - 'read-char)))) - -;; Handle missing 'force-mode-line-update' function. -(eval-and-compile - (if (fboundp 'force-mode-line-update) - (fset 'po-force-mode-line-update - (symbol-function 'force-mode-line-update)) - - (defun po-force-mode-line-update () - "Force the mode-line of the current buffer to be redisplayed." - (set-buffer-modified-p (buffer-modified-p))))) + (if (fboundp 'defvar-local) + (defalias 'po--defvar-local #'defvar-local) + (defmacro po--defvar-local (var val &optional docstring) + "Define VAR as a buffer-local variable with default value VAL. +Like `defvar' but additionally marks the variable as being +automatically buffer-local wherever it is set." + (declare (debug defvar) (doc-string 3) (indent 2)) + `(progn + (defvar ,var ,val ,docstring) + (make-variable-buffer-local ',var))))) ;; Handle portable highlighting. Code has been adapted (OK... stolen! :-) ;; from 'ispell.el'. @@ -581,32 +521,32 @@ The current buffer should be in PO mode, when this function is called." ;; Flag telling that MODE-LINE-STRING should be displayed. See 'Window' ;; page below. Exceptionally, this variable is local to *all* buffers. -(defvar po-mode-flag) +(po--defvar-local po-mode-flag nil) ;; PO buffers are kept read-only to prevent random modifications. READ-ONLY ;; holds the value of the read-only flag before PO mode was entered. -(defvar po-read-only) +(po--defvar-local po-read-only nil) ;; The current entry extends from START-OF-ENTRY to END-OF-ENTRY, it ;; includes preceding whitespace and excludes following whitespace. The ;; 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-msgctxt) ; = po-start-of-msgid if there is no msgctxt -(defvar po-start-of-msgid) -(defvar po-start-of-msgid_plural) ; = nil if there is no msgid_plural -(defvar po-start-of-msgstr-block) -(defvar po-start-of-msgstr-form) -(defvar po-end-of-msgstr-form) -(defvar po-end-of-entry) -(defvar po-entry-type) +(po--defvar-local po-start-of-entry nil) +(po--defvar-local po-start-of-msgctxt nil) ; = po-start-of-msgid if there is no msgctxt +(po--defvar-local po-start-of-msgid nil) +(po--defvar-local po-start-of-msgid_plural nil) ; = nil if there is no msgid_plural +(po--defvar-local po-start-of-msgstr-block nil) +(po--defvar-local po-start-of-msgstr-form nil) +(po--defvar-local po-end-of-msgstr-form nil) +(po--defvar-local po-end-of-entry nil) +(po--defvar-local po-entry-type nil) ;; A few counters are usefully shown in the Emacs mode line. -(defvar po-translated-counter) -(defvar po-fuzzy-counter) -(defvar po-untranslated-counter) -(defvar po-obsolete-counter) -(defvar po-mode-line-string) +(po--defvar-local po-translated-counter nil) +(po--defvar-local po-fuzzy-counter nil) +(po--defvar-local po-untranslated-counter nil) +(po--defvar-local po-obsolete-counter nil) +(po--defvar-local po-mode-line-string nil) ;; PO mode keeps track of fields being edited, for one given field should ;; have one editing buffer at most, and for exiting a PO buffer properly @@ -618,15 +558,15 @@ The current buffer should be in PO mode, when this function is called." ;; temporary Emacs buffer used to edit the string. OVERLAY-INFO, when not ;; nil, holds an overlay (or if overlays are not supported, a cons of two ;; markers) for this msgid string which became highlighted for the edit. -(defvar po-edited-fields) +(po--defvar-local po-edited-fields nil) ;; We maintain a set of movable pointers for returning to entries. -(defvar po-marker-stack) +(po--defvar-local po-marker-stack nil) ;; SEARCH path contains a list of directories where files may be found, ;; in a format suitable for read completion. Each directory includes ;; its trailing slash. PO mode starts with "./" and "../". -(defvar po-search-path) +(po--defvar-local po-search-path nil) ;; The following variables are meaningful only when REFERENCE-CHECK ;; is identical to START-OF-ENTRY, else they should be recomputed. @@ -634,9 +574,9 @@ The current buffer should be in PO mode, when this function is called." ;; entry, each list element is (PROMPT FILE LINE), where PROMPT may ;; be used for completing read, FILE is a string and LINE is a number. ;; REFERENCE-CURSOR is a cycling cursor into REFERENCE-ALIST. -(defvar po-reference-alist) -(defvar po-reference-cursor) -(defvar po-reference-check) +(po--defvar-local po-reference-alist nil) +(po--defvar-local po-reference-cursor nil) +(po--defvar-local po-reference-check nil) ;; The following variables are for marking translatable strings in program ;; sources. KEYWORDS is the list of keywords for marking translatable @@ -646,12 +586,12 @@ The current buffer should be in PO mode, when this function is called." ;; describe where it is. MARKING-OVERLAY, if not 'nil', holds the overlay ;; which highlight the last found string; for older Emacses, it holds the cons ;; of two markers around the highlighted region. -(defvar po-keywords) -(defvar po-string-contents) -(defvar po-string-buffer) -(defvar po-string-start) -(defvar po-string-end) -(defvar po-marking-overlay) +(po--defvar-local po-keywords nil) +(po--defvar-local po-string-contents nil) +(po--defvar-local po-string-buffer nil) +(po--defvar-local po-string-start nil) +(po--defvar-local po-string-end nil) +(po--defvar-local po-marking-overlay nil) ;;; PO mode variables and constants (usually not to customize). @@ -843,25 +783,7 @@ M-S Ignore path M-A Ignore PO file *M-L Ignore lexicon (defvar po-auxiliary-cursor nil "Cursor into the 'po-auxiliary-list'.") -(defvar po-compose-mail-function - (let ((functions '(compose-mail-other-window - message-mail-other-window - compose-mail - message-mail)) - result) - (while (and (not result) functions) - (if (fboundp (car functions)) - (setq result (car functions)) - (setq functions (cdr functions)))) - (cond (result) - ((fboundp 'mail-other-window) - (function (lambda (to subject) - (mail-other-window nil to subject)))) - ((fboundp 'mail) - (function (lambda (to subject) - (mail nil to subject)))) - (t (function (lambda (to subject) - (error (_"I do not know how to mail to '%s'") to)))))) +(defvar po-compose-mail-function #'compose-mail-other-window "Function to start composing an electronic message.") (defvar po-any-previous-msgctxt-regexp @@ -915,35 +837,15 @@ M-S Ignore path M-A Ignore PO file *M-L Ignore lexicon ("\\\\.\\|%[*$-.0-9hjltuzL]*[a-zA-Z]" . font-lock-variable-name-face) ) "Additional expressions to highlight in PO mode.") - -;; Old activator for 'font lock'. Is it still useful? I don't think so. -;;(if (boundp 'font-lock-keywords) -;; (put 'po-mode 'font-lock-keywords 'po-font-lock-keywords)) - -;; 'hilit19' based highlighting code has been disabled, as most probably -;; nobody really needs it (it also generates ugly byte-compiler warnings). -;; -;;(if (fboundp 'hilit-set-mode-patterns) -;; (hilit-set-mode-patterns 'po-mode -;; '(("^# .*\\|^#$" nil comment) -;; ("^#[.,:].*" nil include) -;; ("^\\(msgid\\|msgstr\\) *\"" nil keyword) -;; ("^\"\\|\"$" nil keyword)))) ;;; Mode activation. -;; Emacs 21.2 comes with po-find-file-coding-system. We give preference -;; to the version shipped with Emacs. -(if (not (fboundp 'po-find-file-coding-system)) - (require 'po-compat)) - (defvar po-mode-abbrev-table nil "Abbrev table used while in PO mode.") (define-abbrev-table 'po-mode-abbrev-table ()) (defvar po-mode-map - ;; Use (make-keymap) because (make-sparse-keymap) does not work on Demacs. - (let ((po-mode-map (make-keymap))) + (let ((po-mode-map (make-sparse-keymap))) (suppress-keymap po-mode-map) (define-key po-mode-map "\C-i" 'po-unfuzzy) (define-key po-mode-map "\C-j" 'po-msgid-to-msgstr) @@ -1010,64 +912,39 @@ M-S Ignore path M-A Ignore PO file *M-L Ignore lexicon "Keymap for PO mode.") ;;;###autoload -(defun po-mode () +(define-derived-mode po-mode nil "PO" "Major mode for translators when they edit PO files. -Special commands: -\\{po-mode-map} -Turning on PO mode calls the value of the variable 'po-mode-hook', -if that value is non-nil. Behaviour may be adjusted through some variables, -all reachable through 'M-x customize', in group 'Emacs.Editing.I18n.Po'." - (interactive) - (kill-all-local-variables) - (setq major-mode 'po-mode - mode-name "PO") - (use-local-map po-mode-map) - (if (fboundp 'easy-menu-define) - (easy-menu-define po-mode-menu po-mode-map "" po-mode-menu-layout)) - (set (make-local-variable 'font-lock-defaults) '(po-font-lock-keywords t)) - - (set (make-local-variable 'po-read-only) buffer-read-only) - (setq buffer-read-only t) +Behaviour may be adjusted through some variables, all reachable +through `\\[execute-extended-command] customize RET', in group 'Emacs.Editing.I18n.Po'." + :group 'po - (make-local-variable 'po-start-of-entry) - (make-local-variable 'po-start-of-msgctxt) - (make-local-variable 'po-start-of-msgid) - (make-local-variable 'po-start-of-msgid_plural) - (make-local-variable 'po-start-of-msgstr-block) - (make-local-variable 'po-end-of-entry) - (make-local-variable 'po-entry-type) + (easy-menu-define po-mode-menu po-mode-map "" po-mode-menu-layout) + (setq font-lock-defaults '(po-font-lock-keywords t)) - (make-local-variable 'po-translated-counter) - (make-local-variable 'po-fuzzy-counter) - (make-local-variable 'po-untranslated-counter) - (make-local-variable 'po-obsolete-counter) - (make-local-variable 'po-mode-line-string) + (setq po-read-only buffer-read-only) + (setq buffer-read-only t) (setq po-mode-flag t) (po-check-file-header) (po-compute-counters nil) - (set (make-local-variable 'po-edited-fields) nil) - (set (make-local-variable 'po-marker-stack) nil) - (set (make-local-variable 'po-search-path) '(("./") ("../"))) - - (set (make-local-variable 'po-reference-alist) nil) - (set (make-local-variable 'po-reference-cursor) nil) - (set (make-local-variable 'po-reference-check) 0) + (setq po-edited-fields nil + po-marker-stack nil + po-search-path '(("./") ("../")) + po-reference-alist nil + po-reference-cursor nil + po-reference-check 0 + po-keywords '(("gettext") ("gettext_noop") ("_") ("N_")) + po-string-contents nil + po-string-buffer nil + po-string-start nil + po-string-end nil + po-marking-overlay (po-create-overlay)) + + (add-hook 'write-contents-functions 'po-replace-revision-date) - (set (make-local-variable 'po-keywords) - '(("gettext") ("gettext_noop") ("_") ("N_"))) - (set (make-local-variable 'po-string-contents) nil) - (set (make-local-variable 'po-string-buffer) nil) - (set (make-local-variable 'po-string-start) nil) - (set (make-local-variable 'po-string-end) nil) - (set (make-local-variable 'po-marking-overlay) (po-create-overlay)) - - (add-hook 'write-contents-hooks 'po-replace-revision-date) - - (run-hooks 'po-mode-hook) (message (_"You may type 'h' or '?' for a short PO mode reminder."))) (defvar po-subedit-mode-map @@ -1082,8 +959,6 @@ all reachable through 'M-x customize', in group 'Emacs.Editing.I18n.Po'." ;;; Window management. -(make-variable-buffer-local 'po-mode-flag) - (defvar po-mode-line-entry '(po-mode-flag (" " po-mode-line-string)) "Mode line format entry displaying MODE-LINE-STRING.") @@ -1106,7 +981,7 @@ all reachable through 'M-x customize', in group 'Emacs.Editing.I18n.Po'." (format "+%du" po-untranslated-counter)) (if (> po-obsolete-counter 0) (format "+%do" po-obsolete-counter)))) - (po-force-mode-line-update)) + (force-mode-line-update)) (defun po-type-counter () "Return the symbol name of the counter appropriate for the current entry." @@ -1250,28 +1125,26 @@ Can be customized with the `po-auto-update-file-header' variable." (defun po-replace-revision-date () "Replace the revision date by current time in the PO file header." - (if (fboundp 'format-time-string) - (if (or (eq po-auto-replace-revision-date t) - (and (eq po-auto-replace-revision-date 'ask) - (y-or-n-p (_"May I set PO-Revision-Date? ")))) - (save-excursion - (goto-char (point-min)) - (if (re-search-forward "^\"PO-Revision-Date:.*" nil t) - (let* ((buffer-read-only po-read-only) - (time (current-time)) - (seconds (or (car (current-time-zone time)) 0)) - (minutes (/ (abs seconds) 60)) - (zone (format "%c%02d%02d" - (if (< seconds 0) ?- ?+) - (/ minutes 60) - (% minutes 60)))) - (replace-match - (concat "\"PO-Revision-Date: " - (format-time-string "%Y-%m-%d %H:%M" time) - zone "\\n\"") - t t)))) - (message "")) - (message (_"PO-Revision-Date should be adjusted..."))) + (if (or (eq po-auto-replace-revision-date t) + (and (eq po-auto-replace-revision-date 'ask) + (y-or-n-p (_"May I set PO-Revision-Date? ")))) + (save-excursion + (goto-char (point-min)) + (if (re-search-forward "^\"PO-Revision-Date:.*" nil t) + (let* ((buffer-read-only po-read-only) + (time (current-time)) + (seconds (or (car (current-time-zone time)) 0)) + (minutes (/ (abs seconds) 60)) + (zone (format "%c%02d%02d" + (if (< seconds 0) ?- ?+) + (/ minutes 60) + (% minutes 60)))) + (replace-match + (concat "\"PO-Revision-Date: " + (format-time-string "%Y-%m-%d %H:%M" time) + zone "\\n\"") + t t)))) + (message "")) ;; Return nil to indicate that the buffer has not yet been saved. nil) @@ -1707,7 +1580,7 @@ Crumb preceding or following the quoted string is ignored." (defun po-extract-part-unquoted (buffer start end) "Extract and return the unquoted string in BUFFER going from START to END. Surrounding quotes are already excluded by the position of START and END." - (po-with-temp-buffer + (with-temp-buffer (insert-buffer-substring buffer start end) ;; Glue concatenated strings. (goto-char (point-min)) @@ -1741,7 +1614,7 @@ If PREFIX, precede the result with its contents. If OBSOLETE, comment all generated lines in the returned string. Evaluating FORM should insert the wanted string in the buffer which is current at the time of evaluation. If FORM is itself a string, then this string is used for insertion." - (po-with-temp-buffer + (with-temp-buffer (if (stringp form) (insert form) (push-mark) @@ -1821,7 +1694,7 @@ described by FORM is merely identical to the msgid already in place." (save-excursion (goto-char po-start-of-entry) (re-search-forward po-any-msgid-regexp po-start-of-msgstr-block) - (and (not (string-equal (po-match-string 0) string)) + (and (not (string-equal (match-string-no-properties 0) string)) (let ((buffer-read-only po-read-only)) (replace-match string t t) (goto-char po-start-of-msgid) @@ -1842,7 +1715,7 @@ described by FORM is merely identical to the msgstr already in place." (save-excursion (goto-char po-start-of-msgstr-form) (re-search-forward po-any-msgstr-form-regexp po-end-of-msgstr-form) - (and (not (string-equal (po-match-string 0) string)) + (and (not (string-equal (match-string-no-properties 0) string)) (let ((buffer-read-only po-read-only)) (po-decrease-type-counter) (replace-match string t t) @@ -1856,7 +1729,7 @@ described by FORM is merely identical to the msgstr already in place." (interactive) (po-find-span-of-entry) (let ((string (po-get-msgstr-form))) - (po-kill-new string) + (kill-new string) string)) (defun po-kill-msgstr () @@ -1910,7 +1783,7 @@ or completely delete an obsolete entry, saving its msgstr on the kill ring." (po-decrease-type-counter) (po-update-mode-line-string) ;; TODO: Should save all msgstr forms here, not just one. - (po-kill-new (po-get-msgstr-form)) + (kill-new (po-get-msgstr-form)) (let ((buffer-read-only po-read-only)) (delete-region po-start-of-entry po-end-of-entry)) (goto-char po-start-of-entry) @@ -1934,7 +1807,7 @@ If KILL-FLAG, then add the unquoted comment to the kill ring." (save-excursion (goto-char po-start-of-entry) (if (re-search-forward po-comment-regexp po-end-of-entry t) - (po-with-temp-buffer + (with-temp-buffer (insert-buffer-substring buffer (match-beginning 0) (match-end 0)) (goto-char (point-min)) (while (not (eobp)) @@ -1952,7 +1825,7 @@ If FORM is itself a string, then this string is used for insertion. The string is properly recommented before the replacement occurs." (let ((obsolete (eq po-entry-type 'obsolete)) string) - (po-with-temp-buffer + (with-temp-buffer (if (stringp form) (insert form) (push-mark) @@ -1966,7 +1839,7 @@ The string is properly recommented before the replacement occurs." (setq string (buffer-string))) (goto-char po-start-of-entry) (if (re-search-forward po-comment-regexp po-end-of-entry t) - (if (not (string-equal (po-match-string 0) string)) + (if (not (string-equal (match-string-no-properties 0) string)) (let ((buffer-read-only po-read-only)) (replace-match string t t))) (skip-chars-forward " \t\n") @@ -2056,7 +1929,7 @@ comments) from the current entry, if the user gives the permission." ;; list EDITED-FIELDS kept in the PO buffer. See its description elsewhere. ;; Reminder: slots have the form (ENTRY-MARKER EDIT-BUFFER OVERLAY-INFO). -(defvar po-subedit-back-pointer) +(po--defvar-local po-subedit-back-pointer nil) (defun po-clean-out-killed-edits () "From EDITED-FIELDS, clean out any edit having a killed edit buffer." @@ -2104,6 +1977,9 @@ comments) from the current entry, if the user gives the permission." (fundamental-mode) (message (_"Type 'M-x po-mode RET' once done"))))) +(declare-function ediff-quit nil) +(defvar ediff-mode-map) + (defun po-ediff-quit () "Quit ediff and exit `recursive-edit'." (interactive) @@ -2111,8 +1987,8 @@ comments) from the current entry, if the user gives the permission." (exit-recursive-edit)) (add-hook 'ediff-keymap-setup-hook - '(lambda () - (define-key ediff-mode-map "Q" 'po-ediff-quit))) + #'(lambda () + (define-key ediff-mode-map "Q" #'po-ediff-quit))) ;; Avoid byte compiler warnings. (defvar entry-buffer) @@ -2264,7 +2140,7 @@ Run functions on po-subedit-mode-hook." po-edited-fields (cons slot po-edited-fields)) (pop-to-buffer edit-buffer) (text-mode) - (set (make-local-variable 'po-subedit-back-pointer) slot) + (setq po-subedit-back-pointer slot) (set (make-local-variable 'indent-line-function) 'indent-relative) (setq buffer-file-coding-system edit-coding) @@ -2274,9 +2150,8 @@ Run functions on po-subedit-mode-hook." (goto-char (point-min)) (and expand-tabs (setq indent-tabs-mode nil)) (use-local-map po-subedit-mode-map) - (if (fboundp 'easy-menu-define) - (easy-menu-define po-subedit-mode-menu po-subedit-mode-map "" - po-subedit-mode-menu-layout)) + (easy-menu-define po-subedit-mode-menu po-subedit-mode-map "" + po-subedit-mode-menu-layout) (set-syntax-table po-subedit-mode-syntax-table) (run-hooks 'po-subedit-mode-hook) (message po-subedit-message))))) @@ -2544,8 +2419,8 @@ without moving its cursor." (let (current name line path file) (while (looking-at "\\(\n#:\\)? *\\([^: ]*\\):\\([0-9]+\\)") (goto-char (match-end 0)) - (setq name (po-match-string 2) - line (po-match-string 3) + (setq name (match-string-no-properties 2) + line (match-string-no-properties 3) path po-search-path) (if (string-equal name "") nil @@ -2612,8 +2487,8 @@ If the command is repeated many times in a row, cycle through contexts." (defvar tags-loop-scan) ;; Locally set in each program source buffer. -(defvar po-find-string-function) -(defvar po-mark-string-function) +(po--defvar-local po-find-string-function nil) +(po--defvar-local po-mark-string-function nil) ;; Dynamically set within po-tags-search for po-tags-loop-operate. (defvar po-current-po-buffer) @@ -2679,7 +2554,7 @@ Disregard some simple strings which are most probably non-translatable." (setq data (apply po-find-string-function po-current-po-keywords nil)) (if data ;; Push the string just found into a work buffer for study. - (po-with-temp-buffer + (with-temp-buffer (insert (nth 0 data)) (goto-char (point-min)) ;; Accept if at least three letters in a row. @@ -2762,23 +2637,22 @@ keyword for subsequent commands, also added to possible completions." (defun po-preset-string-functions () "Preset FIND-STRING-FUNCTION and MARK-STRING-FUNCTION according to mode. -These variables are locally set in source buffer only when not already bound." - (let ((pair (cond ((equal major-mode 'awk-mode) - '(po-find-awk-string . po-mark-awk-string)) - ((member major-mode '(c-mode c++-mode)) - '(po-find-c-string . po-mark-c-string)) - ((equal major-mode 'emacs-lisp-mode) - '(po-find-emacs-lisp-string . po-mark-emacs-lisp-string)) - ((equal major-mode 'python-mode) - '(po-find-python-string . po-mark-python-string)) - ((and (equal major-mode 'sh-mode) - (string-equal mode-line-process "[bash]")) - '(po-find-bash-string . po-mark-bash-string)) - (t '(po-find-unknown-string . po-mark-unknown-string))))) - (or (boundp 'po-find-string-function) - (set (make-local-variable 'po-find-string-function) (car pair))) - (or (boundp 'po-mark-string-function) - (set (make-local-variable 'po-mark-string-function) (cdr pair))))) +These variables are locally set in source buffer only when nil." + (unless (and po-find-string-function po-mark-string-function) + (let ((pair (cond ((equal major-mode 'awk-mode) + '(po-find-awk-string . po-mark-awk-string)) + ((member major-mode '(c-mode c++-mode)) + '(po-find-c-string . po-mark-c-string)) + ((equal major-mode 'emacs-lisp-mode) + '(po-find-emacs-lisp-string . po-mark-emacs-lisp-string)) + ((equal major-mode 'python-mode) + '(po-find-python-string . po-mark-python-string)) + ((and (equal major-mode 'sh-mode) + (string-equal mode-line-process "[bash]")) + '(po-find-bash-string . po-mark-bash-string)) + (t '(po-find-unknown-string . po-mark-unknown-string))))) + (setq po-find-string-function (car pair)) + (setq po-mark-string-function (cdr pair))))) (defun po-find-unknown-string (keywords) "Dummy function to skip over a file, finding no string in it." @@ -2825,7 +2699,7 @@ Return (CONTENTS START END) for the found string, or nil if none found." (backward-char 1) (let ((end-keyword (point))) (skip-chars-backward "_A-Za-z0-9") - (if (member (list (po-buffer-substring + (if (member (list (buffer-substring-no-properties (point) end-keyword)) keywords) ;; Disregard already marked strings. @@ -2951,8 +2825,9 @@ Returns (CONTENTS START END) for the found string, or nil if none found." (skip-chars-backward " \n\t") (let ((end-keyword (point))) (skip-chars-backward "_A-Za-z0-9") - (if (member (list (po-buffer-substring (point) - end-keyword)) + (if (member (list (buffer-substring-no-properties + (point) + end-keyword)) keywords) ;; Disregard already marked strings. (progn @@ -3005,8 +2880,9 @@ Returns (CONTENTS START END) for the found string, or nil if none found." (let ((end-keyword (point))) (skip-chars-backward "-_A-Za-z0-9") (if (and (= (preceding-char) ?\() - (member (list (po-buffer-substring (point) - end-keyword)) + (member (list (buffer-substring-no-properties + (point) + end-keyword)) keywords)) ;; Disregard already marked strings. (progn @@ -3064,8 +2940,9 @@ Returns (CONTENTS START END) for the found string, or nil if none found." (skip-chars-backward " \n\t") (let ((end-keyword (point))) (skip-chars-backward "_A-Za-z0-9") - (if (member (list (po-buffer-substring (point) - end-keyword)) + (if (member (list (buffer-substring-no-properties + (point) + end-keyword)) keywords) ;; Disregard already marked strings. (setq contents nil))))) @@ -3161,14 +3038,14 @@ Leave point after marked string." (defun po-help () "Provide an help window for PO mode." (interactive) - (po-with-temp-buffer + (with-temp-buffer (insert po-help-display-string) (goto-char (point-min)) (save-window-excursion (switch-to-buffer (current-buffer)) (delete-other-windows) (message (_"Type any character to continue")) - (po-read-event)))) + (read-event)))) (defun po-undo () "Undo the last change to the PO file." @@ -3190,14 +3067,10 @@ Leave point after marked string." ;; all defcustoms and defvars of compile.el would be undone when the let* ;; terminates. (require 'compile) - (let* ((dev-null - (cond ((boundp 'null-device) null-device) ; since Emacs 20.3 - ((memq system-type '(windows-nt windows-95)) "NUL") - (t "/dev/null"))) - (output + (let* ((output (if po-keep-mo-file (concat (file-name-sans-extension buffer-file-name) ".mo") - dev-null)) + null-device)) (compilation-buffer-name-function (function (lambda (mode-name) (concat "*" mode-name " validation*")))) @@ -3211,7 +3084,7 @@ Leave point after marked string." (defvar po-msgfmt-version-checked nil) (defun po-msgfmt-version-check () "'msgfmt' from GNU gettext 0.10.36 or greater is required." - (po-with-temp-buffer + (with-temp-buffer (or ;; Don't bother checking again. po-msgfmt-version-checked @@ -3259,9 +3132,9 @@ Leave point after marked string." (goto-char start-of-header) (if (re-search-forward "\n\ \"Project-Id-Version: \\(GNU \\|Free \\)?\\([^\n ]+\\) \\([^\n ]+\\)\\\\n\"$" - end-of-header t) - (setq package (po-match-string 2) - version (po-match-string 3))) + end-of-header t) + (setq package (match-string-no-properties 2) + version (match-string-no-properties 3))) (if (or (not package) (string-equal package "PACKAGE") (not version) (string-equal version "VERSION")) (error (_"Project-Id-Version field does not have a proper value"))) @@ -3271,11 +3144,11 @@ Leave point after marked string." (;; TP Robot compatible `filename': PACKAGE-VERSION.LL.po (string-match (concat (regexp-quote package) "-\\(.*\\)\\.[^\\.]*\\.po\\'") filename) - (if (not (equal version (po-match-string 1 filename))) + (if (not (equal version (match-string-no-properties 1 filename))) (error (_"\ Version mismatch: file name: %s; header: %s.\n\ Adjust Project-Id-Version field to match file name and try again") - (po-match-string 1 filename) version)))) + (match-string-no-properties 1 filename) version)))) ;; Get the team. (if (stringp po-team-name-to-code) (setq team po-team-name-to-code) @@ -3283,7 +3156,7 @@ Adjust Project-Id-Version field to match file name and try again") (if (re-search-forward "\n\ \"Language-Team: \\([^ ].*[^ ]\\) <.+@.+>\\\\n\"$" end-of-header t) - (let ((name (po-match-string 1))) + (let ((name (match-string-no-properties 1))) (if name (let ((pair (assoc name po-team-name-to-code))) (if pair @@ -3306,10 +3179,10 @@ Team name '%s' unknown. What is the team code? " (if (re-search-forward "\n\"Language-Team: +\\(.*<\\(.*\\)@.*>\\)\\\\n\"$" (match-end 0) t) - (setq team (po-match-string 2))) + (setq team (match-string-no-properties 2))) (if (or (not team) (string-equal team "LL")) (error (_"Language-Team field does not have a proper value"))) - (po-match-string 1)))) + (match-string-no-properties 1)))) (defun po-send-mail () "Start composing a letter, possibly including the current PO file." diff --git a/gettext-tools/emacs/start-po.el b/gettext-tools/emacs/start-po.el index f8770ab3e..d90594fff 100644 --- a/gettext-tools/emacs/start-po.el +++ b/gettext-tools/emacs/start-po.el @@ -33,11 +33,8 @@ (autoload 'po-mode "po-mode" "Major mode for translators when they edit PO files. -Special commands: -\\{po-mode-map} -Turning on PO mode calls the value of the variable 'po-mode-hook', -if that value is non-nil. Behaviour may be adjusted through some variables, -all reachable through 'M-x customize', in group 'Emacs.Editing.I18n.Po'." +Behaviour may be adjusted through some variables, all reachable +through `\\[execute-extended-command] customize RET', in group 'Emacs.Editing.I18n.Po'." t) (setq auto-mode-alist (cons '("\\.po\\'\\|\\.po\\." . po-mode) auto-mode-alist)) @@ -45,10 +42,5 @@ all reachable through 'M-x customize', in group 'Emacs.Editing.I18n.Po'." ;; For viewing PO and POT files. ;; To use the right coding system automatically. -(unless (fboundp 'po-find-file-coding-system) - (autoload 'po-find-file-coding-system "po-compat" - "\ -Return a Mule (DECODING . ENCODING) pair, according to PO file charset. -Called through file-coding-system-alist, before the file is visited for real.")) (modify-coding-system-alist 'file "\\.po[t]?\\'\\|\\.po\\." 'po-find-file-coding-system) -- 2.40.1