annotate lisp/edmacro.el @ 551:36827ee0a6df

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