annotate lisp/utils/edmacro.el @ 118:7d55a9ba150c r20-1b11

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