annotate lisp/prim/macros.el @ 22:8fc7fe29b841 r19-15b94

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