annotate lisp/kmacro.el @ 47358:fb6838a09b61

(transient-mark-mode): Delete. Done in simple.el.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 09 Sep 2002 23:18:20 +0000
parents 5a8754f590f4
children 5e3418a37a64
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1 ;;; kmacro.el --- enhanced keyboard macros
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
2
46085
33538dc6ac79 Fixed copyright and keywords.
Kim F. Storm <storm@cua.dk>
parents: 46083
diff changeset
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
4
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
5 ;; Author: Kim F. Storm <storm@cua.dk>
46085
33538dc6ac79 Fixed copyright and keywords.
Kim F. Storm <storm@cua.dk>
parents: 46083
diff changeset
6 ;; Keywords: keyboard convenience
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
7
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
9
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
13 ;; any later version.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
14
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
18 ;; GNU General Public License for more details.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
19
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
24
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
25 ;;; Commentary:
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
26
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
27 ;; The kmacro package is an alternative user interface to emacs'
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
28 ;; keyboard macro functionality. This functionality is normally bound
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
29 ;; to C-x (, C-x ), and C-x e, but these bindings are too hard to
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
30 ;; type to be really useful for doing small repeated tasks.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
31
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
32 ;; With kmacro, two function keys are dedicated to keyboard macros,
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
33 ;; by default F3 and F4. Personally, I prefer F1 and F2, but those
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
34 ;; keys already have default bindings.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
35 ;;
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
36 ;; To start defining a keyboard macro, use F3. To end the macro,
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
37 ;; use F4, and to call the macro also use F4. This makes it very
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
38 ;; easy to repeat a macro immediately after defining it.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
39 ;;
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
40 ;; You can call the macro repeatedly by pressing F4 multiple times, or
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
41 ;; you can give a numeric prefix argument specifying the number of
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
42 ;; times to repeat the macro. Macro execution automatically
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
43 ;; terminates when point reaches the end of the buffer or if an error
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
44 ;; is signalled by ringing the bell.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
45
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
46 ;; When you define a macro with F3/F4, it is automatically added to
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
47 ;; the head of the "keyboard macro ring", and F4 actually executes the
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
48 ;; first element of the macro ring.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
49 ;;
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
50 ;; Note: an empty macro is never added to the macro ring.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
51 ;;
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
52 ;; You can execute the second element on the macro ring with C-u F4 or
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
53 ;; C-x C-k C-l, you can use C-x C-k C-p and C-x C-k C-n to cycle
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
54 ;; through the macro ring, and you can swap the first and second
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
55 ;; elements with C-x C-k C-t. To delete the first element in the
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
56 ;; macro ring, use C-x C-k C-d.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
57 ;;
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
58 ;;
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
59 ;; You can also use C-x C-k C-s to start a macro, and C-x C-k C-k to
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
60 ;; end it; then use C-k to execute it immediately, or C-x C-k C-k to
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
61 ;; execute it later.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
62 ;;
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
63 ;; In general, immediately after using C-x C-k followed by one of C-k,
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
64 ;; C-l, C-p, or C-n, you can further cycle the macro ring using C-p or
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
65 ;; C-n, execute the first or second macro using C-k or C-l, delete
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
66 ;; the head macro with C-d, or edit the current macro with C-e without
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
67 ;; repeating the C-x C-k prefix.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
68
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
69 ;; If you enter F3 while defining the macro, the numeric value of
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
70 ;; `kmacro-counter' is inserted using the `kmacro-counter-format', and
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
71 ;; `kmacro-counter' is incremented by 1 (or the numeric prefix value
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
72 ;; of F3).
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
73 ;;
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
74 ;; The initial value of `kmacro-counter' is 0, or the numeric prefix
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
75 ;; value given to F3 when starting the macro.
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
76 ;;
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
77 ;; Now, each time you call the macro using F4, the current
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
78 ;; value of `kmacro-counter' is inserted and incremented, making it
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
79 ;; easy to insert incremental numbers in the buffer.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
80 ;;
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
81 ;; Example:
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
82 ;;
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
83 ;; The following sequence: M-5 F3 x M-2 F3 y F4 F4 F4 F4
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
84 ;; inserts the following string: x5yx7yx9yx11y
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
85
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
86 ;; A macro can also be called using a mouse click, default S-mouse-3.
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
87 ;; This calls the macro at the point where you click the mouse.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
88
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
89 ;; You can edit the last macro using C-x C-k C-e.
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
90
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
91 ;; You can append to the last macro using C-u F3.
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
92
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
93 ;; You can set the macro counter using C-x C-k C-c, add to it using C-x C-k C-a,
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
94 ;; and you can set the macro counter format with C-x C-k C-f.
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
95
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
96 ;; The following key bindings are performed:
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
97 ;;
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
98 ;; Normal While defining macro
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
99 ;; --------------------------- ------------------------------
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
100 ;; f3 Define macro Insert current counter value
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
101 ;; Prefix arg specifies initial and increase counter by prefix
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
102 ;; counter value (default 0) (default increment: 1)
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
103 ;;
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
104 ;; C-u f3 APPENDs to last macro
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
105 ;;
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
106 ;; f4 Call last macro End macro
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
107 ;; Prefix arg specifies number
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
108 ;; of times to execute macro.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
109 ;;
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
110 ;; C-u f4 Swap last and head of macro ring.
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
111 ;;
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
112 ;; S-mouse-3 Set point at click and End macro and execute macro at
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
113 ;; execute last macro. click.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
114
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
115 ;;; Code:
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
116
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
117 ;; Customization:
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
118
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
119 (defgroup kmacro nil
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
120 "Simplified keyboard macro user interface."
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
121 :group 'keyboard
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
122 :group 'convenience
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
123 :link '(emacs-commentary-link :tag "Commentary" "kmacro.el")
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
124 :link '(emacs-library-link :tag "Lisp File" "kmacro.el"))
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
125
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
126 (defcustom kmacro-call-mouse-event 'S-mouse-3
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
127 "The mouse event used by kmacro to call a macro.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
128 Set to nil if no mouse binding is desired."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
129 :type 'symbol
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
130 :group 'kmacro)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
131
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
132 (defcustom kmacro-ring-max 8
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
133 "Maximum number of keyboard macros to save in macro ring."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
134 :type 'integer
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
135 :group 'kmacro)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
136
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
137
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
138 (defcustom kmacro-execute-before-append t
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
139 "Controls whether appending to a macro starts by executing the macro.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
140 If non-nil, using a single \\[universal-argument] prefix executes the macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
141 before appending, while more than one \\[universal-argument] prefix does not
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
142 execute the macro.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
143 Otherwise, a single \\[universal-argument] prefix does not execute the
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
144 macro, while more than one \\[universal-argument] prefix causes the
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
145 macro to be executed before appending to it."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
146 :type 'boolean
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
147 :group 'kmacro)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
148
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
149
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
150 (defcustom kmacro-repeat-no-prefix t
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
151 "Allow repeating certain macro commands without entering the C-x C-k prefix."
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
152 :type 'boolean
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
153 :group 'kmacro)
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
154
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
155 (defcustom kmacro-call-repeat-key t
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
156 "Allow repeating macro call using last key or a specific key."
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
157 :type '(choice (const :tag "Disabled" nil)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
158 (const :tag "Last key" t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
159 (character :tag "Character" :value ?e)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
160 (symbol :tag "Key symbol" :value RET))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
161 :group 'kmacro)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
162
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
163 (defcustom kmacro-call-repeat-with-arg nil
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
164 "Repeat macro call with original arg when non-nil; repeat once if nil."
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
165 :type 'boolean
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
166 :group 'kmacro)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
167
47310
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
168 (defcustom kmacro-step-edit-mini-window-height 0.75
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
169 "Override `max-mini-window-height' when step edit keyboard macro."
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
170 :type 'number
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
171 :group 'kmacro)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
172
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
173 ;; Keymap
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
174
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
175 (defvar kmacro-keymap
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
176 (let ((map (make-sparse-keymap)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
177 (define-key map "\C-s" 'kmacro-start-macro)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
178 (define-key map "\C-k" 'kmacro-end-or-call-macro-repeat)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
179 (define-key map "\C-e" 'kmacro-edit-macro-repeat)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
180 (define-key map "\r" 'kmacro-edit-macro)
47310
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
181 (define-key map " " 'kmacro-step-edit-macro)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
182 (define-key map "l" 'kmacro-edit-lossage)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
183 (define-key map "\C-i" 'kmacro-insert-counter)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
184 (define-key map "\C-a" 'kmacro-add-counter)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
185 (define-key map "\C-v" 'kmacro-view-macro-repeat)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
186 (define-key map "\C-l" 'kmacro-call-ring-2nd-repeat)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
187 (define-key map "\C-r" 'kmacro-view-ring-2nd)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
188 (define-key map "\C-n" 'kmacro-cycle-ring-next)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
189 (define-key map "\C-p" 'kmacro-cycle-ring-previous)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
190 (define-key map "\C-f" 'kmacro-set-format)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
191 (define-key map "\C-c" 'kmacro-set-counter)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
192 (define-key map "\C-t" 'kmacro-swap-ring)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
193 (define-key map "\C-b" 'kmacro-bind-to-key)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
194 (define-key map "\C-d" 'kmacro-delete-ring-head)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
195 ;; Compatibility bindings
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
196 (define-key map "q" 'kbd-macro-query)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
197 (define-key map "n" 'name-last-kbd-macro)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
198 (define-key map "e" 'edit-kbd-macro)
46972
88b4ed0b18c9 Bind C-x C-k r to apply-macro-to-region-lines.
Kim F. Storm <storm@cua.dk>
parents: 46961
diff changeset
199 (define-key map "r" 'apply-macro-to-region-lines)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
200 map)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
201 "Keymap for keyboard macro commands.")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
202 (defalias 'kmacro-keymap kmacro-keymap)
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
203
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
204 ;;; Provide some binding for startup:
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
205 ;;;###autoload (global-set-key "\C-x(" 'kmacro-start-macro)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
206 ;;;###autoload (global-set-key "\C-x)" 'kmacro-end-macro)
47310
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
207 ;;;###autoload (global-set-key "\C-xe" 'kmacro-end-and-call-macro)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
208 ;;;###autoload (global-set-key [f3] 'kmacro-start-macro-or-insert-counter)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
209 ;;;###autoload (global-set-key [f4] 'kmacro-end-or-call-macro)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
210 ;;;###autoload (global-set-key "\C-x\C-k" 'kmacro-keymap)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
211 ;;;###autoload (autoload 'kmacro-keymap "kmacro" "Keymap for keyboard macro commands." t 'keymap)
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
212
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
213 (if kmacro-call-mouse-event
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
214 (global-set-key (vector kmacro-call-mouse-event) 'kmacro-end-call-mouse))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
215
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
216
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
217
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
218 ;;; Keyboard macro counter
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
219
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
220 (defvar kmacro-counter 0
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
221 "*Current keyboard macro counter.")
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
222
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
223 (defvar kmacro-counter-format "%d"
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
224 "*Current keyboard macro counter format.")
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
225
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
226 (defvar kmacro-counter-format-start kmacro-counter-format
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
227 "Macro format at start of macro execution.")
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
228
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
229 (defvar kmacro-counter-value-start kmacro-counter
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
230 "Macro counter at start of macro execution.")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
231
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
232 (defvar kmacro-last-counter 0 "Last counter inserted by key macro.")
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
233
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
234
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
235 (defun kmacro-insert-counter (arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
236 "Insert macro counter and increment with ARG or 1 if missing.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
237 With \\[universal-argument], insert previous kmacro-counter (but do not modify counter)."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
238 (interactive "P")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
239 (if (and arg (listp arg))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
240 (insert (format kmacro-counter-format kmacro-last-counter))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
241 (insert (format kmacro-counter-format kmacro-counter))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
242 (kmacro-add-counter (prefix-numeric-value arg))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
243
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
244
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
245 (defun kmacro-set-format (format)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
246 "Set macro counter FORMAT."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
247 (interactive "sMacro Counter Format (printf format): ")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
248 (setq kmacro-counter-format
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
249 (if (equal format "") "%d" format))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
250 ;; redefine initial macro counter if we are not executing a macro.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
251 (if (not (or defining-kbd-macro executing-kbd-macro))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
252 (setq kmacro-counter-format-start kmacro-counter-format)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
253
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
254
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
255 (defun kmacro-display-counter (&optional value)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
256 "Display current counter value."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
257 (unless value (setq value kmacro-counter))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
258 (message "New macro counter value: %s (%d)" (format kmacro-counter-format value) value))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
259
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
260
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
261 (defun kmacro-set-counter (arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
262 "Set kmacro-counter to ARG or prompt if missing.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
263 With \\[universal-argument], reset counter to its value prior to this iteration of the macro."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
264 (interactive "NMacro counter value: ")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
265 (setq kmacro-last-counter kmacro-counter
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
266 kmacro-counter (if (and current-prefix-arg (listp current-prefix-arg))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
267 kmacro-counter-value-start
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
268 arg))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
269 (unless executing-kbd-macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
270 (kmacro-display-counter)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
271
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
272
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
273 (defun kmacro-add-counter (arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
274 "Add numeric prefix arg (prompt if missing) to macro counter.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
275 With \\[universal-argument], restore previous counter value."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
276 (interactive "NAdd to macro counter: ")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
277 (let ((last kmacro-last-counter))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
278 (setq kmacro-last-counter kmacro-counter
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
279 kmacro-counter (if (and current-prefix-arg (listp current-prefix-arg))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
280 last
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
281 kmacro-counter (+ kmacro-counter arg))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
282 (unless executing-kbd-macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
283 (kmacro-display-counter)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
284
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
285
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
286 (defun kmacro-loop-setup-function ()
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
287 "Function called prior to each iteration of macro."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
288 ;; Restore macro counter format to initial format, so it is ok to change
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
289 ;; counter format in the macro without restoring it.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
290 (setq kmacro-counter-format kmacro-counter-format-start)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
291 ;; Save initial counter value so we can restore it with C-u kmacro-set-counter.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
292 (setq kmacro-counter-value-start kmacro-counter)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
293 ;; Return non-nil to continue execution.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
294 t)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
295
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
296
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
297 ;;; Keyboard macro ring
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
298
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
299 (defvar kmacro-ring nil
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
300 "The keyboard macro ring.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
301 Each element is a list (MACRO COUNTER FORMAT). Actually, the head of
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
302 the macro ring (when defining or executing) is not stored in the ring;
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
303 instead it is available in the variables `last-kbd-macro', `kmacro-counter',
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
304 and `kmacro-counter-format'.")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
305
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
306
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
307 (defun kmacro-ring-head ()
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
308 "Return pseudo head element in macro ring."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
309 (and last-kbd-macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
310 (list last-kbd-macro kmacro-counter kmacro-counter-format-start)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
311
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
312
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
313 (defun kmacro-push-ring (&optional elt)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
314 "Push ELT or current macro onto `kmacro-ring'."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
315 (when (setq elt (or elt (kmacro-ring-head)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
316 (let ((len (length kmacro-ring)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
317 (setq kmacro-ring (cons elt kmacro-ring))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
318 (if (>= len kmacro-ring-max)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
319 (setcdr (nthcdr len kmacro-ring) nil)))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
320
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
321
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
322 (defun kmacro-split-ring-element (elt)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
323 (setq last-kbd-macro (car elt)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
324 kmacro-counter (nth 1 elt)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
325 kmacro-counter-format-start (nth 2 elt)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
326
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
327
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
328 (defun kmacro-pop-ring1 (&optional raw)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
329 "Pop head element off macro ring (no check).
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
330 Non-nil arg RAW means just return raw first element."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
331 (prog1 (car kmacro-ring)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
332 (unless raw
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
333 (kmacro-split-ring-element (car kmacro-ring)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
334 (setq kmacro-ring (cdr kmacro-ring))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
335
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
336
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
337 (defun kmacro-pop-ring (&optional raw)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
338 "Pop head element off macro ring.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
339 Non-nil arg RAW means just return raw first element."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
340 (unless (kmacro-ring-empty-p)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
341 (kmacro-pop-ring1 raw)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
342
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
343
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
344 (defun kmacro-ring-length ()
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
345 "Return length of macro ring, including pseudo head."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
346 (+ (if last-kbd-macro 1 0) (length kmacro-ring)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
347
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
348
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
349 (defun kmacro-ring-empty-p (&optional none)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
350 "Tell user and return t if `last-kbd-macro' is nil or `kmacro-ring' is empty.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
351 Check only `last-kbd-macro' if optional arg NONE is non-nil."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
352 (while (and (null last-kbd-macro) kmacro-ring)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
353 (kmacro-pop-ring1))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
354 (cond
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
355 ((null last-kbd-macro)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
356 (message "No keyboard macro defined.")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
357 t)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
358 ((and (null none) (null kmacro-ring))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
359 (message "Only one keyboard macro defined.")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
360 t)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
361 (t nil)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
362
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
363
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
364 (defun kmacro-display (macro &optional trunc descr empty )
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
365 "Display a keyboard MACRO."
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
366 (if macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
367 (let* ((x 60)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
368 (m (format-kbd-macro macro))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
369 (l (length m))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
370 (z (and nil trunc (> l x))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
371 (message (format "%s: %s%s" (or descr "Macro")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
372 (if z (substring m 0 (1- x)) m) (if z "..." ""))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
373 (message (or empty "No keyboard macros defined"))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
374
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
375
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
376 (defun kmacro-repeat-on-last-key (keys)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
377 "Process kmacro commands keys immidiately after cycling the ring."
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
378 (setq keys (vconcat keys))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
379 (let ((n (1- (length keys)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
380 cmd done repeat)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
381 (while (and last-kbd-macro
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
382 (not done)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
383 (aset keys n (read-event))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
384 (setq cmd (key-binding keys t))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
385 (setq repeat (get cmd 'kmacro-repeat)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
386 (clear-this-command-keys t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
387 (cond
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
388 ((eq repeat 'ring)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
389 (if kmacro-ring
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
390 (let ((kmacro-repeat-no-prefix nil))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
391 (funcall cmd nil))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
392 (kmacro-display last-kbd-macro t)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
393 ((eq repeat 'head)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
394 (let ((kmacro-repeat-no-prefix nil))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
395 (funcall cmd nil)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
396 ((eq repeat 'stop)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
397 (funcall cmd nil)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
398 (setq done t)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
399 (setq last-input-event nil)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
400 (when last-input-event
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
401 (clear-this-command-keys t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
402 (setq unread-command-events (list last-input-event))))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
403
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
404
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
405 (defun kmacro-get-repeat-prefix ()
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
406 (let (keys)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
407 (and kmacro-repeat-no-prefix
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
408 (setq keys (this-single-command-keys))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
409 (> (length keys) 1)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
410 keys)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
411
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
412
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
413 (defun kmacro-call-ring-2nd (arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
414 "Execute second keyboard macro at in macro ring."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
415 (interactive "P")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
416 (unless (kmacro-ring-empty-p)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
417 ;; should use counter format specific to the macro on the ring!
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
418 (let ((kmacro-counter (nth 1 (car kmacro-ring)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
419 (kmacro-counter-format-start (nth 2 (car kmacro-ring))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
420 (execute-kbd-macro (car (car kmacro-ring)) arg #'kmacro-loop-setup-function)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
421 (setcar (cdr (car kmacro-ring)) kmacro-counter))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
422
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
423
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
424 (defun kmacro-call-ring-2nd-repeat (arg)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
425 "Like `kmacro-call-ring-2nd', but allow repeat without repeating prefix."
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
426 (interactive "P")
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
427 (let ((keys (kmacro-get-repeat-prefix)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
428 (kmacro-call-ring-2nd arg)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
429 (if (and kmacro-ring keys)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
430 (kmacro-repeat-on-last-key keys))))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
431
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
432 (put 'kmacro-call-ring-2nd-repeat 'kmacro-repeat 'head)
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
433
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
434
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
435 (defun kmacro-view-ring-2nd ()
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
436 "Display the current head of the keyboard macro ring."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
437 (interactive)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
438 (unless (kmacro-ring-empty-p)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
439 (kmacro-display (car (car kmacro-ring)) "2nd macro")))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
440
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
441
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
442
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
443 (defun kmacro-cycle-ring-next (&optional arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
444 "Move to next keyboard macro in keyboard macro ring.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
445 Displays the selected macro in the echo area."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
446 (interactive)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
447 (unless (kmacro-ring-empty-p)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
448 (kmacro-push-ring)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
449 (let* ((keys (kmacro-get-repeat-prefix))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
450 (len (length kmacro-ring))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
451 (tail (nthcdr (- len 2) kmacro-ring))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
452 (elt (car (cdr tail))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
453 (setcdr tail nil)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
454 (kmacro-split-ring-element elt)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
455 (kmacro-display last-kbd-macro t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
456 (if keys
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
457 (kmacro-repeat-on-last-key keys)))))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
458
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
459 (put 'kmacro-cycle-ring-next 'kmacro-repeat 'ring)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
460
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
461
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
462 (defun kmacro-cycle-ring-previous (&optional arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
463 "Move to previous keyboard macro in keyboard macro ring.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
464 Displays the selected macro in the echo area."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
465 (interactive)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
466 (unless (kmacro-ring-empty-p)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
467 (let ((keys (kmacro-get-repeat-prefix))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
468 (cur (kmacro-ring-head)))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
469 (kmacro-pop-ring1)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
470 (if kmacro-ring
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
471 (nconc kmacro-ring (list cur))
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
472 (setq kmacro-ring (list cur)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
473 (kmacro-display last-kbd-macro t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
474 (if keys
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
475 (kmacro-repeat-on-last-key keys)))))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
476
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
477 (put 'kmacro-cycle-ring-previous 'kmacro-repeat 'ring)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
478
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
479
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
480 (defun kmacro-swap-ring ()
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
481 "Swap first two elements on keyboard macro ring."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
482 (interactive)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
483 (unless (kmacro-ring-empty-p)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
484 (let ((cur (kmacro-ring-head)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
485 (kmacro-pop-ring1)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
486 (kmacro-push-ring cur))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
487 (kmacro-display last-kbd-macro t)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
488
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
489
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
490 (defun kmacro-delete-ring-head (&optional arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
491 "Delete current macro from keyboard macro ring."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
492 (interactive)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
493 (unless (kmacro-ring-empty-p t)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
494 (if (null kmacro-ring)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
495 (setq last-kbd-macro nil)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
496 (kmacro-pop-ring))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
497 (kmacro-display last-kbd-macro t nil "Keyboard macro ring is now empty.")))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
498
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
499 (put 'kmacro-delete-ring-head 'kmacro-repeat 'head)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
500
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
501 ;;; Traditional bindings:
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
502
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
503
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
504 ;;;###autoload
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
505 (defun kmacro-start-macro (arg)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
506 "Record subsequent keyboard input, defining a keyboard macro.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
507 The commands are recorded even as they are executed.
47051
11f467f2a131 (kmacro-start-macro): Doc fix.
Andreas Schwab <schwab@suse.de>
parents: 46972
diff changeset
508 Use \\[kmacro-end-macro] to finish recording and make the macro available.
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
509 Use \\[call-last-kbd-macro] to execute the macro.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
510 Use \\[name-last-kbd-macro] to give it a permanent name.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
511 Non-nil arg (prefix arg) means append to last macro defined;
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
512
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
513 With \\[universal-argument] prefix, append to last keyboard macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
514 defined. Depending on `kmacro-execute-before-append', this may begin
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
515 by re-executing the last macro as if you typed it again.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
516
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
517 Otherwise, it sets `kmacro-counter' to ARG or 0 if missing before
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
518 defining the macro.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
519
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
520 Use \\[kmacro-insert-counter] to insert (and increment) the macro counter.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
521 The counter value can be set or modified via \\[kmacro-set-counter] and \\[kmacro-add-counter].
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
522 The format of the counter can be modified via \\[kmacro-set-format]."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
523 (interactive "P")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
524 (if (or defining-kbd-macro executing-kbd-macro)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
525 (message "Already defining keyboard macro.")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
526 (let ((append (and arg (listp arg))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
527 (unless append
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
528 (if last-kbd-macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
529 (let ((len (length kmacro-ring)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
530 (setq kmacro-ring
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
531 (cons
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
532 (list last-kbd-macro kmacro-counter kmacro-counter-format-start)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
533 kmacro-ring))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
534 (if (>= len kmacro-ring-max)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
535 (setcdr (nthcdr len kmacro-ring) nil))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
536 (setq kmacro-counter (if arg (prefix-numeric-value arg) 0)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
537 kmacro-counter-value-start kmacro-counter
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
538 kmacro-last-counter kmacro-counter
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
539 kmacro-counter-format-start kmacro-counter-format))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
540
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
541 (start-kbd-macro append
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
542 (and append
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
543 (if kmacro-execute-before-append
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
544 (> (car arg) 4)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
545 (= (car arg) 4)))))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
546
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
547
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
548 ;;;###autoload
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
549 (defun kmacro-end-macro (arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
550 "Finish defining a keyboard macro.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
551 The definition was started by \\[kmacro-start-macro].
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
552 The macro is now available for use via \\[kmacro-call-macro],
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
553 or it can be given a name with \\[name-last-kbd-macro] and then invoked
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
554 under that name.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
555
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
556 With numeric arg, repeat macro now that many times,
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
557 counting the definition just completed as the first repetition.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
558 An argument of zero means repeat until error."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
559 (interactive "P")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
560 (end-kbd-macro arg #'kmacro-loop-setup-function)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
561 (when (and last-kbd-macro (= (length last-kbd-macro) 0))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
562 (message "Ignore empty macro")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
563 (kmacro-pop-ring)))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
564
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
565
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
566 ;;;###autoload
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
567 (defun kmacro-call-macro (arg &optional no-repeat end-macro)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
568 "Call the last keyboard macro that you defined with \\[kmacro-start-macro].
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
569 A prefix argument serves as a repeat count. Zero means repeat until error.
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
570
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
571 When you call the macro, you can call the macro again by repeating
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
572 just the last key in the key sequence that you used to call this
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
573 command. See `kmacro-call-repeat-key' and `kmacro-call-repeat-with-arg'
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
574 for details on how to adjust or disable this behaviour.
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
575
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
576 To make a macro permanent so you can call it even after defining
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
577 others, use M-x name-last-kbd-macro."
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
578 (interactive "p")
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
579 (let ((repeat-key (and (null no-repeat)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
580 (> (length (this-single-command-keys)) 1)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
581 last-input-event))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
582 repeat-key-str)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
583 (if end-macro
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
584 (kmacro-end-macro arg)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
585 (call-last-kbd-macro arg #'kmacro-loop-setup-function))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
586 (when (and (or (null arg) (> arg 0))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
587 (setq repeat-key
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
588 (if (eq kmacro-call-repeat-key t) repeat-key kmacro-call-repeat-key)))
47310
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
589 (setq repeat-key-str (format-kbd-macro (vector repeat-key) nil))
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
590 (while repeat-key
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
591 (message "Repeat macro %swith `%s'..."
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
592 (if (and kmacro-call-repeat-with-arg
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
593 arg (> arg 1))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
594 (format "%d times " arg) "")
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
595 repeat-key-str)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
596 (if (equal repeat-key (read-event))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
597 (progn
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
598 (clear-this-command-keys t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
599 (call-last-kbd-macro (and kmacro-call-repeat-with-arg arg) #'kmacro-loop-setup-function)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
600 (setq last-input-event nil))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
601 (setq repeat-key nil)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
602 (when last-input-event
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
603 (clear-this-command-keys t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
604 (setq unread-command-events (list last-input-event))))))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
605
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
606
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
607 ;;; Combined function key bindings:
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
608
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
609 ;;;###autoload
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
610 (defun kmacro-start-macro-or-insert-counter (arg)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
611 "Record subsequent keyboard input, defining a keyboard macro.
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
612 The commands are recorded even as they are executed.
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
613
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
614 Sets the `kmacro-counter' to ARG (or 0 if no prefix arg) before defining the
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
615 macro.
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
616
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
617 With \\[universal-argument], appends to current keyboard macro (keeping
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
618 the current value of `kmacro-counter').
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
619
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
620 When defining/executing macro, inserts macro counter and increments
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
621 the counter with ARG or 1 if missing. With \\[universal-argument],
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
622 inserts previous kmacro-counter (but do not modify counter).
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
623
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
624 The macro counter can be modified via \\[kmacro-set-counter] and \\[kmacro-add-counter].
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
625 The format of the counter can be modified via \\[kmacro-set-format]."
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
626 (interactive "P")
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
627 (if (or defining-kbd-macro executing-kbd-macro)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
628 (kmacro-insert-counter arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
629 (kmacro-start-macro arg)))
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
630
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
631
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
632 ;;;###autoload
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
633 (defun kmacro-end-or-call-macro (arg &optional no-repeat)
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
634 "End kbd macro if currently being defined; else call last kbd macro.
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
635 With numeric prefix ARG, repeat macro that many times.
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
636 With \\[universal-argument], call second macro in macro ring."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
637 (interactive "P")
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
638 (cond
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
639 (defining-kbd-macro
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
640 (if kmacro-call-repeat-key
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
641 (kmacro-call-macro arg no-repeat t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
642 (kmacro-end-macro arg)))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
643 ((and arg (listp arg))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
644 (kmacro-call-ring-2nd 1))
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
645 (t
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
646 (kmacro-call-macro arg no-repeat))))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
647
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
648
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
649 (defun kmacro-end-or-call-macro-repeat (arg)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
650 "As `kmacro-end-or-call-macro' but allows repeat without repeating prefix."
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
651 (interactive "P")
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
652 (let ((keys (kmacro-get-repeat-prefix)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
653 (kmacro-end-or-call-macro arg t)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
654 (if keys
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
655 (kmacro-repeat-on-last-key keys))))
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
656
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
657 (put 'kmacro-end-or-call-macro-repeat 'kmacro-repeat 'head)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
658
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
659
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
660 ;;;###autoload
47310
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
661 (defun kmacro-end-and-call-macro (arg &optional no-repeat)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
662 "Call last keyboard macro, ending it first if currently being defined.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
663 With numeric prefix ARG, repeat macro that many times."
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
664 (interactive "P")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
665 (if defining-kbd-macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
666 (kmacro-end-macro nil))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
667 (kmacro-call-macro arg no-repeat))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
668
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
669
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
670 ;;;###autoload
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
671 (defun kmacro-end-call-mouse (event)
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
672 "Move point to the position clicked with the mouse and call last kbd macro.
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
673 If kbd macro currently being defined end it before activating it."
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
674 (interactive "e")
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
675 (when defining-kbd-macro
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
676 (end-kbd-macro))
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
677 (mouse-set-point event)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
678 (kmacro-call-macro nil t))
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
679
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
680
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
681 ;;; Misc. commands
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
682
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
683 (defun kmacro-bind-to-key (arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
684 "When not defining or executing a macro, offer to bind last macro to a key."
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
685 (interactive "p")
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
686 (if (or defining-kbd-macro executing-kbd-macro)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
687 (if defining-kbd-macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
688 (message "Cannot save macro while defining it."))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
689 (unless last-kbd-macro
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
690 (error "No keyboard macro defined"))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
691 (let ((key-seq (read-key-sequence "Bind last macro to key: ")))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
692 (unless (equal key-seq "")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
693 (define-key global-map key-seq last-kbd-macro)))))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
694
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
695
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
696 (defun kmacro-view-macro (&optional arg)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
697 "Display the last keyboard macro."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
698 (interactive)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
699 (kmacro-display last-kbd-macro))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
700
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
701
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
702 (defun kmacro-view-macro-repeat (&optional arg)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
703 "Like `kmacro-view-macro', but allow repeat without repeating prefix."
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
704 (interactive)
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
705 (let ((keys (kmacro-get-repeat-prefix)))
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
706 (kmacro-view-macro arg)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
707 (if (and last-kbd-macro keys)
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
708 (kmacro-repeat-on-last-key keys))))
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
709
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
710 (put 'kmacro-view-macro-repeat 'kmacro-repeat 'head)
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
711
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
712
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
713 (defun kmacro-edit-macro-repeat (&optional arg)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
714 "Edit last keyboard macro."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
715 (interactive "P")
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
716 (edit-kbd-macro "\r" arg))
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
717
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
718 (put 'kmacro-edit-macro-repeat 'kmacro-repeat 'stop)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
719
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
720
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
721 (defun kmacro-edit-macro (&optional arg)
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
722 "As edit last keyboard macro, but without kmacro-repeat property."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
723 (interactive "P")
47094
cbc107c19e30 Changed default bindings from F7/F8 to F3/F4.
Kim F. Storm <storm@cua.dk>
parents: 47051
diff changeset
724 (edit-kbd-macro "\r" arg))
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
725
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
726
46961
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
727 (defun kmacro-edit-lossage ()
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
728 "Edit most recent 100 keystrokes as a keyboard macro."
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
729 (interactive)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
730 (kmacro-push-ring)
7e8358ec31ba Major rework based on discussions with RMS.
Kim F. Storm <storm@cua.dk>
parents: 46099
diff changeset
731 (edit-kbd-macro "\C-hl"))
46083
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
732
bd954daa704a New file.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
733
47310
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
734 ;;; Single-step editing of keyboard macros
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
735
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
736 (defvar kmacro-step-edit-active) ;; step-editing active
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
737 (defvar kmacro-step-edit-new-macro) ;; storage for new macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
738 (defvar kmacro-step-edit-inserting) ;; inserting into macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
739 (defvar kmacro-step-edit-appending) ;; append to end of macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
740 (defvar kmacro-step-edit-replace) ;; replace orig macro when done
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
741 (defvar kmacro-step-edit-prefix-index) ;; index of first prefix arg key
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
742 (defvar kmacro-step-edit-key-index) ;; index of current key
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
743 (defvar kmacro-step-edit-action) ;; automatic action on next pre-command hook
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
744 (defvar kmacro-step-edit-help) ;; kmacro step edit help enabled
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
745 (defvar kmacro-step-edit-num-input-keys) ;; to ignore duplicate pre-command hook
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
746
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
747 (defvar kmacro-step-edit-map (make-sparse-keymap)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
748 "Keymap that defines the responses to questions in `kmacro-step-edit-macro'.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
749 This keymap is an extension to the `query-replace-map', allowing the
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
750 following additional answers: `insert-1', `insert', `append-1',
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
751 `append', `replace-1', `replace', `act-repeat', `skip-rest',
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
752 `skip-keep'.")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
753
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
754 ;; query-replace-map answers include: `act', `skip', `act-and-show',
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
755 ;; `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
756 ;; `automatic', `backup', `exit-prefix', and `help'.")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
757 ;; Also: `quit', `edit-replacement'
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
758
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
759 (set-keymap-parent kmacro-step-edit-map query-replace-map)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
760
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
761 (define-key kmacro-step-edit-map "\t" 'act-repeat)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
762 (define-key kmacro-step-edit-map [tab] 'act-repeat)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
763 (define-key kmacro-step-edit-map "\C-k" 'skip-rest)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
764 (define-key kmacro-step-edit-map "c" 'automatic)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
765 (define-key kmacro-step-edit-map "f" 'skip-keep)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
766 (define-key kmacro-step-edit-map "q" 'quit)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
767 (define-key kmacro-step-edit-map "d" 'skip)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
768 (define-key kmacro-step-edit-map "i" 'insert)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
769 (define-key kmacro-step-edit-map "I" 'insert-1)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
770 (define-key kmacro-step-edit-map "r" 'replace)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
771 (define-key kmacro-step-edit-map "R" 'replace-1)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
772 (define-key kmacro-step-edit-map "a" 'append)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
773 (define-key kmacro-step-edit-map "A" 'append-1)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
774
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
775 (defvar kmacro-step-edit-prefix-commands
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
776 '(universal-argument universal-argument-more universal-argument-minus
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
777 digit-argument negative-argument)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
778 "Commands which builds up a prefix arg for the current command")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
779
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
780 (defun kmacro-step-edit-prompt (macro index)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
781 ;; Show step-edit prompt
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
782 (let ((keys (and (not kmacro-step-edit-appending)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
783 index (substring macro index executing-macro-index)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
784 (future (and (not kmacro-step-edit-appending)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
785 (substring macro executing-macro-index)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
786 (message-log-max nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
787 (curmsg (current-message)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
788
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
789 ;; TODO: Scroll macro if max-mini-window-height is too small.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
790 (message (concat
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
791 (format "Macro: %s%s%s%s%s\n"
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
792 (format-kbd-macro kmacro-step-edit-new-macro 1)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
793 (if (and kmacro-step-edit-new-macro (> (length kmacro-step-edit-new-macro) 0)) " " "")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
794 (propertize (if keys (format-kbd-macro keys)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
795 (if kmacro-step-edit-appending "<APPEND>" "<INSERT>")) 'face 'region)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
796 (if future " " "")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
797 (if future (format-kbd-macro future) ""))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
798 (cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
799 ((minibufferp)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
800 (format "%s\n%s\n"
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
801 (propertize "\
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
802 minibuffer " 'face 'header-line)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
803 (buffer-substring (point-min) (point-max))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
804 (curmsg
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
805 (format "%s\n%s\n"
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
806 (propertize "\
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
807 echo area " 'face 'header-line)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
808 curmsg))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
809 (t ""))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
810 (if keys
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
811 (format "%s\n%s%s %S [yn iIaArR C-k kq!] "
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
812 (propertize "\
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
813 --------------Step Edit Keyboard Macro [?: help]---------------" 'face 'mode-line)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
814 (if kmacro-step-edit-help "\
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
815 Step: y/SPC: execute next, d/n/DEL: skip next, f: skip but keep
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
816 TAB: execute while same, ?: toggle help
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
817 Edit: i: insert, a: append, r: replace, I/A/R: one sequence
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
818 End: !/c: execute rest, C-k: skip rest and save, q/C-g: quit
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
819 ----------------------------------------------------------------
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
820 " "")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
821 (propertize "Next command:" 'face 'bold)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
822 this-command)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
823 (propertize
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
824 (format "Type key sequence%s to insert and execute%s: "
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
825 (if (numberp kmacro-step-edit-inserting) "" "s")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
826 (if (numberp kmacro-step-edit-inserting) "" "[end with C-j]"))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
827 'face 'bold))))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
828
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
829 (defun kmacro-step-edit-query ()
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
830 ;; Pre-command hook function for step-edit in "command" mode
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
831 (let ((resize-mini-windows t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
832 (max-mini-window-height kmacro-step-edit-mini-window-height)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
833 act restore-index next-index)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
834
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
835 ;; Handle commands which reads additional input using read-char.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
836 (cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
837 ((and (eq this-command 'quoted-insert)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
838 (not (eq kmacro-step-edit-action t)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
839 ;; Find the actual end of this key sequence.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
840 ;; Must be able to backtrack in case we actually execute it.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
841 (setq restore-index executing-macro-index)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
842 (let (unread-command-events)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
843 (quoted-insert 0)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
844 (when unread-command-events
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
845 (setq executing-macro-index (- executing-macro-index (length unread-command-events))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
846 next-index executing-macro-index)))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
847
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
848 ;; Query the user; stop macro exection temporarily
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
849 (let ((macro executing-kbd-macro)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
850 (executing-kbd-macro nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
851 (defining-kbd-macro nil))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
852
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
853 ;; Any action requested by previous command
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
854 (cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
855 ((eq kmacro-step-edit-action t) ;; Reentry for actual command @ end of prefix arg.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
856 (cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
857 ((eq this-command 'quoted-insert)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
858 (clear-this-command-keys) ;; recent-keys actually
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
859 (let (unread-command-events)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
860 (quoted-insert (prefix-numeric-value current-prefix-arg))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
861 (setq kmacro-step-edit-new-macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
862 (vconcat kmacro-step-edit-new-macro (recent-keys)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
863 (when unread-command-events
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
864 (setq kmacro-step-edit-new-macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
865 (substring kmacro-step-edit-new-macro 0 (- (length unread-command-events)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
866 executing-macro-index (- executing-macro-index (length unread-command-events)))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
867 (setq current-prefix-arg nil
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
868 prefix-arg nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
869 (setq act 'ignore))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
870 (t
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
871 (setq act 'act)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
872 (setq kmacro-step-edit-action nil))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
873 ((eq this-command kmacro-step-edit-action) ;; TAB -> activate while same command
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
874 (setq act 'act))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
875 (t
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
876 (setq kmacro-step-edit-action nil)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
877
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
878 ;; Handle prefix arg, or query user
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
879 (cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
880 (act act) ;; set above
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
881 ((memq this-command kmacro-step-edit-prefix-commands)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
882 (unless kmacro-step-edit-prefix-index
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
883 (setq kmacro-step-edit-prefix-index kmacro-step-edit-key-index))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
884 (setq act 'universal-argument))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
885 ((eq this-command 'universal-argument-other-key)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
886 (setq act 'universal-argument))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
887 (t
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
888 (kmacro-step-edit-prompt macro (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
889 (setq act (lookup-key kmacro-step-edit-map
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
890 (vector (with-current-buffer (current-buffer) (read-event))))))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
891
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
892 ;; Resume macro execution and perform the action
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
893 (cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
894 ((eq act 'universal-argument)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
895 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
896 ((cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
897 ((eq act 'act)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
898 t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
899 ((eq act 'act-repeat)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
900 (setq kmacro-step-edit-action this-command)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
901 t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
902 ((eq act 'quit)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
903 (setq kmacro-step-edit-replace nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
904 (setq kmacro-step-edit-active 'ignore)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
905 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
906 ((eq act 'skip)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
907 (setq kmacro-step-edit-prefix-index nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
908 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
909 ((eq act 'skip-keep)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
910 (setq this-command 'ignore)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
911 t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
912 ((eq act 'skip-rest)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
913 (setq kmacro-step-edit-active 'ignore)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
914 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
915 ((eq act 'automatic)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
916 (setq kmacro-step-edit-active nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
917 (setq act t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
918 t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
919 ((member act '(insert-1 insert))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
920 (setq executing-macro-index (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
921 (setq kmacro-step-edit-inserting (if (eq act 'insert-1) 1 t))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
922 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
923 ((member act '(replace-1 replace))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
924 (setq kmacro-step-edit-inserting (if (eq act 'replace-1) 1 t))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
925 (setq kmacro-step-edit-prefix-index nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
926 (if (= executing-macro-index (length executing-kbd-macro))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
927 (setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
928 kmacro-step-edit-appending t))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
929 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
930 ((member act '(append-1 append))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
931 (setq kmacro-step-edit-inserting (if (eq act 'append-1) 1 t))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
932 (if (= executing-macro-index (length executing-kbd-macro))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
933 (setq executing-kbd-macro (vconcat executing-kbd-macro [nil])
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
934 kmacro-step-edit-appending t))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
935 t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
936 ((eq act 'help)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
937 (setq executing-macro-index (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
938 (setq kmacro-step-edit-help (not kmacro-step-edit-help))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
939 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
940 (t ;; Ignore unknown responses
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
941 (setq executing-macro-index (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
942 nil))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
943 (if (> executing-macro-index (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
944 (setq kmacro-step-edit-new-macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
945 (vconcat kmacro-step-edit-new-macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
946 (substring executing-kbd-macro
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
947 (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
948 (if (eq act t) nil executing-macro-index)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
949 kmacro-step-edit-prefix-index nil))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
950 (if restore-index
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
951 (setq executing-macro-index restore-index)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
952 (t
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
953 (setq this-command 'ignore)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
954 (setq kmacro-step-edit-key-index next-index)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
955
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
956 (defun kmacro-step-edit-insert ()
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
957 ;; Pre-command hook function for step-edit in "insert" mode
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
958 (let ((resize-mini-windows t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
959 (max-mini-window-height kmacro-step-edit-mini-window-height)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
960 (macro executing-kbd-macro)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
961 (executing-kbd-macro nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
962 (defining-kbd-macro nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
963 cmd keys next-index)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
964 (setq executing-macro-index (or kmacro-step-edit-prefix-index kmacro-step-edit-key-index)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
965 kmacro-step-edit-prefix-index nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
966 (kmacro-step-edit-prompt macro nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
967 ;; Now, we have read a key sequence from the macro, but we don't want
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
968 ;; to execute it yet. So push it back and read another sequence.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
969 (reset-this-command-lengths)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
970 (setq keys (read-key-sequence nil nil nil nil t))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
971 (setq cmd (key-binding keys t nil))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
972 (if (cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
973 ((null cmd)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
974 t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
975 ((eq cmd 'quoted-insert)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
976 (clear-this-command-keys) ;; recent-keys actually
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
977 (quoted-insert (prefix-numeric-value current-prefix-arg))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
978 (setq current-prefix-arg nil
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
979 prefix-arg nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
980 (setq keys (vconcat keys (recent-keys)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
981 (when (numberp kmacro-step-edit-inserting)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
982 (setq kmacro-step-edit-inserting nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
983 (when unread-command-events
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
984 (setq keys (substring keys 0 (- (length unread-command-events)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
985 executing-macro-index (- executing-macro-index (length unread-command-events))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
986 next-index executing-macro-index
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
987 unread-command-events nil)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
988 (setq cmd 'ignore)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
989 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
990 ((memq cmd kmacro-step-edit-prefix-commands)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
991 (setq universal-argument-num-events 0)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
992 (reset-this-command-lengths)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
993 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
994 ((eq cmd 'universal-argument-other-key)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
995 (setq kmacro-step-edit-action t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
996 (setq universal-argument-num-events 0)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
997 (reset-this-command-lengths)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
998 (if (numberp kmacro-step-edit-inserting)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
999 (setq kmacro-step-edit-inserting nil))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1000 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1001 ((numberp kmacro-step-edit-inserting)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1002 (setq kmacro-step-edit-inserting nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1003 nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1004 ((equal keys "\C-j")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1005 (setq kmacro-step-edit-inserting nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1006 (setq kmacro-step-edit-action nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1007 ;; Forget any (partial) prefix arg from next command
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1008 (setq kmacro-step-edit-prefix-index nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1009 (reset-this-command-lengths)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1010 (setq overriding-terminal-local-map nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1011 (setq universal-argument-num-events nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1012 (setq next-index kmacro-step-edit-key-index)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1013 t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1014 (t nil))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1015 (setq this-command 'ignore)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1016 (setq this-command cmd)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1017 (if (memq this-command '(self-insert-command digit-argument))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1018 (setq last-command-char (aref keys (1- (length keys)))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1019 (if keys
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1020 (setq kmacro-step-edit-new-macro (vconcat kmacro-step-edit-new-macro keys))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1021 (setq kmacro-step-edit-key-index next-index)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1022
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1023 (defun kmacro-step-edit-pre-command ()
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1024 (remove-hook 'post-command-hook 'kmacro-step-edit-post-command)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1025 (when kmacro-step-edit-active
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1026 (cond
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1027 ((eq kmacro-step-edit-active 'ignore)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1028 (setq this-command 'ignore))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1029 ((/= kmacro-step-edit-num-input-keys num-input-keys)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1030 (if kmacro-step-edit-inserting
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1031 (kmacro-step-edit-insert)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1032 (kmacro-step-edit-query))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1033 (setq kmacro-step-edit-num-input-keys num-input-keys)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1034 (if (and kmacro-step-edit-appending (not kmacro-step-edit-inserting))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1035 (setq kmacro-step-edit-appending nil
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1036 kmacro-step-edit-active 'ignore)))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1037 (when (eq kmacro-step-edit-active t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1038 (add-hook 'post-command-hook 'kmacro-step-edit-post-command t)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1039
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1040 (defun kmacro-step-edit-minibuf-setup ()
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1041 (remove-hook 'pre-command-hook 'kmacro-step-edit-pre-command t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1042 (when kmacro-step-edit-active
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1043 (add-hook 'pre-command-hook 'kmacro-step-edit-pre-command nil t)))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1044
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1045 (defun kmacro-step-edit-post-command ()
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1046 (remove-hook 'pre-command-hook 'kmacro-step-edit-pre-command)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1047 (when kmacro-step-edit-active
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1048 (add-hook 'pre-command-hook 'kmacro-step-edit-pre-command nil nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1049 (if kmacro-step-edit-key-index
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1050 (setq executing-macro-index kmacro-step-edit-key-index)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1051 (setq kmacro-step-edit-key-index executing-macro-index))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1052
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1053
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1054 (defun kmacro-step-edit-macro ()
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1055 "Step edit and execute last keyboard macro.
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1056
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1057 To customize possible responses, change the \"bindings\" in `kmacro-step-edit-map'."
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1058 (interactive)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1059 (let ((kmacro-step-edit-active t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1060 (kmacro-step-edit-new-macro "")
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1061 (kmacro-step-edit-inserting nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1062 (kmacro-step-edit-appending nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1063 (kmacro-step-edit-replace t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1064 (kmacro-step-edit-prefix-index nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1065 (kmacro-step-edit-key-index 0)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1066 (kmacro-step-edit-action nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1067 (kmacro-step-edit-help nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1068 (kmacro-step-edit-num-input-keys num-input-keys)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1069 (pre-command-hook pre-command-hook)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1070 (post-command-hook post-command-hook)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1071 (minibuffer-setup-hook minibuffer-setup-hook))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1072 (add-hook 'pre-command-hook 'kmacro-step-edit-pre-command nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1073 (add-hook 'post-command-hook 'kmacro-step-edit-post-command t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1074 (add-hook 'minibuffer-setup-hook 'kmacro-step-edit-minibuf-setup t)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1075 (call-last-kbd-macro nil nil)
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1076 (if kmacro-step-edit-replace
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1077 (setq last-kbd-macro kmacro-step-edit-new-macro))))
5a8754f590f4 (kmacro-end-and-call-macro): New command to end and
Kim F. Storm <storm@cua.dk>
parents: 47094
diff changeset
1078
46099
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
1079 (provide 'kmacro)
d441fc235798 Passed it through checkdoc. Moved `provide' to the end, where it belongs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46085
diff changeset
1080 ;;; kmacro.el ends here