annotate lisp/edmacro.el @ 1028:508bb8dd1e88

Formerly GETTING.GNU.SOFTWARE.~3~
author gnulists <gnulists>
date Fri, 21 Aug 1992 23:06:13 +0000
parents 213978acbc1e
children 2c7997f249eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
1 ;;; edmacro.el --- keyboard macro editor
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
2
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
3 ;; Copyright (C) 1990 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
5 ;; Author: Dave Gillespie <daveg@csvax.caltech.edu>
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
6 ;; Maintainer: FSF
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
7 ;; Version: 1.02
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
8
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
10
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
14 ;; any later version.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
15
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
20
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
24
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
25 ;;; Commentary:
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
26
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
27 ;; To use, type `M-x edit-last-kbd-macro' to edit the most recently
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
28 ;; defined keyboard macro. If you have used `M-x name-last-kbd-macro'
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
29 ;; to give a keyboard macro a name, type `M-x edit-kbd-macro' to edit
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
30 ;; the macro by name. When you are done editing, type `C-c C-c' to
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
31 ;; record your changes back into the original keyboard macro.
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
32
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
33 ;;; Code:
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
34
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
35 ;;; The user-level commands for editing macros.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
36
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 199
diff changeset
37 ;;;###autoload
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
38 (defun edit-last-kbd-macro (&optional prefix buffer hook)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
39 "Edit the most recently defined keyboard macro."
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
40 (interactive "P")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
41 (edmacro-edit-macro last-kbd-macro
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
42 (function (lambda (x arg) (setq last-kbd-macro x)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
43 prefix buffer hook))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
44
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 199
diff changeset
45 ;;;###autoload
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
46 (defun edit-kbd-macro (cmd &optional prefix buffer hook in-hook out-hook)
199
b3710ab30435 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 109
diff changeset
47 "Edit a keyboard macro which has been given a name by `name-last-kbd-macro'.
b3710ab30435 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 109
diff changeset
48 \(See also `edit-last-kbd-macro'.)"
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
49 (interactive "CCommand name: \nP")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
50 (and cmd
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
51 (edmacro-edit-macro (if in-hook
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
52 (funcall in-hook cmd)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
53 (symbol-function cmd))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
54 (or out-hook
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
55 (list 'lambda '(x arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
56 (list 'fset
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
57 (list 'quote cmd)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
58 'x)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
59 prefix buffer hook cmd)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
60
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 199
diff changeset
61 ;;;###autoload
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
62 (defun read-kbd-macro (start end)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
63 "Read the region as a keyboard macro definition.
199
b3710ab30435 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 109
diff changeset
64 The region is interpreted as spelled-out keystrokes, e.g., \"M-x abc RET\".
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
65 The resulting macro is installed as the \"current\" keyboard macro.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
66
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
67 Symbols: RET, SPC, TAB, DEL, LFD, NUL; C-key; M-key. (Must be uppercase.)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
68 REM marks the rest of a line as a comment.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
69 Whitespace is ignored; other characters are copied into the macro."
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
70 (interactive "r")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
71 (setq last-kbd-macro (edmacro-parse-keys (buffer-substring start end)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
72 (if (and (string-match "\\`\C-x(" last-kbd-macro)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
73 (string-match "\C-x)\\'" last-kbd-macro))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
74 (setq last-kbd-macro (substring last-kbd-macro 2 -2))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
75
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
76 ;;; Formatting a keyboard macro as human-readable text.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
77
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
78 (defun edmacro-print-macro (macro-str local-map)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
79 (let ((save-map (current-local-map))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
80 (print-escape-newlines t)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
81 key-symbol key-str key-last prefix-arg this-prefix)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
82 (unwind-protect
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
83 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
84 (use-local-map local-map)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
85 (while (edmacro-peek-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
86 (edmacro-read-key)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
87 (setq this-prefix prefix-arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
88 (or (memq key-symbol '(digit-argument
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
89 negative-argument
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
90 universal-argument))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
91 (null prefix-arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
92 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
93 (cond ((consp prefix-arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
94 (insert (format "prefix-arg (%d)\n"
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
95 (car prefix-arg))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
96 ((eq prefix-arg '-)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
97 (insert "prefix-arg -\n"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
98 ((numberp prefix-arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
99 (insert (format "prefix-arg %d\n" prefix-arg))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
100 (setq prefix-arg nil)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
101 (cond ((null key-symbol)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
102 (insert "type \"")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
103 (edmacro-insert-string macro-str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
104 (insert "\"\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
105 (setq macro-str ""))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
106 ((eq key-symbol 'digit-argument)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
107 (edmacro-prefix-arg key-last nil prefix-arg))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
108 ((eq key-symbol 'negative-argument)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
109 (edmacro-prefix-arg ?- nil prefix-arg))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
110 ((eq key-symbol 'universal-argument)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
111 (let* ((c-u 4) (argstartchar key-last)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
112 (char (edmacro-read-char)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
113 (while (= char argstartchar)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
114 (setq c-u (* 4 c-u)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
115 char (edmacro-read-char)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
116 (edmacro-prefix-arg char c-u nil)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
117 ((eq key-symbol 'self-insert-command)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
118 (insert "insert ")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
119 (if (and (>= key-last 32) (<= key-last 126))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
120 (let ((str ""))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
121 (while (or (and (eq key-symbol
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
122 'self-insert-command)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
123 (< (length str) 60)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
124 (>= key-last 32)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
125 (<= key-last 126))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
126 (and (memq key-symbol
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
127 '(backward-delete-char
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
128 delete-backward-char
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
129 backward-delete-char-untabify))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
130 (> (length str) 0)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
131 (if (eq key-symbol 'self-insert-command)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
132 (setq str (concat str
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
133 (char-to-string key-last)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
134 (setq str (substring str 0 -1)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
135 (edmacro-read-key))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
136 (insert "\"" str "\"\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
137 (edmacro-unread-chars key-str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
138 (insert "\"")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
139 (edmacro-insert-string (char-to-string key-last))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
140 (insert "\"\n")))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
141 ((and (eq key-symbol 'quoted-insert)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
142 (edmacro-peek-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
143 (insert "quoted-insert\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
144 (let ((ch (edmacro-read-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
145 ch2)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
146 (if (and (>= ch ?0) (<= ch ?7))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
147 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
148 (setq ch (- ch ?0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
149 ch2 (edmacro-read-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
150 (if ch2
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
151 (if (and (>= ch2 ?0) (<= ch2 ?7))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
152 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
153 (setq ch (+ (* ch 8) (- ch2 ?0))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
154 ch2 (edmacro-read-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
155 (if ch2
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
156 (if (and (>= ch2 ?0) (<= ch2 ?7))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
157 (setq ch (+ (* ch 8) (- ch2 ?0)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
158 (edmacro-unread-chars ch2))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
159 (edmacro-unread-chars ch2)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
160 (if (or (and (>= ch ?0) (<= ch ?7))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
161 (< ch 32) (> ch 126))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
162 (insert (format "type \"\\%03o\"\n" ch))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
163 (insert "type \"" (char-to-string ch) "\"\n"))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
164 ((memq key-symbol '(isearch-forward
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
165 isearch-backward
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
166 isearch-forward-regexp
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
167 isearch-backward-regexp))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
168 (insert (symbol-name key-symbol) "\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
169 (edmacro-isearch-argument))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
170 ((eq key-symbol 'execute-extended-command)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
171 (edmacro-read-argument obarray 'commandp))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
172 (t
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
173 (let ((cust (get key-symbol 'edmacro-print)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
174 (if cust
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
175 (funcall cust)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
176 (insert (symbol-name key-symbol))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
177 (indent-to 30)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
178 (insert " # ")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
179 (edmacro-insert-string key-str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
180 (insert "\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
181 (let ((int (edmacro-get-interactive key-symbol)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
182 (if (string-match "\\`\\*" int)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
183 (setq int (substring int 1)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
184 (while (> (length int) 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
185 (cond ((= (aref int 0) ?a)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
186 (edmacro-read-argument
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
187 obarray nil))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
188 ((memq (aref int 0) '(?b ?B ?D ?f ?F ?n
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
189 ?s ?S ?x ?X))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
190 (edmacro-read-argument))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
191 ((and (= (aref int 0) ?c)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
192 (edmacro-peek-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
193 (insert "type \"")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
194 (edmacro-insert-string
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
195 (char-to-string
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
196 (edmacro-read-char)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
197 (insert "\"\n"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
198 ((= (aref int 0) ?C)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
199 (edmacro-read-argument
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
200 obarray 'commandp))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
201 ((= (aref int 0) ?k)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
202 (edmacro-read-key)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
203 (if key-symbol
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
204 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
205 (insert "type \"")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
206 (edmacro-insert-string key-str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
207 (insert "\"\n"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
208 (edmacro-unread-chars key-str)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
209 ((= (aref int 0) ?N)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
210 (or this-prefix
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
211 (edmacro-read-argument)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
212 ((= (aref int 0) ?v)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
213 (edmacro-read-argument
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
214 obarray 'user-variable-p)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
215 (let ((nl (string-match "\n" int)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
216 (setq int (if nl
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
217 (substring int (1+ nl))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
218 "")))))))))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
219 (use-local-map save-map))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
220
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
221 (defun edmacro-prefix-arg (char c-u value)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
222 (let ((sign 1))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
223 (if (and (numberp value) (< value 0))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
224 (setq sign -1 value (- value)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
225 (if (eq value '-)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
226 (setq sign -1 value nil))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
227 (while (and char (= ?- char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
228 (setq sign (- sign) c-u nil)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
229 (setq char (edmacro-read-char)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
230 (while (and char (>= char ?0) (<= char ?9))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
231 (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)) c-u nil)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
232 (setq char (edmacro-read-char)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
233 (setq prefix-arg
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
234 (cond (c-u (list c-u))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
235 ((numberp value) (* value sign))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
236 ((= sign -1) '-)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
237 (edmacro-unread-chars char)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
238
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
239 (defun edmacro-insert-string (str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
240 (let ((i 0) j ch)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
241 (while (< i (length str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
242 (if (and (> (setq ch (aref str i)) 127)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
243 (< ch 160))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
244 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
245 (setq ch (- ch 128))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
246 (insert "\\M-")))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
247 (if (< ch 32)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
248 (cond ((= ch 8) (insret "\\b"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
249 ((= ch 9) (insert "\\t"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
250 ((= ch 10) (insert "\\n"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
251 ((= ch 13) (insert "\\r"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
252 ((= ch 27) (insert "\\e"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
253 (t (insert "\\C-" (char-to-string (downcase (+ ch 64))))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
254 (if (< ch 127)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
255 (if (or (= ch 34) (= ch 92))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
256 (insert "\\" (char-to-string ch))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
257 (setq j i)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
258 (while (and (< (setq i (1+ i)) (length str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
259 (>= (setq ch (aref str i)) 32)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
260 (/= ch 34) (/= ch 92)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
261 (< ch 127)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
262 (insert (substring str j i))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
263 (setq i (1- i)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
264 (if (memq ch '(127 255))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
265 (insert (format "\\%03o" ch))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
266 (insert "\\M-" (char-to-string (- ch 128))))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
267 (setq i (1+ i)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
268
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
269 (defun edmacro-lookup-key (map)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
270 (let ((loc (and map (lookup-key map macro-str)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
271 (glob (lookup-key (current-global-map) macro-str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
272 (loc-str macro-str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
273 (glob-str macro-str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
274 (and (integerp loc)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
275 (setq loc-str (substring macro-str 0 loc)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
276 loc (lookup-key map loc-str)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
277 (and (consp loc)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
278 (setq loc nil))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
279 (or loc
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
280 (setq loc-str ""))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
281 (and (integerp glob)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
282 (setq glob-str (substring macro-str 0 glob)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
283 glob (lookup-key (current-global-map) glob-str)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
284 (and (consp glob)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
285 (setq glob nil))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
286 (or glob
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
287 (setq glob-str ""))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
288 (if (> (length glob-str) (length loc-str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
289 (setq key-symbol glob
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
290 key-str glob-str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
291 (setq key-symbol loc
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
292 key-str loc-str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
293 (setq key-last (and (> (length key-str) 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
294 (logand (aref key-str (1- (length key-str))) 127)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
295 key-symbol))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
296
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
297 (defun edmacro-read-argument (&optional obarray pred) ;; currently ignored
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
298 (let ((str "")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
299 (min-bsp 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
300 (exec (eq key-symbol 'execute-extended-command))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
301 str-base)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
302 (while (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
303 (edmacro-lookup-key (current-global-map))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
304 (or (and (eq key-symbol 'self-insert-command)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
305 (< (length str) 60))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
306 (memq key-symbol
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
307 '(backward-delete-char
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
308 delete-backward-char
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
309 backward-delete-char-untabify))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
310 (eq key-last 9)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
311 (setq macro-str (substring macro-str (length key-str)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
312 (or (and (eq key-last 9)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
313 obarray
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
314 (let ((comp (try-completion str obarray pred)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
315 (and (stringp comp)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
316 (> (length comp) (length str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
317 (setq str comp))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
318 (if (or (eq key-symbol 'self-insert-command)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
319 (and (or (eq key-last 9)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
320 (<= (length str) min-bsp))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
321 (setq min-bsp (+ (length str) (length key-str)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
322 (setq str (concat str key-str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
323 (setq str (substring str 0 -1)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
324 (setq str-base str
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
325 str (concat str key-str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
326 macro-str (substring macro-str (length key-str)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
327 (if exec
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
328 (let ((comp (try-completion str-base obarray pred)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
329 (if (if (stringp comp)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
330 (and (commandp (intern comp))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
331 (setq str-base comp))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
332 (commandp (intern str-base)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
333 (insert str-base "\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
334 (insert "execute-extended-command\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
335 (insert "type \"")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
336 (edmacro-insert-string str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
337 (insert "\"\n")))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
338 (if (> (length str) 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
339 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
340 (insert "type \"")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
341 (edmacro-insert-string str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
342 (insert "\"\n"))))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
343
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
344 (defun edmacro-isearch-argument ()
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
345 (let ((str "")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
346 (min-bsp 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
347 ch)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
348 (while (and (setq ch (edmacro-read-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
349 (or (<= ch 127) (not search-exit-option))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
350 (not (eq ch search-exit-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
351 (or (eq ch search-repeat-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
352 (eq ch search-reverse-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
353 (eq ch search-delete-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
354 (eq ch search-yank-word-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
355 (eq ch search-yank-line-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
356 (eq ch search-quote-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
357 (eq ch ?\r)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
358 (eq ch ?\t)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
359 (not search-exit-option)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
360 (and (/= ch 127) (>= ch 32))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
361 (if (and (eq ch search-quote-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
362 (edmacro-peek-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
363 (setq str (concat str (char-to-string ch)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
364 (char-to-string (edmacro-read-char)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
365 min-bsp (length str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
366 (if (or (and (< ch 127) (>= ch 32))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
367 (eq ch search-yank-word-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
368 (eq ch search-yank-line-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
369 (and (or (not (eq ch search-delete-char))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
370 (<= (length str) min-bsp))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
371 (setq min-bsp (1+ (length str)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
372 (setq str (concat str (char-to-string ch)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
373 (setq str (substring str 0 -1)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
374 (if (eq ch search-exit-char)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
375 (if (= (length str) 0) ;; non-incremental search
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
376 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
377 (setq str (concat str (char-to-string ch)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
378 (and (eq (edmacro-peek-char) ?\C-w)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
379 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
380 (setq str (concat str "\C-w"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
381 (edmacro-read-char)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
382 (if (> (length str) 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
383 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
384 (insert "type \"")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
385 (edmacro-insert-string str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
386 (insert "\"\n")))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
387 (edmacro-read-argument)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
388 (setq str "")))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
389 (edmacro-unread-chars ch))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
390 (if (> (length str) 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
391 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
392 (insert "type \"")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
393 (edmacro-insert-string str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
394 (insert "\\e\"\n")))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
395
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
396 ;;; Get the next keystroke-sequence from the input stream.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
397 ;;; Sets key-symbol, key-str, and key-last as a side effect.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
398 (defun edmacro-read-key ()
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
399 (edmacro-lookup-key (current-local-map))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
400 (and key-symbol
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
401 (setq macro-str (substring macro-str (length key-str)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
402
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
403 (defun edmacro-peek-char ()
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
404 (and (> (length macro-str) 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
405 (aref macro-str 0)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
406
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
407 (defun edmacro-read-char ()
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
408 (and (> (length macro-str) 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
409 (prog1
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
410 (aref macro-str 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
411 (setq macro-str (substring macro-str 1)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
412
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
413 (defun edmacro-unread-chars (chars)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
414 (and (integerp chars)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
415 (setq chars (char-to-string chars)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
416 (and chars
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
417 (setq macro-str (concat chars macro-str))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
418
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
419 (defun edmacro-dump (mac)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
420 (set-mark-command nil)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
421 (insert "\n\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
422 (edmacro-print-macro mac (current-local-map)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
423
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
424 ;;; Parse a string of spelled-out keystrokes, as produced by key-description.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
425
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
426 (defun edmacro-parse-keys (str)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
427 (let ((pos 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
428 (mac "")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
429 part)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
430 (while (and (< pos (length str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
431 (string-match "[^ \t\n]+" str pos))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
432 (setq pos (match-end 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
433 part (substring str (match-beginning 0) (match-end 0))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
434 mac (concat mac
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
435 (if (and (> (length part) 2)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
436 (= (aref part 1) ?-)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
437 (= (aref part 0) ?M))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
438 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
439 (setq part (substring part 2))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
440 "\e")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
441 (if (and (> (length part) 4)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
442 (= (aref part 0) ?C)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
443 (= (aref part 1) ?-)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
444 (= (aref part 2) ?M)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
445 (= (aref part 3) ?-))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
446 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
447 (setq part (concat "C-" (substring part 4)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
448 "\e")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
449 ""))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
450 (or (cdr (assoc part '( ( "NUL" . "\0" )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
451 ( "RET" . "\r" )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
452 ( "LFD" . "\n" )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
453 ( "TAB" . "\t" )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
454 ( "ESC" . "\e" )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
455 ( "SPC" . " " )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
456 ( "DEL" . "\177" )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
457 ( "C-?" . "\177" )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
458 ( "C-2" . "\0" )
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
459 ( "C-SPC" . "\0") )))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
460 (and (equal part "REM")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
461 (setq pos (or (string-match "\n" str pos)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
462 (length str)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
463 "")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
464 (and (= (length part) 3)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
465 (= (aref part 0) ?C)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
466 (= (aref part 1) ?-)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
467 (char-to-string (logand (aref part 2) 31)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
468 part))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
469 mac))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
470
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
471 ;;; Parse a keyboard macro description in edmacro-print-macro's format.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
472
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
473 (defun edmacro-read-macro (&optional map)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
474 (or map (setq map (current-local-map)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
475 (let ((macro-str ""))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
476 (while (not (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
477 (skip-chars-forward " \t\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
478 (eobp)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
479 (cond ((looking-at "#")) ;; comment
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
480 ((looking-at "prefix-arg[ \t]*-[ \t]*\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
481 (edmacro-append-chars "\C-u-"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
482 ((looking-at "prefix-arg[ \t]*\\(-?[0-9]+\\)[ \t]*\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
483 (edmacro-append-chars (concat "\C-u" (edmacro-match-string 1))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
484 ((looking-at "prefix-arg[ \t]*(\\([0-9]+\\))[ \t]*\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
485 (let ((val (string-to-int (edmacro-match-string 1))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
486 (while (> val 1)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
487 (or (= (% val 4) 0)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
488 (error "Bad prefix argument value"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
489 (edmacro-append-chars "\C-u")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
490 (setq val (/ val 4)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
491 ((looking-at "prefix-arg")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
492 (error "Bad prefix argument syntax"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
493 ((looking-at "insert ")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
494 (forward-char 7)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
495 (edmacro-append-chars (read (current-buffer)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
496 (if (< (current-column) 7)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
497 (forward-line -1)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
498 ((looking-at "type ")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
499 (forward-char 5)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
500 (edmacro-append-chars (read (current-buffer)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
501 (if (< (current-column) 5)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
502 (forward-line -1)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
503 ((looking-at "keys \\(.*\\)\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
504 (goto-char (1- (match-end 0)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
505 (edmacro-append-chars (edmacro-parse-keys
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
506 (buffer-substring (match-beginning 1)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
507 (match-end 1)))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
508 ((looking-at "\\([-a-zA-z0-9_]+\\)[ \t]*\\(.*\\)\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
509 (let* ((func (intern (edmacro-match-string 1)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
510 (arg (edmacro-match-string 2))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
511 (cust (get func 'edmacro-read)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
512 (if cust
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
513 (funcall cust arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
514 (or (commandp func)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
515 (error "Not an Emacs command"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
516 (or (equal arg "")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
517 (string-match "\\`#" arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
518 (error "Unexpected argument to command"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
519 (let ((keys
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
520 (or (where-is-internal func map t)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
521 (where-is-internal func (current-global-map) t))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
522 (if keys
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
523 (edmacro-append-chars keys)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
524 (edmacro-append-chars (concat "\ex"
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
525 (symbol-name func)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
526 "\n")))))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
527 (t (error "Syntax error")))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
528 (forward-line 1))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
529 macro-str))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
530
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
531 (defun edmacro-append-chars (chars)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
532 (setq macro-str (concat macro-str chars)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
533
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
534 (defun edmacro-match-string (n)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
535 (if (match-beginning n)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
536 (buffer-substring (match-beginning n) (match-end n))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
537 ""))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
538
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
539 (defun edmacro-get-interactive (func)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
540 (if (symbolp func)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
541 (let ((cust (get func 'edmacro-interactive)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
542 (if cust
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
543 cust
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
544 (edmacro-get-interactive (symbol-function func))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
545 (or (and (eq (car-safe func) 'lambda)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
546 (let ((int (if (consp (nth 2 func))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
547 (nth 2 func)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
548 (nth 3 func))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
549 (and (eq (car-safe int) 'interactive)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
550 (stringp (nth 1 int))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
551 (nth 1 int))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
552 "")))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
553
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
554 (put 'search-forward 'edmacro-interactive "s")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
555 (put 'search-backward 'edmacro-interactive "s")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
556 (put 'word-search-forward 'edmacro-interactive "s")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
557 (put 'word-search-backward 'edmacro-interactive "s")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
558 (put 're-search-forward 'edmacro-interactive "s")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
559 (put 're-search-backward 'edmacro-interactive "s")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
560 (put 'switch-to-buffer 'edmacro-interactive "B")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
561 (put 'kill-buffer 'edmacro-interactive "B")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
562 (put 'rename-buffer 'edmacro-interactive "B\nB")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
563 (put 'goto-char 'edmacro-interactive "N")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
564 (put 'global-set-key 'edmacro-interactive "k\nC")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
565 (put 'global-unset-key 'edmacro-interactive "k")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
566 (put 'local-set-key 'edmacro-interactive "k\nC")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
567 (put 'local-unset-key 'edmacro-interactive "k")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
568
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
569 ;;; Think about kbd-macro-query
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
570
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
571 ;;; Edit a keyboard macro in another buffer.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
572 ;;; (Prefix argument is currently ignored.)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
573
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
574 (defun edmacro-edit-macro (mac repl &optional prefix buffer hook arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
575 (or (stringp mac)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
576 (error "Not a keyboard macro"))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
577 (let ((oldbuf (current-buffer))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
578 (local (current-local-map))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
579 (buf (get-buffer-create (or buffer "*Edit Macro*"))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
580 (set-buffer buf)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
581 (kill-all-local-variables)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
582 (use-local-map edmacro-mode-map)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
583 (setq buffer-read-only nil
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
584 major-mode 'edmacro-mode
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
585 mode-name "Edit Macro")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
586 (set (make-local-variable 'edmacro-original-buffer) oldbuf)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
587 (set (make-local-variable 'edmacro-replace-function) repl)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
588 (set (make-local-variable 'edmacro-replace-argument) arg)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
589 (set (make-local-variable 'edmacro-finish-hook) hook)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
590 (erase-buffer)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
591 (insert "# Keyboard Macro Editor. Press C-c C-c to finish; press C-x k RET to cancel.\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
592 (insert "# Original keys: " (key-description mac) "\n\n")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
593 (message "Formatting keyboard macro...")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
594 (edmacro-print-macro mac local)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
595 (switch-to-buffer buf)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
596 (goto-char (point-min))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
597 (forward-line 3)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
598 (recenter '(4))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
599 (set-buffer-modified-p nil)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
600 (message "Formatting keyboard macro...done")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
601 (run-hooks 'edmacro-format-hook)))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
602
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
603 (defun edmacro-finish-edit ()
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
604 (interactive)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
605 (or (and (boundp 'edmacro-original-buffer)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
606 (boundp 'edmacro-replace-function)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
607 (boundp 'edmacro-replace-argument)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
608 (boundp 'edmacro-finish-hook)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
609 (eq major-mode 'edmacro-mode))
199
b3710ab30435 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 109
diff changeset
610 (error "This command is valid only in buffers created by `edit-kbd-macro'."))
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
611 (let ((buf (current-buffer))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
612 (str (buffer-string))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
613 (func edmacro-replace-function)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
614 (arg edmacro-replace-argument)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
615 (hook edmacro-finish-hook))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
616 (goto-char (point-min))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
617 (run-hooks 'edmacro-compile-hook)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
618 (and (buffer-modified-p)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
619 func
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
620 (progn
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
621 (message "Compiling keyboard macro...")
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
622 (let ((mac (edmacro-read-macro
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
623 (and (buffer-name edmacro-original-buffer)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
624 (save-excursion
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
625 (set-buffer edmacro-original-buffer)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
626 (current-local-map))))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
627 (and (buffer-name edmacro-original-buffer)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
628 (switch-to-buffer edmacro-original-buffer))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
629 (funcall func mac arg))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
630 (message "Compiling keyboard macro...done")))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
631 (kill-buffer buf)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
632 (if hook
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
633 (funcall hook arg))))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
634
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
635 (defun edmacro-mode ()
199
b3710ab30435 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 109
diff changeset
636 "\\<edmacro-mode-map>Keyboard Macro Editing mode. Press \\[edmacro-finish-edit] to save and exit.
b3710ab30435 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 109
diff changeset
637 To abort the edit, just kill this buffer with \\[kill-buffer] RET.
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
638
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
639 The keyboard macro is represented as a series of M-x style command names.
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
640 Keystrokes which do not correspond to simple M-x commands are written as
199
b3710ab30435 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 109
diff changeset
641 \"type\" commands. When you press \\[edmacro-finish-edit], edmacro converts each command
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
642 back into a suitable keystroke sequence; \"type\" commands are converted
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
643 directly back into keystrokes."
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
644 (interactive)
199
b3710ab30435 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 109
diff changeset
645 (error "This mode can be enabled only by `edit-kbd-macro' or `edit-last-kbd-macro'."))
109
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
646 (put 'edmacro-mode 'mode-class 'special)
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
647
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
648 (if (boundp 'edmacro-mode-map) ()
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
649 (setq edmacro-mode-map (make-sparse-keymap))
d649664df7e0 Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
650 (define-key edmacro-mode-map "\C-c\C-c" 'edmacro-finish-edit))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
651
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
652 ;;; edmacro.el ends here