]> code.delx.au - gnu-emacs/blobdiff - lisp/kmacro.el
(popup-dialog-box): Don't quote nil and t in docstrings.
[gnu-emacs] / lisp / kmacro.el
index e4388964423f21341c9470329a4e02a2679252fb..a4cb27f5280088b9e06a54e26a5c0c22ad9963c1 100644 (file)
@@ -94,7 +94,7 @@
 ;; and you can set the macro counter format with C-x C-k C-f.
 
 ;; The following key bindings are performed:
-;; 
+;;
 ;;           Normal                         While defining macro
 ;;           ---------------------------    ------------------------------
 ;;  f3       Define macro                   Insert current counter value
 ;;           counter value (default 0)      (default increment: 1)
 ;;
 ;;  C-u f3   APPENDs to last macro
-;; 
-;;  f4       Call last macro                End macro 
+;;
+;;  f4       Call last macro                End macro
 ;;           Prefix arg specifies number
 ;;           of times to execute macro.
 ;;
 ;;  C-u f4   Swap last and head of macro ring.
-;; 
+;;
 ;;  S-mouse-3  Set point at click and       End macro and execute macro at
 ;;             execute last macro.          click.
 
@@ -174,7 +174,7 @@ macro to be executed before appending to it."
 
 (defvar kmacro-keymap
   (let ((map (make-sparse-keymap)))
-    (define-key map "\C-s" 'kmacro-start-macro)
+    (define-key map "s"    'kmacro-start-macro)
     (define-key map "\C-k" 'kmacro-end-or-call-macro-repeat)
     (define-key map "\C-e" 'kmacro-edit-macro-repeat)
     (define-key map "\r"   'kmacro-edit-macro)
@@ -190,7 +190,7 @@ macro to be executed before appending to it."
     (define-key map "\C-f" 'kmacro-set-format)
     (define-key map "\C-c" 'kmacro-set-counter)
     (define-key map "\C-t" 'kmacro-swap-ring)
-    (define-key map "\C-b" 'kmacro-bind-to-key)
+    (define-key map "b"    'kmacro-bind-to-key)
     (define-key map "\C-d" 'kmacro-delete-ring-head)
     ;; Compatibility bindings
     (define-key map "q"    'kbd-macro-query)
@@ -339,7 +339,7 @@ Non-nil arg RAW means just return raw first element."
 Non-nil arg RAW means just return raw first element."
   (unless (kmacro-ring-empty-p)
     (kmacro-pop-ring1 raw)))
-      
+
 
 (defun kmacro-ring-length ()
   "Return length of macro ring, including pseudo head."
@@ -368,7 +368,7 @@ Check only `last-kbd-macro' if optional arg NONE is non-nil."
             (m (format-kbd-macro macro))
             (l (length m))
             (z (and nil trunc (> l x))))
-       (message (format "%s: %s%s" (or descr "Macro") 
+       (message (format "%s: %s%s" (or descr "Macro")
                         (if z (substring m 0 (1- x)) m) (if z "..." ""))))
     (message (or empty "No keyboard macros defined"))))
 
@@ -439,7 +439,7 @@ Check only `last-kbd-macro' if optional arg NONE is non-nil."
     (kmacro-display (car (car kmacro-ring)) "2nd macro")))
 
 
-  
+
 (defun kmacro-cycle-ring-next (&optional arg)
   "Move to next keyboard macro in keyboard macro ring.
 Displays the selected macro in the echo area."
@@ -500,13 +500,13 @@ Displays the selected macro in the echo area."
 
 ;;; Traditional bindings:
 
-  
+
 ;;;###autoload
 (defun kmacro-start-macro (arg)
   "Record subsequent keyboard input, defining a keyboard macro.
 The commands are recorded even as they are executed.
 Use \\[kmacro-end-macro] to finish recording and make the macro available.
-Use \\[call-last-kbd-macro] to execute the macro.
+Use \\[kmacro-end-and-call-macro] to execute the macro.
 Use \\[name-last-kbd-macro] to give it a permanent name.
 Non-nil arg (prefix arg) means append to last macro defined;
 
@@ -527,7 +527,7 @@ The format of the counter can be modified via \\[kmacro-set-format]."
       (unless append
        (if last-kbd-macro
            (let ((len (length kmacro-ring)))
-             (setq kmacro-ring 
+             (setq kmacro-ring
                    (cons
                     (list last-kbd-macro kmacro-counter kmacro-counter-format-start)
                     kmacro-ring))
@@ -538,7 +538,7 @@ The format of the counter can be modified via \\[kmacro-set-format]."
              kmacro-last-counter kmacro-counter
              kmacro-counter-format-start kmacro-counter-format))
 
-      (start-kbd-macro append 
+      (start-kbd-macro append
                       (and append
                            (if kmacro-execute-before-append
                                (> (car arg) 4)
@@ -583,20 +583,25 @@ others, use M-x name-last-kbd-macro."
     (if end-macro
        (kmacro-end-macro arg)
       (call-last-kbd-macro arg #'kmacro-loop-setup-function))
+    (when (consp arg)
+      (setq arg (car arg)))
     (when (and (or (null arg) (> arg 0))
               (setq repeat-key
-                    (if (eq kmacro-call-repeat-key t) repeat-key kmacro-call-repeat-key)))
+                    (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
-       (message "Repeat macro %swith `%s'..." 
+       (message "(Type %s to repeat macro%s)"
+                repeat-key-str
                 (if (and kmacro-call-repeat-with-arg
                          arg (> arg 1))
-                    (format "%d times " arg) "")
-                repeat-key-str)
+                    (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)
+             (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
@@ -635,7 +640,7 @@ The format of the counter can be modified via \\[kmacro-set-format]."
 With numeric prefix ARG, repeat macro that many times.
 With \\[universal-argument], call second macro in macro ring."
   (interactive "P")
-  (cond 
+  (cond
    (defining-kbd-macro
      (if kmacro-call-repeat-key
         (kmacro-call-macro arg no-repeat t)
@@ -660,7 +665,11 @@ With \\[universal-argument], call second macro in macro ring."
 ;;;###autoload
 (defun kmacro-end-and-call-macro (arg &optional no-repeat)
   "Call last keyboard macro, ending it first if currently being defined.
-With numeric prefix ARG, repeat macro that many times."
+With numeric prefix ARG, repeat macro that many times.
+Zero argument means repeat until there is an error.
+
+To give a macro a permanent name, so you can call it
+even after defining other macros, use \\[name-last-kbd-macro]."
   (interactive "P")
   (if defining-kbd-macro
       (kmacro-end-macro nil))
@@ -747,9 +756,8 @@ If kbd macro currently being defined end it before activating it."
 (defvar kmacro-step-edit-map (make-sparse-keymap)
   "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-1', `insert', `append-1', 
-`append', `replace-1', `replace', `act-repeat', `skip-rest',
-`skip-keep'.")
+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',
@@ -765,12 +773,13 @@ following additional answers: `insert-1', `insert', `append-1',
 (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-1)
+(define-key kmacro-step-edit-map "A" 'append-end)
 
 (defvar kmacro-step-edit-prefix-commands
   '(universal-argument universal-argument-more universal-argument-minus
@@ -791,7 +800,7 @@ following additional answers: `insert-1', `insert', `append-1',
              (format "Macro: %s%s%s%s%s\n"
                      (format-kbd-macro kmacro-step-edit-new-macro 1)
                      (if (and kmacro-step-edit-new-macro (> (length kmacro-step-edit-new-macro) 0)) " " "")
-                     (propertize (if keys (format-kbd-macro keys) 
+                     (propertize (if keys (format-kbd-macro keys)
                                    (if kmacro-step-edit-appending "<APPEND>" "<INSERT>")) 'face 'region)
                      (if future " " "")
                      (if future (format-kbd-macro future) ""))
@@ -808,22 +817,23 @@ following additional answers: `insert-1', `insert', `append-1',
                        curmsg))
               (t ""))
              (if keys
-                 (format "%s\n%s%s %S [yn iIaArR C-k kq!] " 
+                 (format "%s\n%s%s %S [yn iIaArR C-k kq!] "
                          (propertize "\
 --------------Step Edit Keyboard Macro  [?: help]---------------" 'face 'mode-line)
                          (if kmacro-step-edit-help "\
  Step: y/SPC: execute next,  d/n/DEL: skip next,  f: skip but keep
        TAB: execute while same,  ?: toggle help
- Edit: i: insert,  a: append,  r: replace, I/A/R: one sequence
+ Edit: i: insert,  r: replace,  a: append,  A: append at end,
+       I/R: insert/replace with one sequence,
  End:  !/c: execute rest,  C-k: skip rest and save,  q/C-g: quit
 ----------------------------------------------------------------
 " "")
                          (propertize "Next command:" 'face 'bold)
                          this-command)
-               (propertize 
+               (propertize
                 (format "Type key sequence%s to insert and execute%s: "
                         (if (numberp kmacro-step-edit-inserting) ""  "s")
-                        (if (numberp kmacro-step-edit-inserting) ""  "[end with C-j]"))
+                        (if (numberp kmacro-step-edit-inserting) ""  " (end with C-j)"))
                 'face 'bold))))))
 
 (defun kmacro-step-edit-query ()
@@ -858,7 +868,7 @@ following additional answers: `insert-1', `insert', `append-1',
          (clear-this-command-keys) ;; recent-keys actually
          (let (unread-command-events)
            (quoted-insert (prefix-numeric-value current-prefix-arg))
-           (setq kmacro-step-edit-new-macro 
+           (setq kmacro-step-edit-new-macro
                  (vconcat kmacro-step-edit-new-macro (recent-keys)))
            (when unread-command-events
              (setq kmacro-step-edit-new-macro
@@ -912,7 +922,7 @@ following additional answers: `insert-1', `insert', `append-1',
        ((eq act 'skip-rest)
        (setq kmacro-step-edit-active 'ignore)
        nil)
-       ((eq act 'automatic)
+       ((memq act '(automatic exit))
        (setq kmacro-step-edit-active nil)
        (setq act t)
        t)
@@ -927,12 +937,20 @@ following additional answers: `insert-1', `insert', `append-1',
            (setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
                  kmacro-step-edit-appending t))
        nil)
-       ((member act '(append-1 append))
-       (setq kmacro-step-edit-inserting (if (eq act 'append-1) 1 t))
+       ((eq act 'append)
+       (setq kmacro-step-edit-inserting t)
        (if (= executing-macro-index (length executing-kbd-macro))
            (setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
                  kmacro-step-edit-appending t))
        t)
+       ((eq act 'append-end)
+       (if (= executing-macro-index (length executing-kbd-macro))
+           (setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
+                 kmacro-step-edit-inserting t
+                 kmacro-step-edit-appending t)
+         (setq kmacro-step-edit-active 'append-end))
+       (setq act t)
+       t)
        ((eq act 'help)
        (setq executing-macro-index (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index))
        (setq kmacro-step-edit-help (not kmacro-step-edit-help))
@@ -943,7 +961,7 @@ following additional answers: `insert-1', `insert', `append-1',
       (if (> executing-macro-index (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index))
          (setq kmacro-step-edit-new-macro
                (vconcat kmacro-step-edit-new-macro
-                        (substring executing-kbd-macro 
+                        (substring executing-kbd-macro
                                    (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index)
                                    (if (eq act t) nil executing-macro-index)))
                kmacro-step-edit-prefix-index nil))
@@ -1026,6 +1044,12 @@ following additional answers: `insert-1', `insert', `append-1',
     (cond
      ((eq kmacro-step-edit-active 'ignore)
       (setq this-command 'ignore))
+     ((eq kmacro-step-edit-active 'append-end)
+      (if (= executing-macro-index (length executing-kbd-macro))
+         (setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
+               kmacro-step-edit-inserting t
+               kmacro-step-edit-appending t
+               kmacro-step-edit-active t)))
      ((/= kmacro-step-edit-num-input-keys num-input-keys)
       (if kmacro-step-edit-inserting
          (kmacro-step-edit-insert)
@@ -1048,7 +1072,7 @@ following additional answers: `insert-1', `insert', `append-1',
     (add-hook 'pre-command-hook 'kmacro-step-edit-pre-command nil nil)
     (if kmacro-step-edit-key-index
        (setq executing-macro-index kmacro-step-edit-key-index)
-      (setq kmacro-step-edit-key-index executing-macro-index))))  
+      (setq kmacro-step-edit-key-index executing-macro-index))))
 
 
 (defun kmacro-step-edit-macro ()
@@ -1073,8 +1097,11 @@ To customize possible responses, change the \"bindings\" in `kmacro-step-edit-ma
     (add-hook 'post-command-hook 'kmacro-step-edit-post-command t)
     (add-hook 'minibuffer-setup-hook 'kmacro-step-edit-minibuf-setup t)
     (call-last-kbd-macro nil nil)
-    (if kmacro-step-edit-replace
-       (setq last-kbd-macro kmacro-step-edit-new-macro))))
+    (when (and kmacro-step-edit-replace
+              kmacro-step-edit-new-macro
+              (not (equal last-kbd-macro kmacro-step-edit-new-macro)))
+      (kmacro-push-ring)
+      (setq last-kbd-macro kmacro-step-edit-new-macro))))
 
 (provide 'kmacro)
 ;;; kmacro.el ends here