Mercurial > emacs
annotate lisp/edmacro.el @ 59499:e13b943b7f9a
(mouse-on-link-p): Change functionality and doc
string to comply with latest description in lisp ref.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Wed, 12 Jan 2005 10:17:02 +0000 |
parents | 89cc919b0ccd |
children | a7e02ef1e3d6 e4029991605f |
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 |
58836
89cc919b0ccd
`edit-kbd-macro' is now bound to `C-x C-k e'.
Luc Teirlinck <teirllm@auburn.edu>
parents:
57292
diff
changeset
|
3 ;; Copyright (C) 1993, 1994, 2004 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 | |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
109 | 26 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
27 ;;; Commentary: |
109 | 28 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
29 ;;; Usage: |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
30 ;; |
58836
89cc919b0ccd
`edit-kbd-macro' is now bound to `C-x C-k e'.
Luc Teirlinck <teirllm@auburn.edu>
parents:
57292
diff
changeset
|
31 ;; The `C-x C-k e' (`edit-kbd-macro') command edits a keyboard macro |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
32 ;; 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
|
33 ;; which should be one of: |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
34 ;; |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47404
diff
changeset
|
35 ;; * RET or `C-x e' (call-last-kbd-macro), to edit the most |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
36 ;; recently defined keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
37 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
38 ;; * `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
|
39 ;; whose definition is a keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
40 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
41 ;; * `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
|
42 ;; and install them as the "current" macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
43 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
44 ;; * any key sequence whose definition is a keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
45 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
46 ;; 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
|
47 ;; more readable format defined by these routines. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
48 ;; |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
49 ;; 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
|
50 ;; 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
|
51 ;; 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
|
52 ;; Lisp functions. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
53 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
54 ;; 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
|
55 ;; for information about the format of written keyboard macros. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
56 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
57 ;; `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
|
58 ;; 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
|
59 ;; 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
|
60 ;; 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
|
61 ;; won't hurt anything. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
62 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
63 ;; 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
|
64 ;; 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
|
65 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
66 ;; 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
|
67 ;; 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
|
68 ;; 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
|
69 ;; Lucid Emacs. |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
70 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
71 ;;; Code: |
109 | 72 |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
73 (eval-when-compile |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
74 (require 'cl)) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
75 |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
76 (require 'kmacro) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
77 |
109 | 78 ;;; The user-level commands for editing macros. |
79 | |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
80 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
81 (defvar edmacro-eight-bits nil |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
82 "*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
|
83 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
|
84 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
85 (defvar edmacro-mode-map nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
86 (unless edmacro-mode-map |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
87 (setq edmacro-mode-map (make-sparse-keymap)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
88 (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
|
89 (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
|
90 |
14464
fea038c6da68
(edmacro-original-buffer, edmacro-finish-hook)
Richard M. Stallman <rms@gnu.org>
parents:
14397
diff
changeset
|
91 (defvar edmacro-store-hook) |
fea038c6da68
(edmacro-original-buffer, edmacro-finish-hook)
Richard M. Stallman <rms@gnu.org>
parents:
14397
diff
changeset
|
92 (defvar edmacro-finish-hook) |
fea038c6da68
(edmacro-original-buffer, edmacro-finish-hook)
Richard M. Stallman <rms@gnu.org>
parents:
14397
diff
changeset
|
93 (defvar edmacro-original-buffer) |
fea038c6da68
(edmacro-original-buffer, edmacro-finish-hook)
Richard M. Stallman <rms@gnu.org>
parents:
14397
diff
changeset
|
94 |
258 | 95 ;;;###autoload |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
96 (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
|
97 "Edit a keyboard macro. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 its command name. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
102 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
|
103 (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
|
104 (when keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
105 (let ((cmd (if (arrayp keys) (key-binding keys) keys)) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
106 (mac nil) (mac-counter nil) (mac-format nil) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
107 kmacro) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
108 (cond (store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
109 (setq mac keys) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
110 (setq cmd nil)) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47404
diff
changeset
|
111 ((or (memq cmd '(call-last-kbd-macro kmacro-call-macro |
47404
51b92fc1f484
(edit-kbd-macro): Recognize new C-x e binding, kmacro-end-and-call-macro.
Kim F. Storm <storm@cua.dk>
parents:
47294
diff
changeset
|
112 kmacro-end-or-call-macro kmacro-end-and-call-macro)) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
113 (member keys '("\r" [return]))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
114 (or last-kbd-macro |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
115 (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
|
116 (keyboard-quit)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
117 (setq mac (or last-kbd-macro "")) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
118 (setq keys nil) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
119 (setq cmd 'last-kbd-macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
120 ((eq cmd 'execute-extended-command) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
121 (setq cmd (read-command "Name of keyboard macro to edit: ")) |
14397
49d961cdc9d6
(edit-kbd-macro): Reject empty cmd name.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
122 (if (string-equal cmd "") |
49d961cdc9d6
(edit-kbd-macro): Reject empty cmd name.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
123 (error "No command name given")) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
124 (setq keys nil) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
125 (setq mac (symbol-function cmd))) |
23945
688314651e5a
(edit-kbd-macro): Recognize electric-view-lossage.
Richard M. Stallman <rms@gnu.org>
parents:
16977
diff
changeset
|
126 ((memq cmd '(view-lossage electric-view-lossage)) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
127 (setq mac (recent-keys)) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
128 (setq keys nil) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
129 (setq cmd 'last-kbd-macro)) |
11870
993431cf1f89
(edit-kbd-macro): Better error messages for undefined keys
Karl Heuer <kwzh@gnu.org>
parents:
10692
diff
changeset
|
130 ((null cmd) |
993431cf1f89
(edit-kbd-macro): Better error messages for undefined keys
Karl Heuer <kwzh@gnu.org>
parents:
10692
diff
changeset
|
131 (error "Key sequence %s is not defined" (key-description keys))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
132 ((symbolp cmd) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
133 (setq mac (symbol-function cmd))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
134 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
135 (setq mac cmd) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
136 (setq cmd nil))) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
137 (when (setq kmacro (kmacro-extract-lambda mac)) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
138 (setq mac (car kmacro) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
139 mac-counter (nth 1 kmacro) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
140 mac-format (nth 2 kmacro))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
141 (unless (arrayp mac) |
11870
993431cf1f89
(edit-kbd-macro): Better error messages for undefined keys
Karl Heuer <kwzh@gnu.org>
parents:
10692
diff
changeset
|
142 (error "Key sequence %s is not a keyboard macro" |
993431cf1f89
(edit-kbd-macro): Better error messages for undefined keys
Karl Heuer <kwzh@gnu.org>
parents:
10692
diff
changeset
|
143 (key-description keys))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
144 (message "Formatting keyboard macro...") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
145 (let* ((oldbuf (current-buffer)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
146 (mmac (edmacro-fix-menu-commands mac)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
147 (fmt (edmacro-format-keys mmac 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
148 (fmtv (edmacro-format-keys mmac (not prefix))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
149 (buf (get-buffer-create "*Edit Macro*"))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
150 (message "Formatting keyboard macro...done") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
151 (switch-to-buffer buf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
152 (kill-all-local-variables) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
153 (use-local-map edmacro-mode-map) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
154 (setq buffer-read-only nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
155 (setq major-mode 'edmacro-mode) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
156 (setq mode-name "Edit Macro") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
157 (set (make-local-variable 'edmacro-original-buffer) oldbuf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
158 (set (make-local-variable 'edmacro-finish-hook) finish-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
159 (set (make-local-variable 'edmacro-store-hook) store-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
160 (erase-buffer) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
161 (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
|
162 "press C-x k RET to cancel.\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
163 (insert ";; Original keys: " fmt "\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
164 (unless store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
165 (insert "\nCommand: " (if cmd (symbol-name cmd) "none") "\n") |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
166 (let ((gkeys (where-is-internal (or cmd mac) '(keymap)))) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
167 (if (and keys (not (member keys gkeys))) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
168 (setq gkeys (cons keys gkeys))) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
169 (if gkeys |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
170 (while gkeys |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
171 (insert "Key: " (edmacro-format-keys (pop gkeys) 1) "\n")) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
172 (insert "Key: none\n"))) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
173 (when (and mac-counter mac-format) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
174 (insert (format "Counter: %d\nFormat: \"%s\"\n" mac-counter mac-format)))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
175 (insert "\nMacro:\n\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
176 (save-excursion |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
177 (insert fmtv "\n")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
178 (recenter '(4)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
179 (when (eq mac mmac) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
180 (set-buffer-modified-p nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
181 (run-hooks 'edmacro-format-hook))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
182 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
183 ;;; 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
|
184 ;;; compatibility. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
185 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
186 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
187 (defun edit-last-kbd-macro (&optional prefix) |
109 | 188 "Edit the most recently defined keyboard macro." |
189 (interactive "P") | |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
190 (edit-kbd-macro 'call-last-kbd-macro prefix)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
191 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
192 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
193 (defun edit-named-kbd-macro (&optional prefix) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
194 "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
|
195 (interactive "P") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
196 (edit-kbd-macro 'execute-extended-command prefix)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
197 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
198 ;;;###autoload |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
199 (defun read-kbd-macro (start &optional end) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
200 "Read the region as a keyboard macro definition. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
201 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
|
202 See documentation for `edmacro-mode' for details. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
203 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
|
204 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
|
205 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 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
|
210 (interactive "r") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
211 (if (stringp start) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
212 (edmacro-parse-keys start end) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
213 (setq last-kbd-macro (edmacro-parse-keys (buffer-substring start end))))) |
109 | 214 |
258 | 215 ;;;###autoload |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
216 (defun format-kbd-macro (&optional macro verbose) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
217 "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
|
218 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
|
219 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
|
220 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
|
221 or nil, use a compact 80-column format." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
222 (and macro (symbolp macro) (setq macro (symbol-function macro))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
223 (edmacro-format-keys (or macro last-kbd-macro) verbose)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
224 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
225 ;;; Commands for *Edit Macro* buffer. |
109 | 226 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
227 (defun edmacro-finish-edit () |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
228 (interactive) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
229 (unless (eq major-mode 'edmacro-mode) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
230 (error |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
231 "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
|
232 (run-hooks 'edmacro-finish-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
233 (let ((cmd nil) (keys nil) (no-keys nil) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
234 (mac-counter nil) (mac-format nil) (kmacro nil) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
235 (top (point-min))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
236 (goto-char top) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
237 (let ((case-fold-search nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
238 (while (cond ((looking-at "[ \t]*\\($\\|;;\\|REM[ \t\n]\\)") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
239 t) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
240 ((looking-at "Command:[ \t]*\\([^ \t\n]*\\)[ \t]*$") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
241 (when edmacro-store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
242 (error "\"Command\" line not allowed in this context")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
243 (let ((str (buffer-substring (match-beginning 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
244 (match-end 1)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
245 (unless (equal str "") |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
246 (setq cmd (and (not (equal str "none")) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
247 (intern str))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
248 (and (fboundp cmd) (not (arrayp (symbol-function cmd))) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
249 (not (setq kmacro (get cmd 'kmacro))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
250 (not (y-or-n-p |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
251 (format "Command %s is already defined; %s" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
252 cmd "proceed? "))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
253 (keyboard-quit)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
254 t) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
255 ((looking-at "Key:\\(.*\\)$") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
256 (when edmacro-store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
257 (error "\"Key\" line not allowed in this context")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
258 (let ((key (edmacro-parse-keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
259 (buffer-substring (match-beginning 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
260 (match-end 1))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
261 (unless (equal key "") |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
262 (if (equal key "none") |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
263 (setq no-keys t) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
264 (push key keys) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
265 (let ((b (key-binding key))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
266 (and b (commandp b) (not (arrayp b)) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
267 (not (kmacro-extract-lambda b)) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
268 (or (not (fboundp b)) |
58836
89cc919b0ccd
`edit-kbd-macro' is now bound to `C-x C-k e'.
Luc Teirlinck <teirllm@auburn.edu>
parents:
57292
diff
changeset
|
269 (not (or (arrayp (symbol-function b)) |
89cc919b0ccd
`edit-kbd-macro' is now bound to `C-x C-k e'.
Luc Teirlinck <teirllm@auburn.edu>
parents:
57292
diff
changeset
|
270 (get b 'kmacro)))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
271 (not (y-or-n-p |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
272 (format "Key %s is already defined; %s" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
273 (edmacro-format-keys key 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
274 "proceed? "))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
275 (keyboard-quit)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
276 t) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
277 ((looking-at "Counter:[ \t]*\\([^ \t\n]*\\)[ \t]*$") |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
278 (when edmacro-store-hook |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
279 (error "\"Counter\" line not allowed in this context")) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
280 (let ((str (buffer-substring (match-beginning 1) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
281 (match-end 1)))) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
282 (unless (equal str "") |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
283 (setq mac-counter (string-to-int str)))) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
284 t) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
285 ((looking-at "Format:[ \t]*\"\\([^\n]*\\)\"[ \t]*$") |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
286 (when edmacro-store-hook |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
287 (error "\"Format\" line not allowed in this context")) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
288 (let ((str (buffer-substring (match-beginning 1) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
289 (match-end 1)))) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
290 (unless (equal str "") |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
291 (setq mac-format str))) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
292 t) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
293 ((looking-at "Macro:[ \t\n]*") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
294 (goto-char (match-end 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
295 nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
296 ((eobp) nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
297 (t (error "Expected a `Macro:' line"))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
298 (forward-line 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
299 (setq top (point))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
300 (let* ((buf (current-buffer)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
301 (str (buffer-substring top (point-max))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
302 (modp (buffer-modified-p)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
303 (obuf edmacro-original-buffer) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
304 (store-hook edmacro-store-hook) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
305 (finish-hook edmacro-finish-hook)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
306 (unless (or cmd keys store-hook (equal str "")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
307 (error "No command name or keys specified")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
308 (when modp |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
309 (when (buffer-name obuf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
310 (set-buffer obuf)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
311 (message "Compiling keyboard macro...") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
312 (let ((mac (edmacro-parse-keys str))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
313 (message "Compiling keyboard macro...done") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
314 (if store-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
315 (funcall store-hook mac) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
316 (when (eq cmd 'last-kbd-macro) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
317 (setq last-kbd-macro (and (> (length mac) 0) mac)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
318 (setq cmd nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
319 (when cmd |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
320 (if (= (length mac) 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
321 (fmakunbound cmd) |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
322 (fset cmd |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
323 (if (and mac-counter mac-format) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
324 (kmacro-lambda-form mac mac-counter mac-format) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
325 mac)))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
326 (if no-keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
327 (when cmd |
5772
daac61915408
(edit-kbd-macro, edmacro-finish-edit, insert-kbd-macro):
Richard M. Stallman <rms@gnu.org>
parents:
5307
diff
changeset
|
328 (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
|
329 (global-unset-key key))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
330 (when keys |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
331 (if (= (length mac) 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
332 (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
|
333 (loop for key in keys do |
57292
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
334 (global-set-key key |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
335 (or cmd |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
336 (if (and mac-counter mac-format) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
337 (kmacro-lambda-form mac mac-counter mac-format) |
00748c19ee41
Require kmacro to use the new kmacro-lambda-form and
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
338 mac)))))))))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
339 (kill-buffer buf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
340 (when (buffer-name obuf) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
341 (switch-to-buffer obuf)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
342 (when finish-hook |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
343 (funcall finish-hook))))) |
109 | 344 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
345 (defun edmacro-insert-key (key) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
346 "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
|
347 (interactive "kKey to insert: ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
348 (if (bolp) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
349 (insert (edmacro-format-keys key t) "\n") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
350 (insert (edmacro-format-keys key) " "))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
351 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
352 (defun edmacro-mode () |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
353 "\\<edmacro-mode-map>Keyboard Macro Editing mode. Press |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
354 \\[edmacro-finish-edit] to save and exit. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
355 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
|
356 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
357 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
|
358 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
359 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
|
360 \"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
|
361 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
|
362 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
367 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
|
368 or \"none\" for no key bindings. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
369 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
370 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
|
371 is stored. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
372 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
373 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
374 Format of keyboard macros during editing: |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
375 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 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
|
380 as in \"foo SPC bar RET\". |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
381 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
382 * 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
|
383 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
|
384 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
385 * 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
|
386 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
|
387 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
|
388 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
|
389 are not required there. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
390 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
391 * 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
|
392 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
|
393 with codes above \\377. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
394 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
395 * 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
|
396 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
|
397 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
|
398 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
|
399 any order: M-C-x = C-M-x. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
400 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
405 * 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
|
406 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
407 * Double angle brackets enclose command names: <<next-line>> is |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
408 shorthand for M-x next-line RET. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
409 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
410 * 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
|
411 comment. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
412 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
413 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
|
414 number and `*': 3*<right> = <right> <right> <right>, and |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
415 10*foo = foofoofoofoofoofoofoofoofoofoo. |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
416 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 doubt, use whitespace." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
424 (interactive) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
425 (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
|
426 (put 'edmacro-mode 'mode-class 'special) |
109 | 427 |
428 ;;; Formatting a keyboard macro as human-readable text. | |
429 | |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
430 (defun edmacro-format-keys (macro &optional verbose) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
431 (setq macro (edmacro-fix-menu-commands macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
432 (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
|
433 (if (current-local-map) |
712e13833ad8
(edmacro-format-keys): Cope if local keymap is nil.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
434 (list (current-local-map))) |
712e13833ad8
(edmacro-format-keys): Cope if local keymap is nil.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
435 (list (current-global-map)))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
436 (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
|
437 ?\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
|
438 ?\M-7 ?\M-8 ?\M-9)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
439 (mdigs (nthcdr 13 pkeys)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
440 (maxkey (if edmacro-eight-bits 255 127)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
441 (case-fold-search nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
442 (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
|
443 (rest-mac (vconcat macro [end-macro])) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
444 (res "") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
445 (len 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
446 (one-line (eq verbose 1))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
447 (if one-line (setq verbose nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
448 (when (stringp macro) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
449 (loop for i below (length macro) do |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
450 (when (>= (aref rest-mac i) 128) |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
451 (incf (aref rest-mac i) (- ?\M-\^@ 128))))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
452 (while (not (eq (aref rest-mac 0) 'end-macro)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
453 (let* ((prefix |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
454 (or (and (integerp (aref rest-mac 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
455 (memq (aref rest-mac 0) mdigs) |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
456 (memq (key-binding (edmacro-subseq rest-mac 0 1)) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
457 '(digit-argument negative-argument)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
458 (let ((i 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
459 (while (memq (aref rest-mac i) (cdr mdigs)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
460 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
461 (and (not (memq (aref rest-mac i) pkeys)) |
52131
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
462 (prog1 (vconcat "M-" (edmacro-subseq rest-mac 0 i) " ") |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
463 (callf edmacro-subseq rest-mac i))))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
464 (and (eq (aref rest-mac 0) ?\C-u) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
465 (eq (key-binding [?\C-u]) 'universal-argument) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
466 (let ((i 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
467 (while (eq (aref rest-mac i) ?\C-u) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
468 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
469 (and (not (memq (aref rest-mac i) pkeys)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
470 (prog1 (loop repeat i concat "C-u ") |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
471 (callf edmacro-subseq rest-mac i))))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
472 (and (eq (aref rest-mac 0) ?\C-u) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
473 (eq (key-binding [?\C-u]) 'universal-argument) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
474 (let ((i 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
475 (when (eq (aref rest-mac i) ?-) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
476 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
477 (while (memq (aref rest-mac i) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
478 '(?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
|
479 (incf i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
480 (and (not (memq (aref rest-mac i) pkeys)) |
52131
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
481 (prog1 (vconcat "C-u " (edmacro-subseq rest-mac 1 i) " ") |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
482 (callf edmacro-subseq rest-mac i))))))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
483 (bind-len (apply 'max 1 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
484 (loop for map in maps |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
485 for b = (lookup-key map rest-mac) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
486 when b collect b))) |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
487 (key (edmacro-subseq rest-mac 0 bind-len)) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
488 (fkey nil) tlen tkey |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
489 (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
|
490 thereis (and (not (integerp b)) b)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
491 (and (setq fkey (lookup-key function-key-map rest-mac)) |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
492 (setq tlen fkey tkey (edmacro-subseq rest-mac 0 tlen) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
493 fkey (lookup-key function-key-map tkey)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
494 (loop for map in maps |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
495 for b = (lookup-key map fkey) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
496 when (and (not (integerp b)) b) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
497 do (setq bind-len tlen key tkey) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
498 and return b |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
499 finally do (setq fkey nil))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
500 (first (aref key 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
501 (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
|
502 for ch = (aref rest-mac i) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
503 while (and (integerp ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
504 (> ch 32) (< ch maxkey) (/= ch 92) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
505 (eq (key-binding (char-to-string ch)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
506 'self-insert-command) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
507 (or (> i (- (length rest-mac) 2)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
508 (not (eq ch (aref rest-mac (+ i 1)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
509 (not (eq ch (aref rest-mac (+ i 2)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
510 finally return i)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
511 desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
512 (if (stringp bind) (setq bind nil)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
513 (cond ((and (eq bind 'self-insert-command) (not prefix) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
514 (> text 1) (integerp first) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
515 (> first 32) (<= first maxkey) (/= first 92) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
516 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
517 (if (> text 30) (setq text 30)) |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
518 (setq desc (concat (edmacro-subseq rest-mac 0 text))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
519 (when (string-match "^[ACHMsS]-." desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
520 (setq text 2) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
521 (callf substring desc 0 2)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
522 (not (string-match |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
523 "^;;\\|^<.*>$\\|^\\\\[0-9]+$\\|^[0-9]+\\*." |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
524 desc)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
525 (when (or (string-match "^\\^.$" desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
526 (member desc res-words)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
527 (setq desc (mapconcat 'char-to-string desc " "))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
528 (when verbose |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
529 (setq bind (format "%s * %d" bind text))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
530 (setq bind-len text)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
531 ((and (eq bind 'execute-extended-command) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
532 (> text bind-len) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
533 (memq (aref rest-mac text) '(return 13)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
534 (progn |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
535 (setq desc (concat (edmacro-subseq rest-mac bind-len text))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
536 (commandp (intern-soft desc)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
537 (if (commandp (intern-soft desc)) (setq bind desc)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
538 (setq desc (format "<<%s>>" desc)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
539 (setq bind-len (1+ text))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
540 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
541 (setq desc (mapconcat |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
542 (function |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
543 (lambda (ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
544 (cond |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
545 ((integerp ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
546 (concat |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
547 (loop for pf across "ACHMsS" |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
548 for bit in '(?\A-\^@ ?\C-\^@ ?\H-\^@ |
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
549 ?\M-\^@ ?\s-\^@ ?\S-\^@) |
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
550 when (/= (logand ch bit) 0) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
551 concat (format "%c-" pf)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
552 (let ((ch2 (logand ch (1- (lsh 1 18))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
553 (cond ((<= ch2 32) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
554 (case ch2 |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
555 (0 "NUL") (9 "TAB") (10 "LFD") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
556 (13 "RET") (27 "ESC") (32 "SPC") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
557 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
558 (format "C-%c" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
559 (+ (if (<= ch2 26) 96 64) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
560 ch2))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
561 ((= ch2 127) "DEL") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
562 ((<= ch2 maxkey) (char-to-string ch2)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
563 (t (format "\\%o" ch2)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
564 ((symbolp ch) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
565 (format "<%s>" ch)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
566 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
567 (error "Unrecognized item in macro: %s" ch))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
568 (or fkey key) " ")))) |
52131
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
569 (if prefix |
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
570 (setq desc (concat (edmacro-sanitize-for-string prefix) desc))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
571 (unless (string-match " " desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
572 (let ((times 1) (pos bind-len)) |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
573 (while (not (edmacro-mismatch rest-mac rest-mac |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
574 0 bind-len pos (+ bind-len pos))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
575 (incf times) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
576 (incf pos bind-len)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
577 (when (> times 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
578 (setq desc (format "%d*%s" times desc)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
579 (setq bind-len (* bind-len times))))) |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
580 (setq rest-mac (edmacro-subseq rest-mac bind-len)) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
581 (if verbose |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
582 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
583 (unless (equal res "") (callf concat res "\n")) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
584 (callf concat res desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
585 (when (and bind (or (stringp bind) (symbolp bind))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
586 (callf concat res |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
587 (make-string (max (- 3 (/ (length desc) 8)) 1) 9) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
588 ";; " (if (stringp bind) bind (symbol-name bind)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
589 (setq len 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
590 (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
|
591 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
592 (callf concat res "\n ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
593 (setq len 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
594 (unless (equal res "") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
595 (callf concat res " ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
596 (incf len))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
597 (callf concat res desc) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
598 (incf len (length desc))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
599 res)) |
109 | 600 |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
601 (defun edmacro-mismatch (cl-seq1 cl-seq2 cl-start1 cl-end1 cl-start2 cl-end2) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
602 "Compare SEQ1 with SEQ2, return index of first mismatching element. |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
603 Return nil if the sequences match. If one sequence is a prefix of the |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
604 other, the return value indicates the end of the shorted sequence." |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
605 (let (cl-test cl-test-not cl-key cl-from-end) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
606 (or cl-end1 (setq cl-end1 (length cl-seq1))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
607 (or cl-end2 (setq cl-end2 (length cl-seq2))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
608 (if cl-from-end |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
609 (progn |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
610 (while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
611 (cl-check-match (elt cl-seq1 (1- cl-end1)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
612 (elt cl-seq2 (1- cl-end2)))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
613 (setq cl-end1 (1- cl-end1) cl-end2 (1- cl-end2))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
614 (and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
615 (1- cl-end1))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
616 (let ((cl-p1 (and (listp cl-seq1) (nthcdr cl-start1 cl-seq1))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
617 (cl-p2 (and (listp cl-seq2) (nthcdr cl-start2 cl-seq2)))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
618 (while (and (< cl-start1 cl-end1) (< cl-start2 cl-end2) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
619 (cl-check-match (if cl-p1 (car cl-p1) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
620 (aref cl-seq1 cl-start1)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
621 (if cl-p2 (car cl-p2) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
622 (aref cl-seq2 cl-start2)))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
623 (setq cl-p1 (cdr cl-p1) cl-p2 (cdr cl-p2) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
624 cl-start1 (1+ cl-start1) cl-start2 (1+ cl-start2))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
625 (and (or (< cl-start1 cl-end1) (< cl-start2 cl-end2)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
626 cl-start1))))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
627 |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
628 (defun edmacro-subseq (seq start &optional end) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
629 "Return the subsequence of SEQ from START to END. |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
630 If END is omitted, it defaults to the length of the sequence. |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
631 If START or END is negative, it counts from the end." |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
632 (if (stringp seq) (substring seq start end) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
633 (let (len) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
634 (and end (< end 0) (setq end (+ end (setq len (length seq))))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
635 (if (< start 0) (setq start (+ start (or len (setq len (length seq)))))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
636 (cond ((listp seq) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
637 (if (> start 0) (setq seq (nthcdr start seq))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
638 (if end |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
639 (let ((res nil)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
640 (while (>= (setq end (1- end)) start) |
47294
15e9f75f55b0
(edmacro-subseq): Don't use cl-push/cl-pop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47197
diff
changeset
|
641 (push (pop seq) res)) |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
642 (nreverse res)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
643 (copy-sequence seq))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
644 (t |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
645 (or end (setq end (or len (length seq)))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
646 (let ((res (make-vector (max (- end start) 0) nil)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
647 (i 0)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
648 (while (< start end) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
649 (aset res i (aref seq start)) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
650 (setq i (1+ i) start (1+ start))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
651 res)))))) |
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
652 |
52131
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
653 (defun edmacro-sanitize-for-string (seq) |
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
654 "Convert a key sequence vector into a string. |
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
655 The string represents the same events; Meta is indicated by bit 7. |
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
656 This function assumes that the events can be stored in a string." |
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
657 (setq seq (copy-sequence seq)) |
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
658 (loop for i below (length seq) do |
58836
89cc919b0ccd
`edit-kbd-macro' is now bound to `C-x C-k e'.
Luc Teirlinck <teirllm@auburn.edu>
parents:
57292
diff
changeset
|
659 (when (logand (aref seq i) 128) |
52131
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
660 (setf (aref seq i) (logand (aref seq i) 127)))) |
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
661 seq) |
6be32b5661a6
(edmacro-format-keys): Use edmacro-sanitize-for-string.
Richard M. Stallman <rms@gnu.org>
parents:
49588
diff
changeset
|
662 |
45939
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
663 (defun edmacro-fix-menu-commands (macro &optional noerror) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
664 (if (vectorp macro) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
665 (let (result) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
666 ;; Make a list of the elements. |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
667 (setq macro (append macro nil)) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
668 (dolist (ev macro) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
669 (cond ((atom ev) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
670 (push ev result)) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
671 ((eq (car ev) 'help-echo)) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
672 ((equal ev '(menu-bar)) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
673 (push 'menu-bar result)) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
674 ((equal (cadadr ev) '(menu-bar)) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
675 (push (vector 'menu-bar (car ev)) result)) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
676 ;; 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
|
677 ;; info is recorded in macros to make this possible. |
45939
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
678 (noerror |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
679 ;; Just ignore mouse events. |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
680 nil) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
681 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
682 (error "Macros with mouse clicks are not %s" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
683 "supported by this command")))) |
45939
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
684 ;; Reverse them again and make them back into a vector. |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
685 (vconcat (nreverse result))) |
6ccb89338ab1
(edmacro-fix-menu-commands):
Richard M. Stallman <rms@gnu.org>
parents:
38436
diff
changeset
|
686 macro)) |
109 | 687 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
688 ;;; Parsing a human-readable keyboard macro. |
109 | 689 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
690 (defun edmacro-parse-keys (string &optional need-vector) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
691 (let ((case-fold-search nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
692 (pos 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
693 (res [])) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
694 (while (and (< pos (length string)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
695 (string-match "[^ \t\n\f]+" string pos)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
696 (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
|
697 (key nil) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
698 (times 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
699 (setq pos (match-end 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
700 (when (string-match "\\([0-9]+\\)\\*." word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
701 (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
|
702 (setq word (substring word (1+ (match-end 1))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
703 (cond ((string-match "^<<.+>>$" word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
704 (setq key (vconcat (if (eq (key-binding [?\M-x]) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
705 'execute-extended-command) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
706 [?\M-x] |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
707 (or (car (where-is-internal |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
708 'execute-extended-command)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
709 [?\M-x])) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
710 (substring word 2 -2) "\r"))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
711 ((and (string-match "^\\(\\([ACHMsS]-\\)*\\)<\\(.+\\)>$" word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
712 (progn |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
713 (setq word (concat (substring word (match-beginning 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
714 (match-end 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
715 (substring word (match-beginning 3) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
716 (match-end 3)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
717 (not (string-match |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
718 "\\<\\(NUL\\|RET\\|LFD\\|ESC\\|SPC\\|DEL\\)$" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
719 word)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
720 (setq key (list (intern word)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
721 ((or (equal word "REM") (string-match "^;;" word)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
722 (setq pos (string-match "$" string pos))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
723 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
724 (let ((orig-word word) (prefix 0) (bits 0)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
725 (while (string-match "^[ACHMsS]-." word) |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
726 (incf bits (cdr (assq (aref word 0) |
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
727 '((?A . ?\A-\^@) (?C . ?\C-\^@) |
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
728 (?H . ?\H-\^@) (?M . ?\M-\^@) |
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
729 (?s . ?\s-\^@) (?S . ?\S-\^@))))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
730 (incf prefix 2) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
731 (callf substring word 2)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
732 (when (string-match "^\\^.$" word) |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
733 (incf bits ?\C-\^@) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
734 (incf prefix) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
735 (callf substring word 1)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
736 (let ((found (assoc word '(("NUL" . "\0") ("RET" . "\r") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
737 ("LFD" . "\n") ("TAB" . "\t") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
738 ("ESC" . "\e") ("SPC" . " ") |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
739 ("DEL" . "\177"))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
740 (when found (setq word (cdr found)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
741 (when (string-match "^\\\\[0-7]+$" word) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
742 (loop for ch across word |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
743 for n = 0 then (+ (* n 8) ch -48) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
744 finally do (setq word (vector n)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
745 (cond ((= bits 0) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
746 (setq key word)) |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
747 ((and (= bits ?\M-\^@) (stringp word) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
748 (string-match "^-?[0-9]+$" word)) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
749 (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
|
750 ((/= (length word) 1) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
751 (error "%s must prefix a single character, not %s" |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
752 (substring orig-word 0 prefix) word)) |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
753 ((and (/= (logand bits ?\C-\^@) 0) (stringp word) |
16951
156fd377c7d0
(edmacro-parse-keys): Don't treat C-. or C-? as ASCII control char.
Richard M. Stallman <rms@gnu.org>
parents:
16283
diff
changeset
|
754 ;; We used to accept . and ? here, |
156fd377c7d0
(edmacro-parse-keys): Don't treat C-. or C-? as ASCII control char.
Richard M. Stallman <rms@gnu.org>
parents:
16283
diff
changeset
|
755 ;; but . is simply wrong, |
156fd377c7d0
(edmacro-parse-keys): Don't treat C-. or C-? as ASCII control char.
Richard M. Stallman <rms@gnu.org>
parents:
16283
diff
changeset
|
756 ;; and C-? is not used (we use DEL instead). |
156fd377c7d0
(edmacro-parse-keys): Don't treat C-. or C-? as ASCII control char.
Richard M. Stallman <rms@gnu.org>
parents:
16283
diff
changeset
|
757 (string-match "[@-_a-z]" word)) |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
758 (setq key (list (+ bits (- ?\C-\^@) |
16977
e97bdda07a30
(edmacro-parse-keys): Remove redundant test for ?.
Erik Naggum <erik@naggum.no>
parents:
16951
diff
changeset
|
759 (logand (aref word 0) 31))))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
760 (t |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
761 (setq key (list (+ bits (aref word 0))))))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
762 (when key |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
763 (loop repeat times do (callf vconcat res key))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
764 (when (and (>= (length res) 4) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
765 (eq (aref res 0) ?\C-x) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
766 (eq (aref res 1) ?\() |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
767 (eq (aref res (- (length res) 2)) ?\C-x) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
768 (eq (aref res (- (length res) 1)) ?\))) |
12955
2e80892d4b39
Load cl only during compilation.
Richard M. Stallman <rms@gnu.org>
parents:
11870
diff
changeset
|
769 (setq res (edmacro-subseq res 2 -2))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
770 (if (and (not need-vector) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
771 (loop for ch across res |
29060
26c9122ca008
(edmacro-parse-keys): Return vector if any elements are invalid
Dave Love <fx@gnu.org>
parents:
23945
diff
changeset
|
772 always (and (char-valid-p ch) |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
773 (let ((ch2 (logand ch (lognot ?\M-\^@)))) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
774 (and (>= ch2 0) (<= ch2 127)))))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
775 (concat (loop for ch across res |
10692
58ab3325da3b
(edmacro-format-keys, edmacro-parse-keys): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents:
9199
diff
changeset
|
776 collect (if (= (logand ch ?\M-\^@) 0) |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
777 ch (+ ch 128)))) |
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
778 res))) |
109 | 779 |
4754
463663a999ee
Total rewrite by Gillespie.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
780 (provide 'edmacro) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
781 |
52401 | 782 ;;; arch-tag: 726807b4-3ae6-49de-b0ae-b9590973e0d7 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
783 ;;; edmacro.el ends here |