In Fset_window_configuration install revison of reverted fix.
[bpt/emacs.git] / lisp / kmacro.el
index 6f4bed3..6ecac2c 100644 (file)
@@ -1,6 +1,6 @@
 ;;; kmacro.el --- enhanced keyboard macros
 
-;; Copyright (C) 2002-2011  Free Software Foundation, Inc.
+;; Copyright (C) 2002-2012  Free Software Foundation, Inc.
 
 ;; Author: Kim F. Storm <storm@cua.dk>
 ;; Keywords: keyboard convenience
@@ -231,12 +231,12 @@ macro to be executed before appending to it."
 ;;; Keyboard macro counter
 
 (defvar kmacro-counter 0
-  "*Current keyboard macro counter.")
+  "Current keyboard macro counter.")
 
 (defvar kmacro-default-counter-format "%d")
 
 (defvar kmacro-counter-format "%d"
-  "*Current keyboard macro counter format.")
+  "Current keyboard macro counter format.")
 
 (defvar kmacro-counter-format-start kmacro-counter-format
   "Macro format at start of macro execution.")
@@ -479,7 +479,7 @@ without repeating the prefix."
     (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)
@@ -498,7 +498,7 @@ Displays the selected macro in the echo area."
 (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)
@@ -526,7 +526,7 @@ Displays the selected macro in the echo area."
     (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)
@@ -625,10 +625,11 @@ for details on how to adjust or disable this behavior.
 To make a macro permanent so you can call it even after defining
 others, use \\[kmacro-name-last-macro]."
   (interactive "p")
-  (let ((repeat-key (and (null no-repeat)
-                        (> (length (this-single-command-keys)) 1)
-                        last-input-event))
-       repeat-key-str)
+  (let ((repeat-key (and (or (and (null no-repeat)
+                                  (> (length (this-single-command-keys)) 1))
+                             ;; Used when we're in the process of repeating.
+                             (eq no-repeat 'repeating))
+                        last-input-event)))
     (if end-macro
        (kmacro-end-macro arg)
       (call-last-kbd-macro arg #'kmacro-loop-setup-function))
@@ -639,25 +640,23 @@ others, use \\[kmacro-name-last-macro]."
                     (if (eq kmacro-call-repeat-key t)
                         repeat-key
                       kmacro-call-repeat-key)))
-      (setq repeat-key-str (format-kbd-macro (vector repeat-key) nil))
-      (while repeat-key
-       ;; 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)
-             (call-last-kbd-macro (and kmacro-call-repeat-with-arg arg)
-                                  #'kmacro-loop-setup-function)
-             (setq last-input-event nil))
-         (setq repeat-key nil)))
-      (when last-input-event
-       (clear-this-command-keys t)
-       (setq unread-command-events (list last-input-event))))))
+      ;; Issue a hint to the user, if the echo area isn't in use.
+      (unless (current-message)
+       (message "(Type %s to repeat macro%s)"
+                (format-kbd-macro (vector repeat-key) nil)
+                (if (and kmacro-call-repeat-with-arg
+                         arg (> arg 1))
+                    (format " %d times" arg) "")))
+      ;; Can't use the `keep-pred' arg because this overlay keymap needs to be
+      ;; removed during the next run of the kmacro (i.e. we need to add&remove
+      ;; this overlay-map at each repetition).
+      (set-temporary-overlay-map
+       (let ((map (make-sparse-keymap)))
+         (define-key map (vector repeat-key)
+           `(lambda () (interactive)
+              (kmacro-call-macro ,(and kmacro-call-repeat-with-arg arg)
+                                 'repeating)))
+         map)))))
 
 
 ;;; Combined function key bindings:
@@ -747,7 +746,7 @@ If kbd macro currently being defined end it before activating it."
 ;; Create a separate keymap installed as a minor-mode keymap (e.g. in
 ;; the emulation-mode-map-alists) in which macro bindings are made
 ;; independent of any other bindings.  When first binding is made,
-;; the kemap is created, installed, and enabled.  Key seq. C-x C-k +
+;; the keymap is created, installed, and enabled.  Key seq. C-x C-k +
 ;; can then be used to toggle the use of this keymap on and off.
 ;; This means that it would be safe(r) to bind ordinary keys like
 ;; letters and digits, provided that we inhibit the keymap while
@@ -777,7 +776,7 @@ If kbd macro currently being defined end it before activating it."
        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
@@ -837,7 +836,7 @@ Such a \"function\" cannot be called from Lisp, but it is a valid editor command
   (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)
@@ -1020,7 +1019,7 @@ following additional answers: `insert', `insert-1', `replace', `replace-1',
          (setq executing-kbd-macro-index (- executing-kbd-macro-index (length unread-command-events))
                next-index executing-kbd-macro-index)))))
 
-    ;; Query the user; stop macro exection temporarily
+    ;; Query the user; stop macro execution temporarily.
     (let ((macro executing-kbd-macro)
          (executing-kbd-macro nil)
          (defining-kbd-macro nil))