|
|
1.1 root 1: ;; Non-primitive commands for keyboard macros.
2: ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
3:
4: ;; This file is part of GNU Emacs.
5:
6: ;; GNU Emacs is distributed in the hope that it will be useful,
7: ;; but WITHOUT ANY WARRANTY. No author or distributor
8: ;; accepts responsibility to anyone for the consequences of using it
9: ;; or for whether it serves any particular purpose or works at all,
10: ;; unless he says so in writing. Refer to the GNU Emacs General Public
11: ;; License for full details.
12:
13: ;; Everyone is granted permission to copy, modify and redistribute
14: ;; GNU Emacs, but only under the conditions described in the
15: ;; GNU Emacs General Public License. A copy of this license is
16: ;; supposed to have been given to you along with GNU Emacs so you
17: ;; can know your rights and responsibilities. It should be in a
18: ;; file named COPYING. Among other things, the copyright notice
19: ;; and this notice must be preserved on all copies.
20:
21:
22: (defun name-last-kbd-macro (symbol)
23: "Assign a name to the last keyboard macro defined.
24: One arg, a symbol, which is the name to define.
25: The symbol's function definition becomes the keyboard macro string.
26: Such a \"function\" cannot be called from Lisp, but it is a valid command
27: definition for the editor command loop."
28: (interactive "SName for last kbd macro: ")
29: (or last-kbd-macro
30: (error "No keyboard macro defined"))
31: (and (fboundp symbol)
32: (not (stringp (symbol-function symbol)))
33: (error "Function %s is already defined and not a keyboard macro."
34: symbol))
35: (fset symbol last-kbd-macro))
36:
37: (defun insert-kbd-macro (macroname &optional keys)
38: "Insert in buffer the definition of kbd macro NAME, as Lisp code.
39: Second argument KEYS non-nil means also record the keys it is on.
40: (This is the prefix argument, when calling interactively.)
41:
42: This Lisp code will, when executed, define the kbd macro with the
43: same definition it has now. If you say to record the keys,
44: the Lisp code will also rebind those keys to the macro.
45: Only global key bindings are recorded since executing this Lisp code
46: always makes global bindings.
47:
48: To save a kbd macro, visit a file of Lisp code such as your ~/.emacs,
49: use this command, and then save the file."
50: (interactive "CInsert kbd macro (name): \nP")
51: (insert "(fset '")
52: (prin1 macroname (current-buffer))
53: (insert "\n ")
54: (prin1 (symbol-function macroname) (current-buffer))
55: (insert ")\n")
56: (if keys
57: (let ((keys (where-is-internal macroname nil)))
58: (while keys
59: (insert "(global-set-key ")
60: (prin1 (car keys) (current-buffer))
61: (insert " '")
62: (prin1 macroname (current-buffer))
63: (insert ")\n")
64: (setq keys (cdr keys))))))
65:
66: (defun kbd-macro-query (flag)
67: "Query user during kbd macro execution.
68: With prefix argument, enters recursive edit,
69: reading keyboard commands even within a kbd macro.
70: You can give different commands each time the macro executes.
71: Without prefix argument, reads a character. Your options are:
72: Space -- execute the rest of the macro.
73: DEL -- skip the rest of the macro; start next repetition.
74: C-d -- skip rest of the macro and don't repeat it any more.
75: C-r -- enter a recursive edit, then on exit ask again for a character
76: C-l -- redisplay screen and ask again."
77: (interactive "P")
78: (or executing-macro
79: defining-kbd-macro
80: (error "Not defining or executing kbd macro"))
81: (if flag
82: (let (executing-macro defining-kbd-macro)
83: (recursive-edit))
84: (if (not executing-macro)
85: nil
86: (let ((loop t))
87: (while loop
88: (let ((char (let ((executing-macro nil)
89: (defining-kbd-macro nil))
90: (message "Proceed with macro? (Space, DEL, C-d, C-r or C-l) ")
91: (read-char))))
92: (cond ((= char ? )
93: (setq loop nil))
94: ((= char ?\177)
95: (setq loop nil)
96: (setq executing-macro ""))
97: ((= char ?\C-d)
98: (setq loop nil)
99: (setq executing-macro t))
100: ((= char ?\C-l)
101: (recenter nil))
102: ((= char ?\C-r)
103: (let (executing-macro defining-kbd-macro)
104: (recursive-edit))))))))))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.