annotate lisp/edmacro.el @ 837:a8aef92e0025

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