Mercurial > emacs
annotate lisp/edmacro.el @ 9453:67b759a9096d
menu-bar-lines fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 11 Oct 1994 20:17:52 +0000 |
parents | 712e13833ad8 |
children | 58ab3325da3b |
rev | line source |
---|---|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
1 ;;; edmacro.el --- keyboard macro editor |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
2 |
7300 | 3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
845 | 4 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
5 ;; Author: Dave Gillespie <daveg@synaptics.com> |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
6 ;; Maintainer: Dave Gillespie <daveg@synaptics.com> |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
7 ;; Version: 2.01 |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
8 ;; Keywords: abbrev |
109 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
109 | 15 ;; any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
26 ;;; Commentary: |
109 | 27 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
28 ;;; Usage: |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
29 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
30 ;; The `C-x C-k' (`edit-kbd-macro') command edits a keyboard macro |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
31 ;; in a special buffer. It prompts you to type a key sequence, |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
32 ;; which should be one of: |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
33 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
34 ;; * RET or `C-x e' (call-last-kbd-macro), to edit the most |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
35 ;; recently defined keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
36 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
37 ;; * `M-x' followed by a command name, to edit a named command |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
38 ;; whose definition is a keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
39 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
40 ;; * `C-h l' (view-lossage), to edit the 100 most recent keystrokes |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
41 ;; and install them as the "current" macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
42 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
43 ;; * any key sequence whose definition is a keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
44 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
45 ;; This file includes a version of `insert-kbd-macro' that uses the |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
46 ;; more readable format defined by these routines. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
47 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
48 ;; Also, the `read-kbd-macro' command parses the region as |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
49 ;; a keyboard macro, and installs it as the "current" macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
50 ;; This and `format-kbd-macro' can also be called directly as |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
51 ;; Lisp functions. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
52 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
53 ;; Type `C-h m', or see the documentation for `edmacro-mode' below, |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
54 ;; for information about the format of written keyboard macros. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
55 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
56 ;; `edit-kbd-macro' formats the macro with one command per line, |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
57 ;; including the command names as comments on the right. If the |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
58 ;; formatter gets confused about which keymap was used for the |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
59 ;; characters, the command-name comments will be wrong but that |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
60 ;; won't hurt anything. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
61 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
62 ;; With a prefix argument, `edit-kbd-macro' will format the |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
63 ;; macro in a more concise way that omits the comments. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
64 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
65 ;; This package requires GNU Emacs 19 or later, and daveg's CL |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
66 ;; package 2.02 or later. (CL 2.02 comes standard starting with |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
67 ;; Emacs 19.18.) This package does not work with Emacs 18 or |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
68 ;; Lucid Emacs. |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
69 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
70 ;;; Code: |
109 | 71 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
72 (require 'cl) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
73 |
109 | 74 ;;; The user-level commands for editing macros. |
75 | |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
76 ;;;###autoload (define-key ctl-x-map "\C-k" 'edit-kbd-macro) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
77 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
78 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
79 (defvar edmacro-eight-bits nil |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
80 "*Non-nil if edit-kbd-macro should leave 8-bit characters intact. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
81 Default nil means to write characters above \\177 in octal notation.") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
82 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
83 (defvar edmacro-mode-map nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
84 (unless edmacro-mode-map |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
85 (setq edmacro-mode-map (make-sparse-keymap)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
86 (define-key edmacro-mode-map "\C-c\C-c" 'edmacro-finish-edit) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
87 (define-key edmacro-mode-map "\C-c\C-q" 'edmacro-insert-key)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
88 |
258 | 89 ;;;###autoload |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
90 (defun edit-kbd-macro (keys &optional prefix finish-hook store-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
91 "Edit a keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
92 At the prompt, type any key sequence which is bound to a keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
93 Or, type `C-x e' or RET to edit the last keyboard macro, `C-h l' to edit |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
94 the last 100 keystrokes as a keyboard macro, or `M-x' to edit a macro by |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
95 its command name. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
96 With a prefix argument, format the macro in a more concise way." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
97 (interactive "kKeyboard macro to edit (C-x e, M-x, C-h l, or keys): \nP") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
98 (when keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
99 (let ((cmd (if (arrayp keys) (key-binding keys) keys)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
100 (mac nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
101 (cond (store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
102 (setq mac keys) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
103 (setq cmd nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
104 ((or (eq cmd 'call-last-kbd-macro) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
105 (member keys '("\r" [return]))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
106 (or last-kbd-macro |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
107 (y-or-n-p "No keyboard macro defined. Create one? ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
108 (keyboard-quit)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
109 (setq mac (or last-kbd-macro "")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
110 (setq cmd 'last-kbd-macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
111 ((eq cmd 'execute-extended-command) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
112 (setq cmd (read-command "Name of keyboard macro to edit: ")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
113 (setq mac (symbol-function cmd))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
114 ((eq cmd 'view-lossage) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
115 (setq mac (recent-keys)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
116 (setq cmd 'last-kbd-macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
117 ((symbolp cmd) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
118 (setq mac (symbol-function cmd))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
119 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
120 (setq mac cmd) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
121 (setq cmd nil))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
122 (unless (arrayp mac) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
123 (error "Not a keyboard macro: %s" cmd)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
124 (message "Formatting keyboard macro...") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
125 (let* ((oldbuf (current-buffer)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
126 (mmac (edmacro-fix-menu-commands mac)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
127 (fmt (edmacro-format-keys mmac 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
128 (fmtv (edmacro-format-keys mmac (not prefix))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
129 (buf (get-buffer-create "*Edit Macro*"))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
130 (message "Formatting keyboard macro...done") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
131 (switch-to-buffer buf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
132 (kill-all-local-variables) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
133 (use-local-map edmacro-mode-map) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
134 (setq buffer-read-only nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
135 (setq major-mode 'edmacro-mode) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
136 (setq mode-name "Edit Macro") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
137 (set (make-local-variable 'edmacro-original-buffer) oldbuf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
138 (set (make-local-variable 'edmacro-finish-hook) finish-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
139 (set (make-local-variable 'edmacro-store-hook) store-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
140 (erase-buffer) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
141 (insert ";; Keyboard Macro Editor. Press C-c C-c to finish; " |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
142 "press C-x k RET to cancel.\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
143 (insert ";; Original keys: " fmt "\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
144 (unless store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
145 (insert "\nCommand: " (if cmd (symbol-name cmd) "none") "\n") |
5772
daac61915408
(edit-kbd-macro, edmacro-finish-edit, insert-kbd-macro):
Richard M. Stallman <rms@gnu.org>
parents:
5307
diff
changeset
|
146 (let ((keys (where-is-internal (or cmd mac) '(keymap)))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
147 (if keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
148 (while keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
149 (insert "Key: " (edmacro-format-keys (pop keys) 1) "\n")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
150 (insert "Key: none\n")))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
151 (insert "\nMacro:\n\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
152 (save-excursion |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
153 (insert fmtv "\n")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
154 (recenter '(4)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
155 (when (eq mac mmac) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
156 (set-buffer-modified-p nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
157 (run-hooks 'edmacro-format-hook))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
158 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
159 ;;; The next two commands are provided for convenience and backward |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
160 ;;; compatibility. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
161 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
162 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
163 (defun edit-last-kbd-macro (&optional prefix) |
109 | 164 "Edit the most recently defined keyboard macro." |
165 (interactive "P") | |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
166 (edit-kbd-macro 'call-last-kbd-macro prefix)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
167 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
168 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
169 (defun edit-named-kbd-macro (&optional prefix) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
170 "Edit a keyboard macro which has been given a name by `name-last-kbd-macro'." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
171 (interactive "P") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
172 (edit-kbd-macro 'execute-extended-command prefix)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
173 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
174 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
175 (defun read-kbd-macro (start &optional end) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
176 "Read the region as a keyboard macro definition. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
177 The region is interpreted as spelled-out keystrokes, e.g., \"M-x abc RET\". |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
178 See documentation for `edmacro-mode' for details. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
179 Leading/trailing \"C-x (\" and \"C-x )\" in the text are allowed and ignored. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
180 The resulting macro is installed as the \"current\" keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
181 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
182 In Lisp, may also be called with a single STRING argument in which case |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
183 the result is returned rather than being installed as the current macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
184 The result will be a string if possible, otherwise an event vector. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
185 Second argument NEED-VECTOR means to return an event vector always." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
186 (interactive "r") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
187 (if (stringp start) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
188 (edmacro-parse-keys start end) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
189 (setq last-kbd-macro (edmacro-parse-keys (buffer-substring start end))))) |
109 | 190 |
258 | 191 ;;;###autoload |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
192 (defun format-kbd-macro (&optional macro verbose) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
193 "Return the keyboard macro MACRO as a human-readable string. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
194 This string is suitable for passing to `read-kbd-macro'. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
195 Second argument VERBOSE means to put one command per line with comments. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
196 If VERBOSE is `1', put everything on one line. If VERBOSE is omitted |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
197 or nil, use a compact 80-column format." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
198 (and macro (symbolp macro) (setq macro (symbol-function macro))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
199 (edmacro-format-keys (or macro last-kbd-macro) verbose)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
200 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
201 ;;; Commands for *Edit Macro* buffer. |
109 | 202 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
203 (defun edmacro-finish-edit () |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
204 (interactive) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
205 (unless (eq major-mode 'edmacro-mode) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
206 (error |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
207 "This command is valid only in buffers created by `edit-kbd-macro'")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
208 (run-hooks 'edmacro-finish-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
209 (let ((cmd nil) (keys nil) (no-keys nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
210 (top (point-min))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
211 (goto-char top) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
212 (let ((case-fold-search nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
213 (while (cond ((looking-at "[ \t]*\\($\\|;;\\|REM[ \t\n]\\)") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
214 t) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
215 ((looking-at "Command:[ \t]*\\([^ \t\n]*\\)[ \t]*$") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
216 (when edmacro-store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
217 (error "\"Command\" line not allowed in this context")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
218 (let ((str (buffer-substring (match-beginning 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
219 (match-end 1)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
220 (unless (equal str "") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
221 (setq cmd (and (not (equalp str "none")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
222 (intern str))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
223 (and (fboundp cmd) (not (arrayp (symbol-function cmd))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
224 (not (y-or-n-p |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
225 (format "Command %s is already defined; %s" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
226 cmd "proceed? "))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
227 (keyboard-quit)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
228 t) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
229 ((looking-at "Key:\\(.*\\)$") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
230 (when edmacro-store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
231 (error "\"Key\" line not allowed in this context")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
232 (let ((key (edmacro-parse-keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
233 (buffer-substring (match-beginning 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
234 (match-end 1))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
235 (unless (equal key "") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
236 (if (equalp key "none") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
237 (setq no-keys t) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
238 (push key keys) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
239 (let ((b (key-binding key))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
240 (and b (commandp b) (not (arrayp b)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
241 (or (not (fboundp b)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
242 (not (arrayp (symbol-function b)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
243 (not (y-or-n-p |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
244 (format "Key %s is already defined; %s" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
245 (edmacro-format-keys key 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
246 "proceed? "))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
247 (keyboard-quit)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
248 t) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
249 ((looking-at "Macro:[ \t\n]*") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
250 (goto-char (match-end 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
251 nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
252 ((eobp) nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
253 (t (error "Expected a `Macro:' line"))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
254 (forward-line 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
255 (setq top (point))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
256 (let* ((buf (current-buffer)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
257 (str (buffer-substring top (point-max))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
258 (modp (buffer-modified-p)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
259 (obuf edmacro-original-buffer) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
260 (store-hook edmacro-store-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
261 (finish-hook edmacro-finish-hook)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
262 (unless (or cmd keys store-hook (equal str "")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
263 (error "No command name or keys specified")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
264 (when modp |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
265 (when (buffer-name obuf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
266 (set-buffer obuf)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
267 (message "Compiling keyboard macro...") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
268 (let ((mac (edmacro-parse-keys str))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
269 (message "Compiling keyboard macro...done") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
270 (if store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
271 (funcall store-hook mac) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
272 (when (eq cmd 'last-kbd-macro) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
273 (setq last-kbd-macro (and (> (length mac) 0) mac)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
274 (setq cmd nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
275 (when cmd |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
276 (if (= (length mac) 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
277 (fmakunbound cmd) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
278 (fset cmd mac))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
279 (if no-keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
280 (when cmd |
5772
daac61915408
(edit-kbd-macro, edmacro-finish-edit, insert-kbd-macro):
Richard M. Stallman <rms@gnu.org>
parents:
5307
diff
changeset
|
281 (loop for key in (where-is-internal cmd '(keymap)) do |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
282 (global-unset-key key))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
283 (when keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
284 (if (= (length mac) 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
285 (loop for key in keys do (global-unset-key key)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
286 (loop for key in keys do |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
287 (global-set-key key (or cmd mac))))))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
288 (kill-buffer buf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
289 (when (buffer-name obuf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
290 (switch-to-buffer obuf)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
291 (when finish-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
292 (funcall finish-hook))))) |
109 | 293 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
294 (defun edmacro-insert-key (key) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
295 "Insert the written name of a key in the buffer." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
296 (interactive "kKey to insert: ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
297 (if (bolp) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
298 (insert (edmacro-format-keys key t) "\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
299 (insert (edmacro-format-keys key) " "))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
300 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
301 (defun edmacro-mode () |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
302 "\\<edmacro-mode-map>Keyboard Macro Editing mode. Press |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
303 \\[edmacro-finish-edit] to save and exit. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
304 To abort the edit, just kill this buffer with \\[kill-buffer] RET. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
305 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
306 Press \\[edmacro-insert-key] to insert the name of any key by typing the key. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
307 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
308 The editing buffer contains a \"Command:\" line and any number of |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
309 \"Key:\" lines at the top. These are followed by a \"Macro:\" line |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
310 and the macro itself as spelled-out keystrokes: `C-x C-f foo RET'. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
311 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
312 The \"Command:\" line specifies the command name to which the macro |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
313 is bound, or \"none\" for no command name. Write \"last-kbd-macro\" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
314 to refer to the current keyboard macro (as used by \\[call-last-kbd-macro]). |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
315 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
316 The \"Key:\" lines specify key sequences to which the macro is bound, |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
317 or \"none\" for no key bindings. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
318 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
319 You can edit these lines to change the places where the new macro |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
320 is stored. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
321 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
322 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
323 Format of keyboard macros during editing: |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
324 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
325 Text is divided into \"words\" separated by whitespace. Except for |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
326 the words described below, the characters of each word go directly |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
327 as characters of the macro. The whitespace that separates words |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
328 is ignored. Whitespace in the macro must be written explicitly, |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
329 as in \"foo SPC bar RET\". |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
330 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
331 * The special words RET, SPC, TAB, DEL, LFD, ESC, and NUL represent |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
332 special control characters. The words must be written in uppercase. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
333 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
334 * A word in angle brackets, e.g., <return>, <down>, or <f1>, represents |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
335 a function key. (Note that in the standard configuration, the |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
336 function key <return> and the control key RET are synonymous.) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
337 You can use angle brackets on the words RET, SPC, etc., but they |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
338 are not required there. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
339 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
340 * Keys can be written by their ASCII code, using a backslash followed |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
341 by up to six octal digits. This is the only way to represent keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
342 with codes above \\377. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
343 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
344 * One or more prefixes M- (meta), C- (control), S- (shift), A- (alt), |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
345 H- (hyper), and s- (super) may precede a character or key notation. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
346 For function keys, the prefixes may go inside or outside of the |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
347 brackets: C-<down> = <C-down>. The prefixes may be written in |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
348 any order: M-C-x = C-M-x. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
349 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
350 Prefixes are not allowed on multi-key words, e.g., C-abc, except |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
351 that the Meta prefix is allowed on a sequence of digits and optional |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
352 minus sign: M--123 = M-- M-1 M-2 M-3. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
353 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
354 * The `^' notation for control characters also works: ^M = C-m. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
355 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
356 * Double angle brackets enclose command names: <<next-line>> is |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
357 shorthand for M-x next-line RET. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
358 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
359 * Finally, REM or ;; causes the rest of the line to be ignored as a |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
360 comment. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
361 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
362 Any word may be prefixed by a multiplier in the form of a decimal |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
363 number and `*': 3*<right> = <right> <right> <right>, and |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
364 10*foo = foofoofoofoofoofoofoofoofoofoo. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
365 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
366 Multiple text keys can normally be strung together to form a word, |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
367 but you may need to add whitespace if the word would look like one |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
368 of the above notations: `; ; ;' is a keyboard macro with three |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
369 semicolons, but `;;;' is a comment. Likewise, `\\ 1 2 3' is four |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
370 keys but `\\123' is a single key written in octal, and `< right >' |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
371 is seven keys but `<right>' is a single function key. When in |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
372 doubt, use whitespace." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
373 (interactive) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
374 (error "This mode can be enabled only by `edit-kbd-macro'")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
375 (put 'edmacro-mode 'mode-class 'special) |
109 | 376 |
377 ;;; Formatting a keyboard macro as human-readable text. | |
378 | |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
379 (defun edmacro-format-keys (macro &optional verbose) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
380 (setq macro (edmacro-fix-menu-commands macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
381 (let* ((maps (append (current-minor-mode-maps) |
9199
712e13833ad8
(edmacro-format-keys): Cope if local keymap is nil.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
382 (if (current-local-map) |
712e13833ad8
(edmacro-format-keys): Cope if local keymap is nil.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
383 (list (current-local-map))) |
712e13833ad8
(edmacro-format-keys): Cope if local keymap is nil.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
384 (list (current-global-map)))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
385 (pkeys '(end-macro ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?- ?\C-u |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
386 ?\M-- ?\M-0 ?\M-1 ?\M-2 ?\M-3 ?\M-4 ?\M-5 ?\M-6 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
387 ?\M-7 ?\M-8 ?\M-9)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
388 (mdigs (nthcdr 13 pkeys)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
389 (maxkey (if edmacro-eight-bits 255 127)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
390 (case-fold-search nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
391 (res-words '("NUL" "TAB" "LFD" "RET" "ESC" "SPC" "DEL" "REM")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
392 (rest-mac (vconcat macro [end-macro])) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
393 (res "") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
394 (len 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
395 (one-line (eq verbose 1))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
396 (if one-line (setq verbose nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
397 (when (stringp macro) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
398 (loop for i below (length macro) do |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
399 (when (>= (aref rest-mac i) 128) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
400 (incf (aref rest-mac i) (- (lsh 1 23) 128))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
401 (while (not (eq (aref rest-mac 0) 'end-macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
402 (let* ((prefix |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
403 (or (and (integerp (aref rest-mac 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
404 (memq (aref rest-mac 0) mdigs) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
405 (memq (key-binding (subseq rest-mac 0 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
406 '(digit-argument negative-argument)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
407 (let ((i 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
408 (while (memq (aref rest-mac i) (cdr mdigs)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
409 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
410 (and (not (memq (aref rest-mac i) pkeys)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
411 (prog1 (concat "M-" (subseq rest-mac 0 i) " ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
412 (callf subseq rest-mac i))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
413 (and (eq (aref rest-mac 0) ?\C-u) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
414 (eq (key-binding [?\C-u]) 'universal-argument) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
415 (let ((i 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
416 (while (eq (aref rest-mac i) ?\C-u) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
417 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
418 (and (not (memq (aref rest-mac i) pkeys)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
419 (prog1 (loop repeat i concat "C-u ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
420 (callf subseq rest-mac i))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
421 (and (eq (aref rest-mac 0) ?\C-u) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
422 (eq (key-binding [?\C-u]) 'universal-argument) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
423 (let ((i 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
424 (when (eq (aref rest-mac i) ?-) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
425 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
426 (while (memq (aref rest-mac i) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
427 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
428 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
429 (and (not (memq (aref rest-mac i) pkeys)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
430 (prog1 (concat "C-u " (subseq rest-mac 1 i) " ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
431 (callf subseq rest-mac i))))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
432 (bind-len (apply 'max 1 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
433 (loop for map in maps |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
434 for b = (lookup-key map rest-mac) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
435 when b collect b))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
436 (key (subseq rest-mac 0 bind-len)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
437 (fkey nil) tlen tkey |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
438 (bind (or (loop for map in maps for b = (lookup-key map key) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
439 thereis (and (not (integerp b)) b)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
440 (and (setq fkey (lookup-key function-key-map rest-mac)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
441 (setq tlen fkey tkey (subseq rest-mac 0 tlen) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
442 fkey (lookup-key function-key-map tkey)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
443 (loop for map in maps |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
444 for b = (lookup-key map fkey) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
445 when (and (not (integerp b)) b) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
446 do (setq bind-len tlen key tkey) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
447 and return b |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
448 finally do (setq fkey nil))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
449 (first (aref key 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
450 (text (loop for i from bind-len below (length rest-mac) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
451 for ch = (aref rest-mac i) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
452 while (and (integerp ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
453 (> ch 32) (< ch maxkey) (/= ch 92) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
454 (eq (key-binding (char-to-string ch)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
455 'self-insert-command) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
456 (or (> i (- (length rest-mac) 2)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
457 (not (eq ch (aref rest-mac (+ i 1)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
458 (not (eq ch (aref rest-mac (+ i 2)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
459 finally return i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
460 desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
461 (if (stringp bind) (setq bind nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
462 (cond ((and (eq bind 'self-insert-command) (not prefix) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
463 (> text 1) (integerp first) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
464 (> first 32) (<= first maxkey) (/= first 92) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
465 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
466 (if (> text 30) (setq text 30)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
467 (setq desc (concat (subseq rest-mac 0 text))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
468 (when (string-match "^[ACHMsS]-." desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
469 (setq text 2) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
470 (callf substring desc 0 2)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
471 (not (string-match |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
472 "^;;\\|^<.*>$\\|^\\\\[0-9]+$\\|^[0-9]+\\*." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
473 desc)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
474 (when (or (string-match "^\\^.$" desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
475 (member desc res-words)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
476 (setq desc (mapconcat 'char-to-string desc " "))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
477 (when verbose |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
478 (setq bind (format "%s * %d" bind text))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
479 (setq bind-len text)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
480 ((and (eq bind 'execute-extended-command) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
481 (> text bind-len) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
482 (memq (aref rest-mac text) '(return 13)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
483 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
484 (setq desc (concat (subseq rest-mac bind-len text))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
485 (commandp (intern-soft desc)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
486 (if (commandp (intern-soft desc)) (setq bind desc)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
487 (setq desc (format "<<%s>>" desc)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
488 (setq bind-len (1+ text))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
489 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
490 (setq desc (mapconcat |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
491 (function |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
492 (lambda (ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
493 (cond |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
494 ((integerp ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
495 (concat |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
496 (loop for pf across "ACHMsS" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
497 for bit in '(18 22 20 23 19 21) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
498 when (/= (logand ch (lsh 1 bit)) 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
499 concat (format "%c-" pf)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
500 (let ((ch2 (logand ch (1- (lsh 1 18))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
501 (cond ((<= ch2 32) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
502 (case ch2 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
503 (0 "NUL") (9 "TAB") (10 "LFD") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
504 (13 "RET") (27 "ESC") (32 "SPC") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
505 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
506 (format "C-%c" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
507 (+ (if (<= ch2 26) 96 64) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
508 ch2))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
509 ((= ch2 127) "DEL") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
510 ((<= ch2 maxkey) (char-to-string ch2)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
511 (t (format "\\%o" ch2)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
512 ((symbolp ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
513 (format "<%s>" ch)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
514 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
515 (error "Unrecognized item in macro: %s" ch))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
516 (or fkey key) " ")))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
517 (if prefix (setq desc (concat prefix desc))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
518 (unless (string-match " " desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
519 (let ((times 1) (pos bind-len)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
520 (while (not (mismatch rest-mac rest-mac |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
521 :end1 bind-len :start2 pos |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
522 :end2 (+ bind-len pos))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
523 (incf times) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
524 (incf pos bind-len)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
525 (when (> times 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
526 (setq desc (format "%d*%s" times desc)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
527 (setq bind-len (* bind-len times))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
528 (setq rest-mac (subseq rest-mac bind-len)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
529 (if verbose |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
530 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
531 (unless (equal res "") (callf concat res "\n")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
532 (callf concat res desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
533 (when (and bind (or (stringp bind) (symbolp bind))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
534 (callf concat res |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
535 (make-string (max (- 3 (/ (length desc) 8)) 1) 9) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
536 ";; " (if (stringp bind) bind (symbol-name bind)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
537 (setq len 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
538 (if (and (> (+ len (length desc) 2) 72) (not one-line)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
539 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
540 (callf concat res "\n ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
541 (setq len 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
542 (unless (equal res "") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
543 (callf concat res " ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
544 (incf len))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
545 (callf concat res desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
546 (incf len (length desc))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
547 res)) |
109 | 548 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
549 (defun edmacro-fix-menu-commands (macro) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
550 (when (vectorp macro) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
551 (let ((i 0) ev) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
552 (while (< i (length macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
553 (when (consp (setq ev (aref macro i))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
554 (cond ((equal (cadadr ev) '(menu-bar)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
555 (setq macro (vconcat (subseq macro 0 i) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
556 (vector 'menu-bar (car ev)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
557 (subseq macro (1+ i)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
558 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
559 ;; It would be nice to do pop-up menus, too, but not enough |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
560 ;; info is recorded in macros to make this possible. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
561 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
562 (error "Macros with mouse clicks are not %s" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
563 "supported by this command")))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
564 (incf i)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
565 macro) |
109 | 566 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
567 ;;; Parsing a human-readable keyboard macro. |
109 | 568 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
569 (defun edmacro-parse-keys (string &optional need-vector) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
570 (let ((case-fold-search nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
571 (pos 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
572 (res [])) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
573 (while (and (< pos (length string)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
574 (string-match "[^ \t\n\f]+" string pos)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
575 (let ((word (substring string (match-beginning 0) (match-end 0))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
576 (key nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
577 (times 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
578 (setq pos (match-end 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
579 (when (string-match "\\([0-9]+\\)\\*." word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
580 (setq times (string-to-int (substring word 0 (match-end 1)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
581 (setq word (substring word (1+ (match-end 1))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
582 (cond ((string-match "^<<.+>>$" word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
583 (setq key (vconcat (if (eq (key-binding [?\M-x]) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
584 'execute-extended-command) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
585 [?\M-x] |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
586 (or (car (where-is-internal |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
587 'execute-extended-command)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
588 [?\M-x])) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
589 (substring word 2 -2) "\r"))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
590 ((and (string-match "^\\(\\([ACHMsS]-\\)*\\)<\\(.+\\)>$" word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
591 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
592 (setq word (concat (substring word (match-beginning 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
593 (match-end 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
594 (substring word (match-beginning 3) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
595 (match-end 3)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
596 (not (string-match |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
597 "\\<\\(NUL\\|RET\\|LFD\\|ESC\\|SPC\\|DEL\\)$" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
598 word)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
599 (setq key (list (intern word)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
600 ((or (equal word "REM") (string-match "^;;" word)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
601 (setq pos (string-match "$" string pos))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
602 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
603 (let ((orig-word word) (prefix 0) (bits 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
604 (while (string-match "^[ACHMsS]-." word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
605 (incf bits (lsh 1 (cdr (assq (aref word 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
606 '((?A . 18) (?C . 22) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
607 (?H . 20) (?M . 23) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
608 (?s . 19) (?S . 21)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
609 (incf prefix 2) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
610 (callf substring word 2)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
611 (when (string-match "^\\^.$" word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
612 (incf bits (lsh 1 22)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
613 (incf prefix) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
614 (callf substring word 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
615 (let ((found (assoc word '(("NUL" . "\0") ("RET" . "\r") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
616 ("LFD" . "\n") ("TAB" . "\t") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
617 ("ESC" . "\e") ("SPC" . " ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
618 ("DEL" . "\177"))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
619 (when found (setq word (cdr found)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
620 (when (string-match "^\\\\[0-7]+$" word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
621 (loop for ch across word |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
622 for n = 0 then (+ (* n 8) ch -48) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
623 finally do (setq word (vector n)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
624 (cond ((= bits 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
625 (setq key word)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
626 ((and (= bits (lsh 1 23)) (stringp word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
627 (string-match "^-?[0-9]+$" word)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
628 (setq key (loop for x across word collect (+ x bits)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
629 ((/= (length word) 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
630 (error "%s must prefix a single character, not %s" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
631 (substring orig-word 0 prefix) word)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
632 ((and (/= (logand bits (lsh 1 22)) 0) (stringp word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
633 (string-match "[@-_.a-z?]" word)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
634 (setq key (list (+ bits (- (lsh 1 22)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
635 (if (equal word "?") 127 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
636 (logand (aref word 0) 31)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
637 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
638 (setq key (list (+ bits (aref word 0))))))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
639 (when key |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
640 (loop repeat times do (callf vconcat res key))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
641 (when (and (>= (length res) 4) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
642 (eq (aref res 0) ?\C-x) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
643 (eq (aref res 1) ?\() |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
644 (eq (aref res (- (length res) 2)) ?\C-x) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
645 (eq (aref res (- (length res) 1)) ?\))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
646 (setq res (subseq res 2 -2))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
647 (if (and (not need-vector) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
648 (loop for ch across res |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
649 always (and (integerp ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
650 (let ((ch2 (logand ch (lognot (lsh 1 23))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
651 (and (>= ch2 0) (<= ch2 127)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
652 (concat (loop for ch across res |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
653 collect (if (= (logand ch (lsh 1 23)) 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
654 ch (+ ch 128)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
655 res))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
656 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
657 ;;; The following probably ought to go in macros.el: |
109 | 658 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
659 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
660 (defun insert-kbd-macro (macroname &optional keys) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
661 "Insert in buffer the definition of kbd macro NAME, as Lisp code. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
662 Optional second arg KEYS means also record the keys it is on |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
663 \(this is the prefix argument, when calling interactively). |
109 | 664 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
665 This Lisp code will, when executed, define the kbd macro with the same |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
666 definition it has now. If you say to record the keys, the Lisp code |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
667 will also rebind those keys to the macro. Only global key bindings |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
668 are recorded since executing this Lisp code always makes global |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
669 bindings. |
109 | 670 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
671 To save a kbd macro, visit a file of Lisp code such as your `~/.emacs', |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
672 use this command, and then save the file." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
673 (interactive "CInsert kbd macro (name): \nP") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
674 (let (definition) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
675 (if (string= (symbol-name macroname) "") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
676 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
677 (setq definition (format-kbd-macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
678 (insert "(setq last-kbd-macro")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
679 (setq definition (format-kbd-macro macroname)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
680 (insert (format "(defalias '%s" macroname))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
681 (if (> (length definition) 50) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
682 (insert " (read-kbd-macro\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
683 (insert "\n (read-kbd-macro ")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
684 (prin1 definition (current-buffer)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
685 (insert "))\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
686 (if keys |
5772
daac61915408
(edit-kbd-macro, edmacro-finish-edit, insert-kbd-macro):
Richard M. Stallman <rms@gnu.org>
parents:
5307
diff
changeset
|
687 (let ((keys (where-is-internal macroname '(keymap)))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
688 (while keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
689 (insert (format "(global-set-key %S '%s)\n" (car keys) macroname)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
690 (setq keys (cdr keys))))))) |
109 | 691 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
692 (provide 'edmacro) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
693 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
694 ;;; edmacro.el ends here |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
695 |