Mercurial > emacs
comparison lisp/kmacro.el @ 57293:cf6524063a28
(kmacro-lambda-form, kmacro-extract-lambda): Add.
(kmacro-bind-to-key, kmacro-name-last-macro): Use kmacro-lambda-form.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Thu, 30 Sep 2004 13:27:45 +0000 |
parents | 778b22aae530 |
children | e12200cc9b00 58db929d96c6 |
comparison
equal
deleted
inserted
replaced
57292:00748c19ee41 | 57293:cf6524063a28 |
---|---|
738 ;; can then be used to toggle the use of this keymap on and off. | 738 ;; can then be used to toggle the use of this keymap on and off. |
739 ;; This means that it would be safe(r) to bind ordinary keys like | 739 ;; This means that it would be safe(r) to bind ordinary keys like |
740 ;; letters and digits, provided that we inhibit the keymap while | 740 ;; letters and digits, provided that we inhibit the keymap while |
741 ;; executing the macro later on (but that's controversial...) | 741 ;; executing the macro later on (but that's controversial...) |
742 | 742 |
743 (defun kmacro-lambda-form (mac &optional counter format) | |
744 "Create lambda form for macro bound to symbol or key." | |
745 (if counter | |
746 (setq mac (list mac counter format))) | |
747 `(lambda (&optional arg) | |
748 "Keyboard macro." | |
749 (interactive "p") | |
750 (kmacro-exec-ring-item ',mac arg))) | |
751 | |
752 (defun kmacro-extract-lambda (mac) | |
753 "Extract kmacro from a kmacro lambda form." | |
754 (and (consp mac) | |
755 (eq (car mac) 'lambda) | |
756 (setq mac (assoc 'kmacro-exec-ring-item mac)) | |
757 (consp (cdr mac)) | |
758 (consp (car (cdr mac))) | |
759 (consp (cdr (car (cdr mac)))) | |
760 (setq mac (car (cdr (car (cdr mac))))) | |
761 (listp mac) | |
762 (= (length mac) 3) | |
763 (arrayp (car mac)) | |
764 mac)) | |
765 | |
766 | |
743 (defun kmacro-bind-to-key (arg) | 767 (defun kmacro-bind-to-key (arg) |
744 "When not defining or executing a macro, offer to bind last macro to a key. | 768 "When not defining or executing a macro, offer to bind last macro to a key. |
745 The key sequences [C-x C-k 0] through [C-x C-k 9] and [C-x C-k A] | 769 The key sequences [C-x C-k 0] through [C-x C-k 9] and [C-x C-k A] |
746 through [C-x C-k Z] are reserved for user bindings, and to bind to | 770 through [C-x C-k Z] are reserved for user bindings, and to bind to |
747 one of these sequences, just enter the digit or letter, rather than | 771 one of these sequences, just enter the digit or letter, rather than |
773 (vectorp cmd) | 797 (vectorp cmd) |
774 (yes-or-no-p (format "%s runs command %S. Bind anyway? " | 798 (yes-or-no-p (format "%s runs command %S. Bind anyway? " |
775 (format-kbd-macro key-seq) | 799 (format-kbd-macro key-seq) |
776 cmd)))) | 800 cmd)))) |
777 (define-key global-map key-seq | 801 (define-key global-map key-seq |
778 `(lambda (&optional arg) | 802 (kmacro-lambda-form (kmacro-ring-head))) |
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)))))) | 803 (message "Keyboard macro bound to %s" (format-kbd-macro key-seq)))))) |
783 | 804 |
784 | 805 |
785 (defun kmacro-name-last-macro (symbol) | 806 (defun kmacro-name-last-macro (symbol) |
786 "Assign a name to the last keyboard macro defined. | 807 "Assign a name to the last keyboard macro defined. |
796 (not (vectorp (symbol-function symbol))) | 817 (not (vectorp (symbol-function symbol))) |
797 (error "Function %s is already defined and not a keyboard macro" | 818 (error "Function %s is already defined and not a keyboard macro" |
798 symbol)) | 819 symbol)) |
799 (if (string-equal symbol "") | 820 (if (string-equal symbol "") |
800 (error "No command name given")) | 821 (error "No command name given")) |
801 (fset symbol | 822 (fset symbol (kmacro-lambda-form (kmacro-ring-head))) |
802 `(lambda (&optional arg) | |
803 "Keyboard macro." | |
804 (interactive "p") | |
805 (kmacro-exec-ring-item ',(kmacro-ring-head) arg))) | |
806 (put symbol 'kmacro t)) | 823 (put symbol 'kmacro t)) |
807 | 824 |
808 | 825 |
809 (defun kmacro-view-macro (&optional arg) | 826 (defun kmacro-view-macro (&optional arg) |
810 "Display the last keyboard macro. | 827 "Display the last keyboard macro. |