annotate lisp/prim/macros.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; macros.el --- non-primitive commands for keyboard macros.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 92, 94, 95 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Extension commands for keyboard macros. These permit you to assign
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; a name to the last-defined keyboard macro, expand and insert the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; lisp corresponding to a macro, query the user from within a macro,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; or apply a macro to each line in the reason.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (defun name-last-kbd-macro (symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 "Assign a name to the last keyboard macro defined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 Argument SYMBOL is the name to define.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 The symbol's function definition becomes the keyboard macro string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 Such a \"function\" cannot be called from Lisp, but it is a valid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 editor command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (interactive "SName for last kbd macro: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (or last-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (error "No keyboard macro defined"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (and (fboundp symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (not (stringp (symbol-function symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (not (vectorp (symbol-function symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (error "Function %s is already defined and not a keyboard macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (fset symbol last-kbd-macro))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defun insert-kbd-macro-pretty-string (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Convert control characters to the traditional readable representation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; put the four characters \M-x in the buffer instead of the one char \370,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; which would deceptively print as `oslash' with the default settings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (narrow-to-region (point) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (prin1 string (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (goto-char (1+ (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (cond ((= (following-char) 0) (insert "\\C-@") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ((= (following-char) ?\n) (insert "\\n") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ((= (following-char) ?\r) (insert "\\r") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ((= (following-char) ?\t) (insert "\\t") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ((= (following-char) ?\e) (insert "\\e") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ((= (following-char) 127) (insert "\\C-?") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ((= (following-char) 128) (insert "\\M-\\C-@") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ((= (following-char) 255) (insert "\\M-\\C-?") (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ((and (> (following-char) 127) (< (following-char) 155))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (insert "\\M-\\C-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (insert (- (following-char) 32))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ((and (>= (following-char) 155) (< (following-char) 160))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (insert "\\M-\\C-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (insert (- (following-char) 64))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ((>= (following-char) 160)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (insert "\\M-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (insert (- (following-char) 128))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ((< (following-char) 27)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;(insert "\\^") (insert (+ (following-char) 64))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (insert "\\C-") (insert (+ (following-char) 96))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ((< (following-char) 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;(insert "\\^") (insert (+ (following-char) 64))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (insert "\\C-") (insert (+ (following-char) 64))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (forward-char 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defun insert-kbd-macro (macroname &optional keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 "Insert in buffer the definition of kbd macro NAME, as Lisp code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 Optional second argument KEYS means also record the keys it is on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 \(this is the prefix argument, when calling interactively).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 This Lisp code will, when executed, define the kbd macro with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 same definition it has now. If you say to record the keys,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 the Lisp code will also rebind those keys to the macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Only global key bindings are recorded since executing this Lisp code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 always makes global bindings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 To save a kbd macro, visit a file of Lisp code such as your `~/.emacs',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 use this command, and then save the file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (interactive "CInsert kbd macro (name): \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (let (definition)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (if (string= (symbol-name macroname) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (setq macroname 'last-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 definition last-kbd-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (insert "(setq "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (setq definition (symbol-function macroname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (insert "(fset '")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (prin1 macroname (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (insert "\n ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (let ((string (events-to-keys definition t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if (stringp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (insert-kbd-macro-pretty-string string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (prin1 string (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (insert ")\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (if keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (let ((keys (where-is-internal macroname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (while keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (insert "(global-set-key ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (prin1 (car keys) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (insert " '")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (prin1 macroname (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (insert ")\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (setq keys (cdr keys)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defun kbd-macro-query (flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "Query user during kbd macro execution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 With prefix argument, enters recursive edit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 reading keyboard commands even within a kbd macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 You can give different commands each time the macro executes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Without prefix argument, asks whether to continue running the macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Your options are: \\<query-replace-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 \\[act] Finish this iteration normally and continue with the next.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 \\[skip] Skip the rest of this iteration, and start the next.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 \\[exit] Stop the macro entirely right now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 \\[recenter] Redisplay the frame, then ask again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 \\[edit] Enter recursive edit; ask again when you exit from that."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (or executing-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 defining-kbd-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (error "Not defining or executing kbd macro"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (if flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let (executing-macro defining-kbd-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (recursive-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if (not executing-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (let ((loop t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (msg (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "Proceed with macro?\\<query-replace-map>\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (\\[act], \\[skip], \\[exit], \\[recenter], \\[edit]) ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (while loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (let ((key (let ((executing-macro nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (defining-kbd-macro nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (message msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (setq key (vector key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq def (lookup-key query-replace-map key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (cond ((eq def 'act)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (setq loop nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ((eq def 'skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (setq loop nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (setq executing-macro ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ((eq def 'exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq loop nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (setq executing-macro t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ((eq def 'recenter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (recenter nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ((eq def 'edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (let (executing-macro defining-kbd-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (recursive-edit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ((eq def 'quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setq quit-flag t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (or (eq def 'help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (princ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 "Specify how to proceed with keyboard macro execution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 Possibilities: \\<query-replace-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 \\[act] Finish this iteration normally and continue with the next.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 \\[skip] Skip the rest of this iteration, and start the next.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 \\[exit] Stop the macro entirely right now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 \\[recenter] Redisplay the frame, then ask again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 \\[edit] Enter recursive edit; ask again when you exit from that."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (help-mode)))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defun apply-macro-to-region-lines (top bottom &optional macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "For each complete line between point and mark, move to the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 of the line, and run the last keyboard macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 When called from lisp, this function takes two arguments TOP and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 BOTTOM, describing the current region. TOP must be before BOTTOM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 The optional third argument MACRO specifies a keyboard macro to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 execute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 This is useful for quoting or unquoting included text, adding and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 removing comments, or producing tables where the entries are regular.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 For example, in Usenet articles, sections of text quoted from another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 author are indented, or have each line start with `>'. To quote a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 section of text, define a keyboard macro which inserts `>', put point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 and mark at opposite ends of the quoted section, and use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 `\\[apply-macro-to-region-lines]' to mark the entire section.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 Suppose you wanted to build a keyword table in C where each entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 looked like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 { \"foo\", foo_data, foo_function },
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 { \"bar\", bar_data, bar_function },
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 { \"baz\", baz_data, baz_function },
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 You could enter the names in this format:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 bar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 baz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 and write a macro to massage a word into a table entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 \\C-x (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 \\M-d { \"\\C-y\", \\C-y_data, \\C-y_function },
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 \\C-x )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 and then select the region of un-tablified names and use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 `\\[apply-macro-to-region-lines]' to build the table from the names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (or macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (if (null last-kbd-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (error "No keyboard macro has been defined."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq macro last-kbd-macro)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (let ((end-marker (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (goto-char bottom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 next-line-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (goto-char top)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if (not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (setq next-line-marker (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (while (< next-line-marker end-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (goto-char next-line-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (set-marker next-line-marker (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (execute-kbd-macro (or macro last-kbd-macro))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (set-marker end-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (set-marker next-line-marker nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;;; macros.el ends here