From: Bruno Haible Date: Fri, 6 Oct 2023 11:25:50 +0000 (+0200) Subject: po-mode: Remove support for Emacs versions < 23. X-Git-Tag: v0.23~330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7797a29e9c05802142fbcb07a9b9890d4e9e61e3;p=thirdparty%2Fgettext.git po-mode: Remove support for Emacs versions < 23. Reported by Julien Palard at . * gettext-tools/emacs/po-mode.el (po-mode-version-string): Bump to 2.29. (po-buffer-substring, po-match-string, po-with-temp-buffer, po-kill-new, po-read-event, po-force-mode-line-update): Remove portability polyfills. (easy-menu-define, format-time-string): Assume present as well. * gettext-tools/emacs/po-compat.el: Update. --- diff --git a/gettext-tools/emacs/po-compat.el b/gettext-tools/emacs/po-compat.el index 438318e7f..33c60e4ff 100644 --- a/gettext-tools/emacs/po-compat.el +++ b/gettext-tools/emacs/po-compat.el @@ -1,6 +1,6 @@ ;;; po-compat.el --- basic support of PO translation files -*- coding: latin-1; -*- -;; Copyright (C) 1995-2002, 2010, 2016, 2019 Free Software Foundation, Inc. +;; Copyright (C) 1995-2002, 2010, 2016, 2019, 2023 Free Software Foundation, Inc. ;; Authors: François Pinard , ;; Greg McGary , @@ -154,7 +154,7 @@ 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 + (with-temp-buffer (let* ((coding-system-for-read 'no-conversion) (charset (or (po-find-charset filename) "ascii")) (charset-upper (upcase charset)) diff --git a/gettext-tools/emacs/po-mode.el b/gettext-tools/emacs/po-mode.el index 78e8d11be..6416037c5 100644 --- a/gettext-tools/emacs/po-mode.el +++ b/gettext-tools/emacs/po-mode.el @@ -62,7 +62,7 @@ ;;; Code: -(defconst po-mode-version-string "2.28" "\ +(defconst po-mode-version-string "2.29" "\ Version number of this version of po-mode.el.") ;;; Emacs portability matters - part I. @@ -486,70 +486,6 @@ or remove the -m if you are not using the GNU version of 'uuencode'." ;;; 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)))))))) - -;; Handle missing 'kill-new' function. -(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))))) - ;; Handle portable highlighting. Code has been adapted (OK... stolen! :-) ;; from 'ispell.el'. @@ -1023,8 +959,7 @@ all reachable through 'M-x customize', in group 'Emacs.Editing.I18n.Po'." (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)) + (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) @@ -1106,7 +1041,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 +1185,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 +1640,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 +1674,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 +1754,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 +1775,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 +1789,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 +1843,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 +1867,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 +1885,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 +1899,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") @@ -2274,9 +2207,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 +2476,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 @@ -2679,7 +2611,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. @@ -2825,7 +2757,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 +2883,8 @@ 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 +2937,8 @@ 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 +2996,8 @@ 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 +3093,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." @@ -3211,7 +3143,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 @@ -3260,8 +3192,8 @@ Leave point after marked string." (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))) + (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 +3203,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 +3215,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 +3238,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."