annotate lisp/utils/edmacro.el @ 138:6608ceec7cf8 r20-2b3

Import from CVS: tag r20-2b3
author cvs
date Mon, 13 Aug 2007 09:31:46 +0200
parents b980b6286996
children 59463afc5666
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;;; edmacro.el --- keyboard macro editor
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; Author: Dave Gillespie <daveg@synaptics.com>
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
6 ;; Hrvoje Niksic <hniksic@srce.hr> -- XEmacs port
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
7 ;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
8 ;; Version: 3.10
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;; Keywords: abbrev
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
11 ;; This file is part of XEmacs.
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;; any later version.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
21 ;; General Public License for more details.
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
26 ;; 02111-1307, USA.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
27
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
28 ;;; Synched up with: FSF 19.34.
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
29 ;;; The important parts of this file have been rewritten for XEmacs,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
30 ;;; so it's completely different from the FSF version. The original
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
31 ;;; could not be used because it worked with the Emacs key
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
32 ;;; representation, and it mixed characters and integers too freely.
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 ;;; Commentary:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 ;;; Usage:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 ;; The `C-x C-k' (`edit-kbd-macro') command edits a keyboard macro
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39 ;; in a special buffer. It prompts you to type a key sequence,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 ;; which should be one of:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 ;; * RET or `C-x e' (call-last-kbd-macro), to edit the most
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 ;; recently defined keyboard macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 ;; * `M-x' followed by a command name, to edit a named command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 ;; whose definition is a keyboard macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 ;; * `C-h l' (view-lossage), to edit the 100 most recent keystrokes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 ;; and install them as the "current" macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 ;; * any key sequence whose definition is a keyboard macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 ;; This file includes a version of `insert-kbd-macro' that uses the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 ;; more readable format defined by these routines.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 ;; Also, the `read-kbd-macro' command parses the region as
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 ;; a keyboard macro, and installs it as the "current" macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 ;; This and `format-kbd-macro' can also be called directly as
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 ;; Lisp functions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
61 ;; The `kbd' macro is a shorter-named and more efficient form of
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
62 ;; `read-kbd-macro'. Unlike `read-kbd-macro', it is evaluated at
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
63 ;; read-time, and doesn't bring any overhead to compiled programs. It
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
64 ;; is recommended to use in your programs and initializations, as you
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
65 ;; needn't know the internal keysym representation. For example:
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
66 ;;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
67 ;; (define-key foo-mode-map (kbd "C-c <up>") 'foo-up)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
68 ;;
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
69 ;; is the exact equivalent of
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
70 ;;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
71 ;; (define-key foo-mode-map [(control ?c) up] 'foo-up)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
72 ;;
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
73
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 ;; Type `C-h m', or see the documentation for `edmacro-mode' below,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 ;; for information about the format of written keyboard macros.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 ;; `edit-kbd-macro' formats the macro with one command per line,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 ;; including the command names as comments on the right. If the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 ;; formatter gets confused about which keymap was used for the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 ;; characters, the command-name comments will be wrong but that
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 ;; won't hurt anything.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 ;; With a prefix argument, `edit-kbd-macro' will format the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 ;; macro in a more concise way that omits the comments.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 ;; This package requires GNU Emacs 19 or later, and daveg's CL
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 ;; package 2.02 or later. (CL 2.02 comes standard starting with
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 ;; Emacs 19.18.) This package does not work with Emacs 18 or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 ;; Lucid Emacs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
91 ;; Ported to XEmacs. -hniksic
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 ;;; Code:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (eval-when-compile
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
96 (require 'cl))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 ;;; The user-level commands for editing macros.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 ;;;###autoload (define-key ctl-x-map "\C-k" 'edit-kbd-macro)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 (defvar edmacro-eight-bits nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 "*Non-nil if edit-kbd-macro should leave 8-bit characters intact.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 Default nil means to write characters above \\177 in octal notation.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
107 (if (fboundp 'mapvector)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
108 (defalias 'edmacro-mapvector 'mapvector)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
109 (defun edmacro-mapvector (fun seq)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
110 (map 'vector fun seq)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
111
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (defvar edmacro-mode-map nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 (unless edmacro-mode-map
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 (setq edmacro-mode-map (make-sparse-keymap))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 (define-key edmacro-mode-map "\C-c\C-c" 'edmacro-finish-edit)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (define-key edmacro-mode-map "\C-c\C-q" 'edmacro-insert-key))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 (defvar edmacro-store-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 (defvar edmacro-finish-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 (defvar edmacro-original-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
122 ;; A lot of cruft here, but I got it to work eventually. Could use
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
123 ;; some cleaning up.
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (defun edit-kbd-macro (keys &optional prefix finish-hook store-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 "Edit a keyboard macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 At the prompt, type any key sequence which is bound to a keyboard macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 Or, type `C-x e' or RET to edit the last keyboard macro, `C-h l' to edit
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 the last 100 keystrokes as a keyboard macro, or `M-x' to edit a macro by
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 its command name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 With a prefix argument, format the macro in a more concise way."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 (interactive "kKeyboard macro to edit (C-x e, M-x, C-h l, or keys): \nP")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 (when keys
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
134 (setq keys (edmacro-events-to-keys keys))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 (let ((cmd (if (arrayp keys) (key-binding keys) keys))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 (mac nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 (cond (store-hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 (setq mac keys)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 (setq cmd nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 ((or (eq cmd 'call-last-kbd-macro)
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
141 (and (arrayp keys)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
142 (= 1 (length keys))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
143 (eq ?\r (aref keys 0))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 (or last-kbd-macro
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 (y-or-n-p "No keyboard macro defined. Create one? ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 (keyboard-quit))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 (setq mac (or last-kbd-macro ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (setq cmd 'last-kbd-macro))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 ((eq cmd 'execute-extended-command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 (setq cmd (read-command "Name of keyboard macro to edit: "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (if (string-equal cmd "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 (error "No command name given"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 (setq mac (symbol-function cmd)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 ((eq cmd 'view-lossage)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 (setq mac (recent-keys))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 (setq cmd 'last-kbd-macro))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 ((null cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 (error "Key sequence %s is not defined" (key-description keys)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 ((symbolp cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160 (setq mac (symbol-function cmd)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
161 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 (setq mac cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 (setq cmd nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164 (unless (arrayp mac)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 (error "Key sequence %s is not a keyboard macro"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
166 (key-description keys)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
167 (message "Formatting keyboard macro...")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
168 (let* ((oldbuf (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
169 (mmac (edmacro-fix-menu-commands mac))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170 (fmt (edmacro-format-keys mmac 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171 (fmtv (edmacro-format-keys mmac (not prefix)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172 (buf (get-buffer-create "*Edit Macro*")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173 (message "Formatting keyboard macro...done")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174 (switch-to-buffer buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175 (kill-all-local-variables)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
176 (use-local-map edmacro-mode-map)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
177 (setq buffer-read-only nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
178 (setq major-mode 'edmacro-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
179 (setq mode-name "Edit Macro")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
180 (set (make-local-variable 'edmacro-original-buffer) oldbuf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
181 (set (make-local-variable 'edmacro-finish-hook) finish-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
182 (set (make-local-variable 'edmacro-store-hook) store-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
183 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
184 (insert ";; Keyboard Macro Editor. Press C-c C-c to finish; "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
185 "press C-x k RET to cancel.\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
186 (insert ";; Original keys: " fmt "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
187 (unless store-hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
188 (insert "\nCommand: " (if cmd (symbol-name cmd) "none") "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
189 (let ((keys (where-is-internal (or cmd mac))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
190 (if keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
191 (while keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
192 (insert "Key: " (edmacro-format-keys (pop keys) 1) "\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
193 (insert "Key: none\n"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
194 (insert "\nMacro:\n\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
195 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
196 (insert fmtv "\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
197 (recenter '(4))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
198 (when (eq mac mmac)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
199 (set-buffer-modified-p nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
200 (run-hooks 'edmacro-format-hook)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
201
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
202 ;;; The next two commands are provided for convenience and backward
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
203 ;;; compatibility.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
204
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
205 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
206 (defun edit-last-kbd-macro (&optional prefix)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
207 "Edit the most recently defined keyboard macro."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
208 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
209 (edit-kbd-macro 'call-last-kbd-macro prefix))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
210
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
211 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
212 (defun edit-named-kbd-macro (&optional prefix)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
213 "Edit a keyboard macro which has been given a name by `name-last-kbd-macro'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
214 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
215 (edit-kbd-macro 'execute-extended-command prefix))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
216
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
217 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
218 (defun read-kbd-macro (start &optional end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
219 "Read the region as a keyboard macro definition.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
220 The region is interpreted as spelled-out keystrokes, e.g., \"M-x abc RET\".
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
221 See documentation for `edmacro-mode' for details.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
222 Leading/trailing \"C-x (\" and \"C-x )\" in the text are allowed and ignored.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
223 The resulting macro is installed as the \"current\" keyboard macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
224
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
225 In Lisp, may also be called with a single STRING argument in which case
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
226 the result is returned rather than being installed as the current macro.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
227 The result will be a string if possible, otherwise an event vector.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
228 Second argument NEED-VECTOR means to return an event vector always."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
229 (interactive "r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
230 (if (stringp start)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
231 (edmacro-parse-keys start end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
232 (setq last-kbd-macro (edmacro-parse-keys (buffer-substring start end)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
233
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
234 ;;;###autoload
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
235 (defmacro kbd (keys)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
236 "Convert KEYS to the internal Emacs key representation."
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
237 (read-kbd-macro keys))
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
238
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
239 ;;;###autoload
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
240 (defun format-kbd-macro (&optional macro verbose)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
241 "Return the keyboard macro MACRO as a human-readable string.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
242 This string is suitable for passing to `read-kbd-macro'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
243 Second argument VERBOSE means to put one command per line with comments.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
244 If VERBOSE is `1', put everything on one line. If VERBOSE is omitted
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
245 or nil, use a compact 80-column format."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
246 (and macro (symbolp macro) (setq macro (symbol-function macro)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
247 (edmacro-format-keys (or macro last-kbd-macro) verbose))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
248
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
249 ;;; Commands for *Edit Macro* buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
250
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
251 (defun edmacro-finish-edit ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
252 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
253 (unless (eq major-mode 'edmacro-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
254 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
255 "This command is valid only in buffers created by `edit-kbd-macro'"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
256 (run-hooks 'edmacro-finish-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
257 (let ((cmd nil) (keys nil) (no-keys nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
258 (top (point-min)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
259 (goto-char top)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
260 (let ((case-fold-search nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
261 (while (cond ((looking-at "[ \t]*\\($\\|;;\\|REM[ \t\n]\\)")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
262 t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
263 ((looking-at "Command:[ \t]*\\([^ \t\n]*\\)[ \t]*$")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
264 (when edmacro-store-hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
265 (error "\"Command\" line not allowed in this context"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
266 (let ((str (buffer-substring (match-beginning 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
267 (match-end 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
268 (unless (equal str "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
269 (setq cmd (and (not (equal str "none"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
270 (intern str)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
271 (and (fboundp cmd) (not (arrayp (symbol-function cmd)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
272 (not (y-or-n-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
273 (format "Command %s is already defined; %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
274 cmd "proceed? ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
275 (keyboard-quit))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
276 t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
277 ((looking-at "Key:\\(.*\\)$")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
278 (when edmacro-store-hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
279 (error "\"Key\" line not allowed in this context"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
280 (let ((key (edmacro-parse-keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
281 (buffer-substring (match-beginning 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
282 (match-end 1)))))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
283 (unless (equal key [])
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
284 (if (equal key [?n ?o ?n ?e])
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
285 (setq no-keys t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
286 (push key keys)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
287 (let ((b (key-binding key)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
288 (and b (commandp b) (not (arrayp b))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
289 (or (not (fboundp b))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
290 (not (arrayp (symbol-function b))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
291 (not (y-or-n-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
292 (format "Key %s is already defined; %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
293 (edmacro-format-keys key 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
294 "proceed? ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
295 (keyboard-quit))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
296 t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
297 ((looking-at "Macro:[ \t\n]*")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
298 (goto-char (match-end 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
299 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
300 ((eobp) nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
301 (t (error "Expected a `Macro:' line")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
302 (forward-line 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
303 (setq top (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
304 (let* ((buf (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
305 (str (buffer-substring top (point-max)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
306 (modp (buffer-modified-p))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
307 (obuf edmacro-original-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
308 (store-hook edmacro-store-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
309 (finish-hook edmacro-finish-hook))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
310 (unless (or cmd keys store-hook (equal str ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
311 (error "No command name or keys specified"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
312 (when modp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
313 (when (buffer-name obuf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
314 (set-buffer obuf))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
315 (message "Compiling keyboard macro...")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
316 (let ((mac (edmacro-parse-keys str)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
317 (message "Compiling keyboard macro...done")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
318 (if store-hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
319 (funcall store-hook mac)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
320 (when (eq cmd 'last-kbd-macro)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
321 (setq last-kbd-macro (and (> (length mac) 0) mac))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
322 (setq cmd nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
323 (when cmd
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
324 (if (= (length mac) 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
325 (fmakunbound cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
326 (fset cmd mac)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
327 (if no-keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
328 (when cmd
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
329 (loop for key in (where-is-internal cmd) do
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
330 (global-unset-key key)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
331 (when keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
332 (if (= (length mac) 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
333 (loop for key in keys do (global-unset-key key))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
334 (loop for key in keys do
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
335 (global-set-key key (or cmd mac)))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
336 (kill-buffer buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
337 (when (buffer-name obuf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
338 (switch-to-buffer obuf))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
339 (when finish-hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
340 (funcall finish-hook)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
341
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
342 (defun edmacro-insert-key (key)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
343 "Insert the written name of a key in the buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
344 (interactive "kKey to insert: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
345 (if (bolp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
346 (insert (edmacro-format-keys key t) "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
347 (insert (edmacro-format-keys key) " ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
348
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
349 (defun edmacro-mode ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
350 "\\<edmacro-mode-map>Keyboard Macro Editing mode. Press
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
351 \\[edmacro-finish-edit] to save and exit.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
352 To abort the edit, just kill this buffer with \\[kill-buffer] RET.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
353
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
354 Press \\[edmacro-insert-key] to insert the name of any key by typing the key.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
355
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
356 The editing buffer contains a \"Command:\" line and any number of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
357 \"Key:\" lines at the top. These are followed by a \"Macro:\" line
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
358 and the macro itself as spelled-out keystrokes: `C-x C-f foo RET'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
359
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
360 The \"Command:\" line specifies the command name to which the macro
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
361 is bound, or \"none\" for no command name. Write \"last-kbd-macro\"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
362 to refer to the current keyboard macro (as used by \\[call-last-kbd-macro]).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
363
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
364 The \"Key:\" lines specify key sequences to which the macro is bound,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
365 or \"none\" for no key bindings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
366
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
367 You can edit these lines to change the places where the new macro
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
368 is stored.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
369
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
370
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
371 Format of keyboard macros during editing:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
372
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
373 Text is divided into \"words\" separated by whitespace. Except for
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
374 the words described below, the characters of each word go directly
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
375 as characters of the macro. The whitespace that separates words
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
376 is ignored. Whitespace in the macro must be written explicitly,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
377 as in \"foo SPC bar RET\".
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
378
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
379 * The special words RET, SPC, TAB, DEL, BS, LFD, ESC, and NUL represent
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
380 special control characters. The words must be written in uppercase.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
381
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
382 * A word in angle brackets, e.g., <return>, <down>, or <f1>, represents
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
383 a function key. (Note that in the standard configuration, the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
384 function key <return> and the control key RET are synonymous.)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
385 You can use angle brackets on the words RET, SPC, etc., but they
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
386 are not required there.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
387
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
388 * Keys can be written by their ASCII code, using a backslash followed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
389 by up to six octal digits. This is the only way to represent keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
390 with codes above \\377.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
391
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
392 * One or more prefixes M- (meta), C- (control), S- (shift), A- (alt),
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
393 H- (hyper), and s- (super) may precede a character or key notation.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
394 For function keys, the prefixes may go inside or outside of the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
395 brackets: C-<down> = <C-down>. The prefixes may be written in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
396 any order: M-C-x = C-M-x.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
397
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
398 Prefixes are not allowed on multi-key words, e.g., C-abc, except
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
399 that the Meta prefix is allowed on a sequence of digits and optional
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
400 minus sign: M--123 = M-- M-1 M-2 M-3.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
401
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
402 * The `^' notation for control characters also works: ^M = C-m.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
403
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
404 * Double angle brackets enclose command names: <<next-line>> is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
405 shorthand for M-x next-line RET.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
406
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
407 * Finally, REM or ;; causes the rest of the line to be ignored as a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
408 comment.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
409
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
410 Any word may be prefixed by a multiplier in the form of a decimal
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
411 number and `*': 3*<right> = <right> <right> <right>, and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
412 10*foo = foofoofoofoofoofoofoofoofoofoo.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
413
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
414 Multiple text keys can normally be strung together to form a word,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
415 but you may need to add whitespace if the word would look like one
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
416 of the above notations: `; ; ;' is a keyboard macro with three
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
417 semicolons, but `;;;' is a comment. Likewise, `\\ 1 2 3' is four
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
418 keys but `\\123' is a single key written in octal, and `< right >'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
419 is seven keys but `<right>' is a single function key. When in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
420 doubt, use whitespace."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
421 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
422 (error "This mode can be enabled only by `edit-kbd-macro'"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
423 (put 'edmacro-mode 'mode-class 'special)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
424
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
425
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
426 (defun edmacro-int-char (int)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
427 (if (fboundp 'char-to-int)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
428 (char-to-int int)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
429 int))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
430
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
431
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
432 ;;; Parsing a human-readable keyboard macro.
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
433
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
434 ;; Changes for XEmacs -- these two functions re-written from scratch.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
435 ;; edmacro-parse-keys always returns a vector. edmacro-format-keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
436 ;; accepts a vector (but works with a string too). Vector may contain
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
437 ;; keypress events. -hniksic
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
438 (defun edmacro-parse-keys (string &optional ignored)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
439 (let* ((pos 0)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
440 (case-fold-search nil)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
441 (word-to-sym '(("NUL" . ?\0)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
442 ("RET" . return)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
443 ("LFD" . linefeed)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
444 ("TAB" . tab)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
445 ("ESC" . escape)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
446 ("SPC" . space)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
447 ("BS" . backspace)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
448 ("DEL" . delete)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
449 (char-to-word '((?\0 . "NUL")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
450 (?\r . "RET")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
451 (?\n . "LFD")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
452 (?\t . "TAB")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
453 (?\e . "ESC")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
454 (?\ . "SPC")
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
455 (?\C-? . "DEL")))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
456 (modifier-prefix-alist '(("C" . control)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
457 ("M" . meta)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
458 ("S" . shift)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
459 ("Sh" . shift)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
460 ("A" . alt)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
461 ("H" . hyper)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
462 ("s" . super)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
463 ;; string-to-symbol-or-char converter
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
464 (conv (lambda (arg)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
465 (if (= (length arg) 1)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
466 (aref arg 0)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
467 (if (string-match "^<\\([^>]+\\)>$" arg)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
468 (setq arg (match-string 1 arg)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
469 (let ((match (assoc arg word-to-sym)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
470 (if match
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
471 (cdr match)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
472 (intern arg))))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
473 (conv-chars (lambda (arg)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
474 (let ((match (assoc arg char-to-word)))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
475 (if match
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
476 (cdr (assoc (cdr match) word-to-sym))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
477 arg))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
478 res)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
479 (while (and (< pos (length string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
480 (string-match "[^ \t\n\f]+" string pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
481 (let ((word (substring string (match-beginning 0) (match-end 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
482 (times 1)
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
483 (force-sym nil)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
484 (add nil)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
485 match)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
486 (setq pos (match-end 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
487 (when (string-match "\\([0-9]+\\)\\*." word)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
488 (setq times (string-to-int (substring word 0 (match-end 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
489 (setq word (substring word (1+ (match-end 1)))))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
490 (when (string-match "^<\\([^<>]+\\)>$" word)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
491 (setq word (match-string 1 word))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
492 (setq force-sym t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
493 (setq match (assoc word word-to-sym))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
494 ;; Add an element; `add' holds the list of elements to be
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
495 ;; added.
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
496 (cond ((string-match "^\\\\[0-7]+" word)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
497 ;; Octal value of character.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
498 (setq add
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
499 (list
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
500 (edmacro-int-char
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
501 (edmacro-octal-string-to-integer (substring word 1))))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
502 ((string-match "^<<.+>>$" word)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
503 ;; Extended command.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
504 (setq add
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
505 (nconc
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
506 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
507 (if (eq (key-binding [(meta x)])
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
508 'execute-extended-command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
509 '(meta x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
510 (or (car (where-is-internal
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
511 'execute-extended-command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
512 '(meta x))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
513 (mapcar conv-chars (concat (substring word 2 -2) "\r")))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
514 ))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
515 ((or (equal word "REM") (string-match "^;;" word))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
516 ;; Comment (discard to EOL) .
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
517 (setq pos (string-match "$" string pos)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
518 (match
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
519 ;; Convert to symbol.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
520 (setq add (list (cdr match))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
521 ((string-match "^\\^" word)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
522 ;; ^X == C-x
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
523 (if (/= (length word) 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
524 (error "^ must be followed by one character"))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
525 (setq add (list 'control (aref word 0))))
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
526 ((string-match "^\\([MCSsAH]\\|Sh\\)-" word)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
527 ;; Parse C-* and stuff
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
528 (setq
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
529 add
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
530 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
531 (let ((pos1 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
532 (r1 nil)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
533 follow curpart prefix)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
534 (while (progn (setq curpart (substring word pos1))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
535 (string-match "^\\([MCSsAH]\\|Sh\\)-"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
536 curpart))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
537 (setq prefix (assoc (match-string 1 curpart)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
538 modifier-prefix-alist))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
539 (setq r1 (nconc r1 (list (cdr prefix))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 24
diff changeset
540 (callf + pos1 (1+ (length (car prefix)))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
541 (setq follow (substring word pos1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
542 (if (equal follow "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
543 (error "%s must precede a string"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
544 (substring word 0 pos1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
545 (nconc r1 (list (funcall conv follow)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
546 (force-sym
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
547 ;; This must be a symbol
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
548 (setq add (list (intern word))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
549 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
550 ;; Characters
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
551 (setq add (mapcar conv-chars word))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
552 (let ((new nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
553 (loop repeat times do (setq new (append new add)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
554 (setq add new))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
555 (setq res (nconc res add))))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
556 (edmacro-mapvector 'identity res)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
557
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
558 (defun edmacro-conv (char-or-sym add-<>)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
559 (let ((char-to-word '((?\0 . "NUL")
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
560 (?\r . "RET")
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
561 (?\n . "LFD")
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
562 (?\t . "TAB")
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
563 (?\e . "ESC")
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
564 (?\ . "SPC")
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
565 (?\C-? . "DEL")))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
566 (symbol-to-char '((return . ?\r)
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
567 (linefeed . ?\n)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
568 (space . ?\ )
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
569 (delete . ?\C-?)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
570 (tab . ?\t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
571 (escape . ?\e))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
572 (if (symbolp char-or-sym)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
573 (if (= (length (symbol-name char-or-sym)) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
574 (setq char-or-sym (aref (symbol-name char-or-sym) 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
575 (let ((found (assq char-or-sym symbol-to-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
576 (if found
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
577 (setq char-or-sym (cdr found))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
578 ;; Return:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
579 (cons (symbolp char-or-sym)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
580 (if (symbolp char-or-sym)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
581 (if add-<>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
582 (concat "<" (symbol-name char-or-sym) ">")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
583 (symbol-name char-or-sym))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
584 (let ((found (assq char-or-sym char-to-word)))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
585 (cond (found
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
586 (cdr found))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
587 ((< char-or-sym 128)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
588 (single-key-description char-or-sym))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
589 ((and edmacro-eight-bits
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
590 (>= char-or-sym 128))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
591 (char-to-string char-or-sym))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
592 (t
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
593 (format "\\%o" (edmacro-int-char char-or-sym)))))))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
594
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
595 (defun edmacro-format-1 (keys command times togetherp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
596 (let ((res "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
597 (start keys)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
598 el)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
599 (while keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
600 (unless (or (eq start keys) togetherp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
601 (callf concat res " "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
602 (if (> times 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
603 (setq res (concat (format "%d*" times) res)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
604 (setq el (car keys))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
605 (callf concat res
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
606 (cond ((listp el)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
607 (let ((my ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
608 (if (or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
609 (let (cnv)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
610 (while el
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
611 (let ((found (assq (car el)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
612 '((control . "C-")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
613 (meta . "M-")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
614 (shift . "S-")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
615 (alt . "A-")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
616 (hyper . "H-")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
617 (super . "s-")))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
618 (callf concat my
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
619 (if found
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
620 (cdr found)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
621 (setq cnv (edmacro-conv (car el) nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
622 (cdr cnv))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
623 (setq el (cdr el)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
624 (car cnv))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
625 (> times 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
626 (concat "<" my ">")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
627 my)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
628 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
629 (cdr (edmacro-conv el t)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
630 (setq keys (cdr keys)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
631 (if command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
632 (callf concat res
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
633 (concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
634 (make-string (max (- 3 (/ (length res) tab-width)) 1) ?\t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
635 ";; "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
636 (symbol-name command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
637 (if togetherp (format " * %d" (length start))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
638 res))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
639
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
640 ;; Convert the keypress events in vector x to keys, and return a
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
641 ;; vector of keys. If a list element is not a keypress event, ignore
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
642 ;; it.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
643 (defun edmacro-events-to-keys (x)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
644 (if (or (not (fboundp 'events-to-keys))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
645 (not (arrayp x)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
646 x
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
647 (let ((cnt 0)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
648 (len (length x))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
649 new el)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
650 (while (< cnt len)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
651 (setq el (aref x cnt))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
652 (cond ((eventp el)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
653 (if (mouse-event-p el)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
654 (setq el nil)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
655 (setq el (aref (events-to-keys (vector el)) 0))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
656 (t
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
657 nil)) ; leave it be.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
658 (if el
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
659 (setq new (nconc new (list el))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
660 (incf cnt))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
661 (edmacro-mapvector 'identity new))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
662
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
663 ;; Collapse a list of keys into a list of function keys, where
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
664 ;; applicable.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
665 (defun edmacro-fkeys (keys)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
666 (let (new k lookup)
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
667 (while keys
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
668 (setq k (nconc k (list (car keys))))
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
669 (setq lookup (lookup-key function-key-map (edmacro-mapvector 'identity k)))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
670 (cond ((vectorp lookup)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
671 (setq new (nconc new (mapcar 'identity lookup)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
672 (setq k nil))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
673 ((keymapp lookup)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
674 nil)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
675 ((null lookup)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
676 (setq new (nconc new k))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
677 (setq k nil))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
678 (t
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
679 (setq k nil)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
680 (setq keys (cdr keys)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
681 (if (keymapp lookup)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
682 (setq new (nconc new k)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
683 new))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
684
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
685 ;;; Formatting a keyboard macro as human-readable text.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 134
diff changeset
686
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
687 (defun edmacro-format-keys (macro &optional verbose)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
688 ;; XEmacs:
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
689 ;; If we're dealing with events, convert them to symbols first.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
690 (setq macro (edmacro-events-to-keys macro))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
691 (if (zerop (length macro))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
692 ""
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
693 (let ((res ""))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
694 ;; I'm not sure I understand the original code, but this seems to
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
695 ;; work.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
696 (and (eq verbose 1)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
697 (setq verbose nil))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
698
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
699 ;; We prefer a list -- much easier to process...
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
700 (setq macro (mapcar 'identity macro))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
701 (setq macro (edmacro-fkeys macro))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
702 (while macro
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
703 (let (key lookup (times 1) self-insert-p)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
704 (loop do
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
705 (setq key (nconc key (list (car macro)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
706 macro (cdr macro)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
707 lookup (lookup-key global-map (edmacro-mapvector
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
708 'identity key)))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
709 while
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
710 (and macro lookup (not (commandp lookup))))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
711 ;; keyboard macro
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
712 (if (vectorp lookup)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
713 (setq lookup nil))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
714 (if (and (eq lookup 'self-insert-command)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
715 (= (length key) 1)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
716 (not (memq (car key)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
717 '(?\ ?\r ?\n space return linefeed tab))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
718 (while (and (< (length key) 23)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
719 (eq (lookup-key global-map (car macro))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
720 'self-insert-command)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
721 (not (memq
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
722 (car macro)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
723 '(?\ ?\r ?\n space return linefeed tab))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
724 (setq key (nconc key (list (car macro)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
725 macro (cdr macro)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
726 self-insert-p t))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
727 (while (edmacro-seq-equal key macro)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
728 (setq macro (nthcdr (length key) macro))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
729 (incf times)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
730 (if (or self-insert-p
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
731 (null (cdr key))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
732 (= times 1))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
733 (callf concat res (edmacro-format-1 key (if verbose lookup
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
734 nil)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
735 times self-insert-p)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
736 (and macro (if verbose "\n" " ")))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
737 (loop repeat times
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
738 do
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
739 (callf concat res
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
740 (edmacro-format-1 key (if verbose lookup
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
741 nil)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
742 1 self-insert-p)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
743 (and macro (if verbose "\n" " ")))))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
744 res)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
745
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
746 (defun edmacro-seq-equal (seq1 seq2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
747 (while (and seq1 seq2
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
748 (equal (car seq1) (car seq2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
749 (setq seq1 (cdr seq1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
750 seq2 (cdr seq2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
751 (not seq1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
752
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
753 (defsubst edmacro-oct-char-to-integer (character)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
754 "Take a char and return its value as if it was a octal digit."
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
755 (if (and (>= character ?0) (<= character ?7))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
756 (- character ?0)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
757 (error (format "Invalid octal digit `%c'." character))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
758
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
759 (defun edmacro-octal-string-to-integer (octal-string)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
760 "Return decimal integer for OCTAL-STRING."
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
761 (interactive "sOctal number: ")
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
762 (let ((oct-num 0))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
763 (while (not (equal octal-string ""))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
764 (setq oct-num (+ (* oct-num 8)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
765 (edmacro-oct-char-to-integer
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
766 (string-to-char octal-string))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
767 (setq octal-string (substring octal-string 1)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
768 oct-num))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
769
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
770
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
771 (defun edmacro-fix-menu-commands (macro)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
772 (when (vectorp macro)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
773 (let ((i 0) ev)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
774 (while (< i (length macro))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
775 (when (and (consp (setq ev (aref macro i)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
776 (not (memq (car ev) ; ha ha
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 118
diff changeset
777 '(hyper super meta alt control shift))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
778 (cond ((equal (cadadr ev) '(menu-bar))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
779 (setq macro (vconcat (edmacro-subseq macro 0 i)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
780 (vector 'menu-bar (car ev))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
781 (edmacro-subseq macro (1+ i))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
782 (incf i))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
783 ;; It would be nice to do pop-up menus, too, but not enough
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
784 ;; info is recorded in macros to make this possible.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
785 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
786 (error "Macros with mouse clicks are not %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
787 "supported by this command"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
788 (incf i))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
789 macro)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
790
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
791
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
792 ;;; The following probably ought to go in macros.el:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
793
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
794 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
795 (defun insert-kbd-macro (macroname &optional keys)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
796 "Insert in buffer the definition of kbd macro NAME, as Lisp code.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
797 Optional second arg KEYS means also record the keys it is on
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
798 \(this is the prefix argument, when calling interactively).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
799
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
800 This Lisp code will, when executed, define the kbd macro with the same
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
801 definition it has now. If you say to record the keys, the Lisp code
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
802 will also rebind those keys to the macro. Only global key bindings
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
803 are recorded since executing this Lisp code always makes global
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
804 bindings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
805
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
806 To save a kbd macro, visit a file of Lisp code such as your `~/.emacs',
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
807 use this command, and then save the file."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
808 (interactive "CInsert kbd macro (name): \nP")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
809 (let (definition)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
810 (if (string= (symbol-name macroname) "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
811 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
812 (setq definition (format-kbd-macro))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
813 (insert "(setq last-kbd-macro"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
814 (setq definition (format-kbd-macro macroname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
815 (insert (format "(defalias '%s" macroname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
816 (if (> (length definition) 50)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
817 (insert " (read-kbd-macro\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
818 (insert "\n (read-kbd-macro "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
819 (prin1 definition (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
820 (insert "))\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
821 (if keys
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
822 (let ((keys (where-is-internal macroname)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
823 (while keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
824 (insert (format "(global-set-key %S '%s)\n" (car keys) macroname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
825 (setq keys (cdr keys)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
826
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
827 (provide 'edmacro)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
828
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
829 ;;; edmacro.el ends here