204 |
|
|
205 |
;; naming and binding |
;; naming and binding |
206 |
(define-key map "b" 'kmacro-bind-to-key) |
(define-key map "b" 'kmacro-bind-to-key) |
207 |
(define-key map "n" 'name-last-kbd-macro) |
(define-key map "n" 'kmacro-name-last-macro) |
208 |
map) |
map) |
209 |
"Keymap for keyboard macro commands.") |
"Keymap for keyboard macro commands.") |
210 |
(defalias 'kmacro-keymap kmacro-keymap) |
(defalias 'kmacro-keymap kmacro-keymap) |
539 |
The commands are recorded even as they are executed. |
The commands are recorded even as they are executed. |
540 |
Use \\[kmacro-end-macro] to finish recording and make the macro available. |
Use \\[kmacro-end-macro] to finish recording and make the macro available. |
541 |
Use \\[kmacro-end-and-call-macro] to execute the macro. |
Use \\[kmacro-end-and-call-macro] to execute the macro. |
542 |
Use \\[name-last-kbd-macro] to give it a permanent name. |
|
543 |
Non-nil arg (prefix arg) means append to last macro defined; |
Non-nil arg (prefix arg) means append to last macro defined. |
544 |
|
|
545 |
With \\[universal-argument] prefix, append to last keyboard macro |
With \\[universal-argument] prefix, append to last keyboard macro |
546 |
defined. Depending on `kmacro-execute-before-append', this may begin |
defined. Depending on `kmacro-execute-before-append', this may begin |
551 |
|
|
552 |
Use \\[kmacro-insert-counter] to insert (and increment) the macro counter. |
Use \\[kmacro-insert-counter] to insert (and increment) the macro counter. |
553 |
The counter value can be set or modified via \\[kmacro-set-counter] and \\[kmacro-add-counter]. |
The counter value can be set or modified via \\[kmacro-set-counter] and \\[kmacro-add-counter]. |
554 |
The format of the counter can be modified via \\[kmacro-set-format]." |
The format of the counter can be modified via \\[kmacro-set-format]. |
555 |
|
|
556 |
|
Use \\[kmacro-name-last-macro] to give it a permanent name. |
557 |
|
Use \\[kmacro-bind-to-key] to bind it to a key sequence." |
558 |
(interactive "P") |
(interactive "P") |
559 |
(if (or defining-kbd-macro executing-kbd-macro) |
(if (or defining-kbd-macro executing-kbd-macro) |
560 |
(message "Already defining keyboard macro.") |
(message "Already defining keyboard macro.") |
588 |
"Finish defining a keyboard macro. |
"Finish defining a keyboard macro. |
589 |
The definition was started by \\[kmacro-start-macro]. |
The definition was started by \\[kmacro-start-macro]. |
590 |
The macro is now available for use via \\[kmacro-call-macro], |
The macro is now available for use via \\[kmacro-call-macro], |
591 |
or it can be given a name with \\[name-last-kbd-macro] and then invoked |
or it can be given a name with \\[kmacro-name-last-macro] and then invoked |
592 |
under that name. |
under that name. |
593 |
|
|
594 |
With numeric arg, repeat macro now that many times, |
With numeric arg, repeat macro now that many times, |
612 |
for details on how to adjust or disable this behaviour. |
for details on how to adjust or disable this behaviour. |
613 |
|
|
614 |
To make a macro permanent so you can call it even after defining |
To make a macro permanent so you can call it even after defining |
615 |
others, use \\[name-last-kbd-macro]." |
others, use \\[kmacro-name-last-macro]." |
616 |
(interactive "p") |
(interactive "p") |
617 |
(let ((repeat-key (and (null no-repeat) |
(let ((repeat-key (and (null no-repeat) |
618 |
(> (length (this-single-command-keys)) 1) |
(> (length (this-single-command-keys)) 1) |
710 |
Zero argument means repeat until there is an error. |
Zero argument means repeat until there is an error. |
711 |
|
|
712 |
To give a macro a permanent name, so you can call it |
To give a macro a permanent name, so you can call it |
713 |
even after defining other macros, use \\[name-last-kbd-macro]." |
even after defining other macros, use \\[kmacro-name-last-macro]." |
714 |
(interactive "P") |
(interactive "P") |
715 |
(if defining-kbd-macro |
(if defining-kbd-macro |
716 |
(kmacro-end-macro nil)) |
(kmacro-end-macro nil)) |
774 |
(yes-or-no-p (format "%s runs command %S. Bind anyway? " |
(yes-or-no-p (format "%s runs command %S. Bind anyway? " |
775 |
(format-kbd-macro key-seq) |
(format-kbd-macro key-seq) |
776 |
cmd)))) |
cmd)))) |
777 |
(define-key global-map key-seq last-kbd-macro) |
(define-key global-map key-seq |
778 |
|
`(lambda (&optional arg) |
779 |
|
"Keyboard macro." |
780 |
|
(interactive "p") |
781 |
|
(kmacro-exec-ring-item ',(kmacro-ring-head) arg))) |
782 |
(message "Keyboard macro bound to %s" (format-kbd-macro key-seq)))))) |
(message "Keyboard macro bound to %s" (format-kbd-macro key-seq)))))) |
783 |
|
|
784 |
|
|
785 |
|
(defun kmacro-name-last-macro (symbol) |
786 |
|
"Assign a name to the last keyboard macro defined. |
787 |
|
Argument SYMBOL is the name to define. |
788 |
|
The symbol's function definition becomes the keyboard macro string. |
789 |
|
Such a \"function\" cannot be called from Lisp, but it is a valid editor command." |
790 |
|
(interactive "SName for last kbd macro: ") |
791 |
|
(or last-kbd-macro |
792 |
|
(error "No keyboard macro defined")) |
793 |
|
(and (fboundp symbol) |
794 |
|
(not (get symbol 'kmacro)) |
795 |
|
(not (stringp (symbol-function symbol))) |
796 |
|
(not (vectorp (symbol-function symbol))) |
797 |
|
(error "Function %s is already defined and not a keyboard macro" |
798 |
|
symbol)) |
799 |
|
(if (string-equal symbol "") |
800 |
|
(error "No command name given")) |
801 |
|
(fset symbol |
802 |
|
`(lambda (&optional arg) |
803 |
|
"Keyboard macro." |
804 |
|
(interactive "p") |
805 |
|
(kmacro-exec-ring-item ',(kmacro-ring-head) arg))) |
806 |
|
(put symbol 'kmacro t)) |
807 |
|
|
808 |
|
|
809 |
(defun kmacro-view-macro (&optional arg) |
(defun kmacro-view-macro (&optional arg) |
810 |
"Display the last keyboard macro. |
"Display the last keyboard macro. |
811 |
If repeated, it shows previous elements in the macro ring." |
If repeated, it shows previous elements in the macro ring." |