aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2004-09-09 20:48:12 +0000
committerKim F. Storm2004-09-09 20:48:12 +0000
commit18d1e6c9fd4d8d446329ceb48a83ddca373f72c0 (patch)
treeb48750768b5d762c1c0a6c53777d4b4e391c2da4
parent340db502fa63af19824db898fec3fd7c6ba5ce0c (diff)
downloademacs-18d1e6c9fd4d8d446329ceb48a83ddca373f72c0.tar.gz
emacs-18d1e6c9fd4d8d446329ceb48a83ddca373f72c0.zip
(kmacro-bind-to-key): Associate dedicated macro
counter and format with binding. (kmacro-name-last-macro): New defun. Like name-last-kbd-macro, but the declared macro uses own macro counter and format. Give symbol kmacro property. (kmacro-keymap): Bind kmacro-name-last-macro to n. (kmacro-start-macro, kmacro-end-macro, kmacro-call-macro) (kmacro-end-and-call-macro): Doc fix.
-rw-r--r--lisp/kmacro.el47
1 files changed, 39 insertions, 8 deletions
diff --git a/lisp/kmacro.el b/lisp/kmacro.el
index a129ab53cef..9e3271d01cc 100644
--- a/lisp/kmacro.el
+++ b/lisp/kmacro.el
@@ -204,7 +204,7 @@ macro to be executed before appending to it."
204 204
205 ;; naming and binding 205 ;; naming and binding
206 (define-key map "b" 'kmacro-bind-to-key) 206 (define-key map "b" 'kmacro-bind-to-key)
207 (define-key map "n" 'name-last-kbd-macro) 207 (define-key map "n" 'kmacro-name-last-macro)
208 map) 208 map)
209 "Keymap for keyboard macro commands.") 209 "Keymap for keyboard macro commands.")
210(defalias 'kmacro-keymap kmacro-keymap) 210(defalias 'kmacro-keymap kmacro-keymap)
@@ -539,8 +539,8 @@ Displays the selected macro in the echo area."
539The commands are recorded even as they are executed. 539The commands are recorded even as they are executed.
540Use \\[kmacro-end-macro] to finish recording and make the macro available. 540Use \\[kmacro-end-macro] to finish recording and make the macro available.
541Use \\[kmacro-end-and-call-macro] to execute the macro. 541Use \\[kmacro-end-and-call-macro] to execute the macro.
542Use \\[name-last-kbd-macro] to give it a permanent name. 542
543Non-nil arg (prefix arg) means append to last macro defined; 543Non-nil arg (prefix arg) means append to last macro defined.
544 544
545With \\[universal-argument] prefix, append to last keyboard macro 545With \\[universal-argument] prefix, append to last keyboard macro
546defined. Depending on `kmacro-execute-before-append', this may begin 546defined. Depending on `kmacro-execute-before-append', this may begin
@@ -551,7 +551,10 @@ defining the macro.
551 551
552Use \\[kmacro-insert-counter] to insert (and increment) the macro counter. 552Use \\[kmacro-insert-counter] to insert (and increment) the macro counter.
553The counter value can be set or modified via \\[kmacro-set-counter] and \\[kmacro-add-counter]. 553The counter value can be set or modified via \\[kmacro-set-counter] and \\[kmacro-add-counter].
554The format of the counter can be modified via \\[kmacro-set-format]." 554The format of the counter can be modified via \\[kmacro-set-format].
555
556Use \\[kmacro-name-last-macro] to give it a permanent name.
557Use \\[kmacro-bind-to-key] to bind it to a key sequence."
555 (interactive "P") 558 (interactive "P")
556 (if (or defining-kbd-macro executing-kbd-macro) 559 (if (or defining-kbd-macro executing-kbd-macro)
557 (message "Already defining keyboard macro.") 560 (message "Already defining keyboard macro.")
@@ -585,7 +588,7 @@ The format of the counter can be modified via \\[kmacro-set-format]."
585 "Finish defining a keyboard macro. 588 "Finish defining a keyboard macro.
586The definition was started by \\[kmacro-start-macro]. 589The definition was started by \\[kmacro-start-macro].
587The macro is now available for use via \\[kmacro-call-macro], 590The macro is now available for use via \\[kmacro-call-macro],
588or it can be given a name with \\[name-last-kbd-macro] and then invoked 591or it can be given a name with \\[kmacro-name-last-macro] and then invoked
589under that name. 592under that name.
590 593
591With numeric arg, repeat macro now that many times, 594With numeric arg, repeat macro now that many times,
@@ -609,7 +612,7 @@ command. See `kmacro-call-repeat-key' and `kmacro-call-repeat-with-arg'
609for details on how to adjust or disable this behaviour. 612for details on how to adjust or disable this behaviour.
610 613
611To make a macro permanent so you can call it even after defining 614To make a macro permanent so you can call it even after defining
612others, use \\[name-last-kbd-macro]." 615others, use \\[kmacro-name-last-macro]."
613 (interactive "p") 616 (interactive "p")
614 (let ((repeat-key (and (null no-repeat) 617 (let ((repeat-key (and (null no-repeat)
615 (> (length (this-single-command-keys)) 1) 618 (> (length (this-single-command-keys)) 1)
@@ -707,7 +710,7 @@ With numeric prefix ARG, repeat macro that many times.
707Zero argument means repeat until there is an error. 710Zero argument means repeat until there is an error.
708 711
709To give a macro a permanent name, so you can call it 712To give a macro a permanent name, so you can call it
710even after defining other macros, use \\[name-last-kbd-macro]." 713even after defining other macros, use \\[kmacro-name-last-macro]."
711 (interactive "P") 714 (interactive "P")
712 (if defining-kbd-macro 715 (if defining-kbd-macro
713 (kmacro-end-macro nil)) 716 (kmacro-end-macro nil))
@@ -771,10 +774,38 @@ may be shaded by a local key binding."
771 (yes-or-no-p (format "%s runs command %S. Bind anyway? " 774 (yes-or-no-p (format "%s runs command %S. Bind anyway? "
772 (format-kbd-macro key-seq) 775 (format-kbd-macro key-seq)
773 cmd)))) 776 cmd))))
774 (define-key global-map key-seq last-kbd-macro) 777 (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)))
775 (message "Keyboard macro bound to %s" (format-kbd-macro key-seq)))))) 782 (message "Keyboard macro bound to %s" (format-kbd-macro key-seq))))))
776 783
777 784
785(defun kmacro-name-last-macro (symbol)
786 "Assign a name to the last keyboard macro defined.
787Argument SYMBOL is the name to define.
788The symbol's function definition becomes the keyboard macro string.
789Such 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
778(defun kmacro-view-macro (&optional arg) 809(defun kmacro-view-macro (&optional arg)
779 "Display the last keyboard macro. 810 "Display the last keyboard macro.
780If repeated, it shows previous elements in the macro ring." 811If repeated, it shows previous elements in the macro ring."