Increment c-version to 5.32.2.
[bpt/emacs.git] / lisp / kmacro.el
index 09fb420..e47f571 100644 (file)
@@ -1,17 +1,16 @@
 ;;; kmacro.el --- enhanced keyboard macros
 
 ;;; kmacro.el --- enhanced keyboard macros
 
-;; Copyright (C) 2002, 2003, 2004, 2005, 2006,
-;;   2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2011  Free Software Foundation, Inc.
 
 ;; Author: Kim F. Storm <storm@cua.dk>
 ;; Keywords: keyboard convenience
 
 ;; This file is part of GNU Emacs.
 
 
 ;; Author: Kim F. Storm <storm@cua.dk>
 ;; Keywords: keyboard convenience
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; 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, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; Commentary:
 
@@ -41,7 +38,7 @@
 ;; you can give a numeric prefix argument specifying the number of
 ;; times to repeat the macro.  Macro execution automatically
 ;; terminates when point reaches the end of the buffer or if an error
 ;; you can give a numeric prefix argument specifying the number of
 ;; times to repeat the macro.  Macro execution automatically
 ;; terminates when point reaches the end of the buffer or if an error
-;; is signalled by ringing the bell.
+;; is signaled by ringing the bell.
 
 ;; When you define a macro with F3/F4, it is automatically added to
 ;; the head of the "keyboard macro ring", and F4 actually executes the
 
 ;; When you define a macro with F3/F4, it is automatically added to
 ;; the head of the "keyboard macro ring", and F4 actually executes the
@@ -255,8 +252,9 @@ macro to be executed before appending to it."
 
 
 (defun kmacro-insert-counter (arg)
 
 
 (defun kmacro-insert-counter (arg)
-  "Insert macro counter and increment with ARG or 1 if missing.
-With \\[universal-argument], insert previous `kmacro-counter' (but do not modify counter)."
+  "Insert macro counter, then increment it by ARG.
+Interactively, ARG defaults to 1.  With \\[universal-argument], insert
+previous `kmacro-counter', and do not modify counter."
   (interactive "P")
   (if kmacro-initial-counter-value
       (setq kmacro-counter kmacro-initial-counter-value
   (interactive "P")
   (if kmacro-initial-counter-value
       (setq kmacro-counter kmacro-initial-counter-value
@@ -404,7 +402,7 @@ Optional arg EMPTY is message to print if no macros are defined."
                   (format " [%s]"
                           (format kmacro-counter-format-start kmacro-counter)))
                 (if z (substring m 0 (1- x)) m) (if z "..." "")))
                   (format " [%s]"
                           (format kmacro-counter-format-start kmacro-counter)))
                 (if z (substring m 0 (1- x)) m) (if z "..." "")))
-    (message (or empty "No keyboard macros defined"))))
+    (message "%s" (or empty "No keyboard macros defined"))))
 
 
 (defun kmacro-repeat-on-last-key (keys)
 
 
 (defun kmacro-repeat-on-last-key (keys)
@@ -481,7 +479,7 @@ without repeating the prefix."
     (kmacro-display (car (car kmacro-ring)) "2nd macro")))
 
 
     (kmacro-display (car (car kmacro-ring)) "2nd macro")))
 
 
-(defun kmacro-cycle-ring-next (&optional arg)
+(defun kmacro-cycle-ring-next (&optional _arg)
   "Move to next keyboard macro in keyboard macro ring.
 Displays the selected macro in the echo area."
   (interactive)
   "Move to next keyboard macro in keyboard macro ring.
 Displays the selected macro in the echo area."
   (interactive)
@@ -500,7 +498,7 @@ Displays the selected macro in the echo area."
 (put 'kmacro-cycle-ring-next 'kmacro-repeat 'ring)
 
 
 (put 'kmacro-cycle-ring-next 'kmacro-repeat 'ring)
 
 
-(defun kmacro-cycle-ring-previous (&optional arg)
+(defun kmacro-cycle-ring-previous (&optional _arg)
   "Move to previous keyboard macro in keyboard macro ring.
 Displays the selected macro in the echo area."
   (interactive)
   "Move to previous keyboard macro in keyboard macro ring.
 Displays the selected macro in the echo area."
   (interactive)
@@ -528,7 +526,7 @@ Displays the selected macro in the echo area."
     (kmacro-display last-kbd-macro t)))
 
 
     (kmacro-display last-kbd-macro t)))
 
 
-(defun kmacro-delete-ring-head (&optional arg)
+(defun kmacro-delete-ring-head (&optional _arg)
   "Delete current macro from keyboard macro ring."
   (interactive)
   (unless (kmacro-ring-empty-p t)
   "Delete current macro from keyboard macro ring."
   (interactive)
   (unless (kmacro-ring-empty-p t)
@@ -607,8 +605,11 @@ An argument of zero means repeat until error."
   (unless executing-kbd-macro
     (end-kbd-macro arg #'kmacro-loop-setup-function)
     (when (and last-kbd-macro (= (length last-kbd-macro) 0))
   (unless executing-kbd-macro
     (end-kbd-macro arg #'kmacro-loop-setup-function)
     (when (and last-kbd-macro (= (length last-kbd-macro) 0))
+      (setq last-kbd-macro nil)
       (message "Ignore empty macro")
       (message "Ignore empty macro")
-      (kmacro-pop-ring))))
+      ;; Don't call `kmacro-ring-empty-p' to avoid its messages.
+      (while (and (null last-kbd-macro) kmacro-ring)
+       (kmacro-pop-ring1)))))
 
 
 ;;;###autoload
 
 
 ;;;###autoload
@@ -640,11 +641,13 @@ others, use \\[kmacro-name-last-macro]."
                       kmacro-call-repeat-key)))
       (setq repeat-key-str (format-kbd-macro (vector repeat-key) nil))
       (while repeat-key
                       kmacro-call-repeat-key)))
       (setq repeat-key-str (format-kbd-macro (vector repeat-key) nil))
       (while repeat-key
-       (message "(Type %s to repeat macro%s)"
-                repeat-key-str
-                (if (and kmacro-call-repeat-with-arg
-                         arg (> arg 1))
-                    (format " %d times" arg) ""))
+       ;; Issue a hint to the user, if the echo area isn't in use.
+       (unless (current-message)
+         (message "(Type %s to repeat macro%s)"
+                  repeat-key-str
+                  (if (and kmacro-call-repeat-with-arg
+                           arg (> arg 1))
+                      (format " %d times" arg) "")))
        (if (equal repeat-key (read-event))
            (progn
              (clear-this-command-keys t)
        (if (equal repeat-key (read-event))
            (progn
              (clear-this-command-keys t)
@@ -774,7 +777,7 @@ If kbd macro currently being defined end it before activating it."
        mac))
 
 
        mac))
 
 
-(defun kmacro-bind-to-key (arg)
+(defun kmacro-bind-to-key (_arg)
   "When not defining or executing a macro, offer to bind last macro to a key.
 The key sequences [C-x C-k 0] through [C-x C-k 9] and [C-x C-k A]
 through [C-x C-k Z] are reserved for user bindings, and to bind to
   "When not defining or executing a macro, offer to bind last macro to a key.
 The key sequences [C-x C-k 0] through [C-x C-k 9] and [C-x C-k A]
 through [C-x C-k Z] are reserved for user bindings, and to bind to
@@ -834,7 +837,7 @@ Such a \"function\" cannot be called from Lisp, but it is a valid editor command
   (put symbol 'kmacro t))
 
 
   (put symbol 'kmacro t))
 
 
-(defun kmacro-view-macro (&optional arg)
+(defun kmacro-view-macro (&optional _arg)
   "Display the last keyboard macro.
 If repeated, it shows previous elements in the macro ring."
   (interactive)
   "Display the last keyboard macro.
 If repeated, it shows previous elements in the macro ring."
   (interactive)
@@ -894,7 +897,7 @@ without repeating the prefix."
 
 
 (defun kmacro-edit-lossage ()
 
 
 (defun kmacro-edit-lossage ()
-  "Edit most recent 100 keystrokes as a keyboard macro."
+  "Edit most recent 300 keystrokes as a keyboard macro."
   (interactive)
   (kmacro-push-ring)
   (edit-kbd-macro "\C-hl"))
   (interactive)
   (kmacro-push-ring)
   (edit-kbd-macro "\C-hl"))
@@ -913,34 +916,35 @@ without repeating the prefix."
 (defvar kmacro-step-edit-help)          ;; kmacro step edit help enabled
 (defvar kmacro-step-edit-num-input-keys) ;; to ignore duplicate pre-command hook
 
 (defvar kmacro-step-edit-help)          ;; kmacro step edit help enabled
 (defvar kmacro-step-edit-num-input-keys) ;; to ignore duplicate pre-command hook
 
-(defvar kmacro-step-edit-map (make-sparse-keymap)
+(defvar kmacro-step-edit-map
+  (let ((map (make-sparse-keymap)))
+    ;; query-replace-map answers include: `act', `skip', `act-and-show',
+    ;; `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
+    ;; `automatic', `backup', `exit-prefix', and `help'.")
+    ;; Also: `quit', `edit-replacement'
+
+    (set-keymap-parent map query-replace-map)
+
+    (define-key map "\t" 'act-repeat)
+    (define-key map [tab] 'act-repeat)
+    (define-key map "\C-k" 'skip-rest)
+    (define-key map "c" 'automatic)
+    (define-key map "f" 'skip-keep)
+    (define-key map "q" 'quit)
+    (define-key map "d" 'skip)
+    (define-key map "\C-d" 'skip)
+    (define-key map "i" 'insert)
+    (define-key map "I" 'insert-1)
+    (define-key map "r" 'replace)
+    (define-key map "R" 'replace-1)
+    (define-key map "a" 'append)
+    (define-key map "A" 'append-end)
+    map)
   "Keymap that defines the responses to questions in `kmacro-step-edit-macro'.
 This keymap is an extension to the `query-replace-map', allowing the
 following additional answers: `insert', `insert-1', `replace', `replace-1',
 `append', `append-end', `act-repeat', `skip-end', `skip-keep'.")
 
   "Keymap that defines the responses to questions in `kmacro-step-edit-macro'.
 This keymap is an extension to the `query-replace-map', allowing the
 following additional answers: `insert', `insert-1', `replace', `replace-1',
 `append', `append-end', `act-repeat', `skip-end', `skip-keep'.")
 
-;; query-replace-map answers include: `act', `skip', `act-and-show',
-;; `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
-;; `automatic', `backup', `exit-prefix', and `help'.")
-;; Also: `quit', `edit-replacement'
-
-(set-keymap-parent kmacro-step-edit-map query-replace-map)
-
-(define-key kmacro-step-edit-map "\t" 'act-repeat)
-(define-key kmacro-step-edit-map [tab] 'act-repeat)
-(define-key kmacro-step-edit-map "\C-k" 'skip-rest)
-(define-key kmacro-step-edit-map "c" 'automatic)
-(define-key kmacro-step-edit-map "f" 'skip-keep)
-(define-key kmacro-step-edit-map "q" 'quit)
-(define-key kmacro-step-edit-map "d" 'skip)
-(define-key kmacro-step-edit-map "\C-d" 'skip)
-(define-key kmacro-step-edit-map "i" 'insert)
-(define-key kmacro-step-edit-map "I" 'insert-1)
-(define-key kmacro-step-edit-map "r" 'replace)
-(define-key kmacro-step-edit-map "R" 'replace-1)
-(define-key kmacro-step-edit-map "a" 'append)
-(define-key kmacro-step-edit-map "A" 'append-end)
-
 (defvar kmacro-step-edit-prefix-commands
   '(universal-argument universal-argument-more universal-argument-minus
                       digit-argument negative-argument)
 (defvar kmacro-step-edit-prefix-commands
   '(universal-argument universal-argument-more universal-argument-minus
                       digit-argument negative-argument)
@@ -1194,7 +1198,7 @@ following additional answers: `insert', `insert-1', `replace', `replace-1',
        (setq this-command 'ignore)
       (setq this-command cmd)
       (if (memq this-command '(self-insert-command digit-argument))
        (setq this-command 'ignore)
       (setq this-command cmd)
       (if (memq this-command '(self-insert-command digit-argument))
-         (setq last-command-char (aref keys (1- (length keys)))))
+         (setq last-command-event (aref keys (1- (length keys)))))
       (if keys
          (setq kmacro-step-edit-new-macro (vconcat kmacro-step-edit-new-macro keys))))
     (setq kmacro-step-edit-key-index next-index)))
       (if keys
          (setq kmacro-step-edit-new-macro (vconcat kmacro-step-edit-new-macro keys))))
     (setq kmacro-step-edit-key-index next-index)))
@@ -1266,5 +1270,4 @@ To customize possible responses, change the \"bindings\" in `kmacro-step-edit-ma
 
 (provide 'kmacro)
 
 
 (provide 'kmacro)
 
-;;; arch-tag: d3fe0b24-ae41-47de-a4d6-41a77d5559f0
 ;;; kmacro.el ends here
 ;;; kmacro.el ends here