X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/1259009aa17da6dc038afff96963f6d9bbd3b8e1..2200a8c91de23f9749d1b3c961c4f8bb3145ddfa:/lisp/kmacro.el diff --git a/lisp/kmacro.el b/lisp/kmacro.el index c8dd05f7c4..4f59c23996 100644 --- a/lisp/kmacro.el +++ b/lisp/kmacro.el @@ -1,6 +1,6 @@ ;;; kmacro.el --- enhanced keyboard macros -;; Copyright (C) 2002-2012 Free Software Foundation, Inc. +;; Copyright (C) 2002-2013 Free Software Foundation, Inc. ;; Author: Kim F. Storm ;; Keywords: keyboard convenience @@ -202,6 +202,7 @@ macro to be executed before appending to it." ;; naming and binding (define-key map "b" 'kmacro-bind-to-key) (define-key map "n" 'kmacro-name-last-macro) + (define-key map "x" 'kmacro-to-register) map) "Keymap for keyboard macro commands.") (defalias 'kmacro-keymap kmacro-keymap) @@ -231,12 +232,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.") @@ -613,9 +614,10 @@ An argument of zero means repeat until error." ;;;###autoload -(defun kmacro-call-macro (arg &optional no-repeat end-macro) - "Call the last keyboard macro that you defined with \\[kmacro-start-macro]. +(defun kmacro-call-macro (arg &optional no-repeat end-macro macro) + "Call the keyboard MACRO that you defined with \\[kmacro-start-macro]. A prefix argument serves as a repeat count. Zero means repeat until error. +MACRO defaults to `last-kbd-macro'. When you call the macro, you can call the macro again by repeating just the last key in the key sequence that you used to call this @@ -625,13 +627,15 @@ 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)) + (kmacro-end-macro arg) ; modifies last-kbd-macro + (let ((last-kbd-macro (or macro last-kbd-macro))) + (call-last-kbd-macro arg #'kmacro-loop-setup-function))) (when (consp arg) (setq arg (car arg))) (when (and (or (null arg) (> arg 0)) @@ -639,25 +643,25 @@ 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 must add and remove this map at each repetition). + (set-transient-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 nil ,(if end-macro + last-kbd-macro + (or macro last-kbd-macro))))) + map))))) ;;; Combined function key bindings: @@ -837,6 +841,25 @@ Such a \"function\" cannot be called from Lisp, but it is a valid editor command (put symbol 'kmacro t)) +(defun kmacro-execute-from-register (k) + (kmacro-call-macro current-prefix-arg nil nil k)) + +(defun kmacro-to-register (r) + "Store the last keyboard macro in register R." + (interactive + (progn + (or last-kbd-macro (error "No keyboard macro defined")) + (list (read-char "Save to register: ")))) + (set-register r (registerv-make + last-kbd-macro + :jump-func 'kmacro-execute-from-register + :print-func (lambda (k) + (princ (format "a keyboard macro:\n %s" + (format-kbd-macro k)))) + :insert-func (lambda (k) + (insert (format-kbd-macro k)))))) + + (defun kmacro-view-macro (&optional _arg) "Display the last keyboard macro. If repeated, it shows previous elements in the macro ring." @@ -1171,12 +1194,10 @@ following additional answers: `insert', `insert-1', `replace', `replace-1', (setq cmd 'ignore) nil) ((memq cmd kmacro-step-edit-prefix-commands) - (setq universal-argument-num-events 0) (reset-this-command-lengths) nil) ((eq cmd 'universal-argument-other-key) (setq kmacro-step-edit-action t) - (setq universal-argument-num-events 0) (reset-this-command-lengths) (if (numberp kmacro-step-edit-inserting) (setq kmacro-step-edit-inserting nil)) @@ -1191,7 +1212,6 @@ following additional answers: `insert', `insert-1', `replace', `replace-1', (setq kmacro-step-edit-prefix-index nil) (reset-this-command-lengths) (setq overriding-terminal-local-map nil) - (setq universal-argument-num-events nil) (setq next-index kmacro-step-edit-key-index) t) (t nil))