;;; Code:
\f
-(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.
;;; 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'.
(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)
(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."
(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)
\f
(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))
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)
(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)
(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)
(interactive)
(po-find-span-of-entry)
(let ((string (po-get-msgstr-form)))
- (po-kill-new string)
+ (kill-new string)
string))
(defun po-kill-msgstr ()
(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)
(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))
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)
(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")
(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)))))
(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
(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.
(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.
(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
(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
(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)))))
(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."
(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
(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")))
(;; 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)
(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
(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."