annotate lisp/prim/macros.el @ 16:0293115a14e9 r19-15b91

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