Mercurial > emacs
annotate lisp/repeat.el @ 22745:ef9607e709bc
(Fw32_set_clipboard_data): Set Vlast_coding_system_used.
(Fw32_get_clipboard_data): Likewise.
author | Andrew Innes <andrewi@gnu.org> |
---|---|
date | Sun, 12 Jul 1998 20:24:23 +0000 |
parents | 1fd9b569c5b4 |
children | 9c6f6af7919f |
rev | line source |
---|---|
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
1 ;;; repeat.el --- convenient way to repeat the previous command |
22131 | 2 |
3 ;; Copyright (C) 1998 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Will Mengarini <seldon@eskimo.com> | |
6 ;; Created: Mo 02 Mar 98 | |
7 ;; Version: 0.51, We 13 May 98 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
8 ;; Keywords: convenience, vi, repeat |
22131 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; This program is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; This program is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; Sometimes the fastest way to get something done is just to lean on a key; | |
30 ;; moving forward through a series of words by leaning on M-f is an example. | |
31 ;; But 'forward-page is orthodoxily bound to C-x ], so moving forward through | |
32 ;; several pages requires | |
33 ;; Loop until desired page is reached: | |
34 ;; Hold down control key with left pinkie. | |
35 ;; Tap <x>. | |
36 ;; Lift left pinkie off control key. | |
37 ;; Tap <]>. | |
38 ;; This is a pain in the ass. | |
39 | |
40 ;; This package defines a command that repeats the preceding command, | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
41 ;; whatever that was, including its arguments, whatever they were. |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
42 ;; This command is connected to the key C-x z. |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
43 ;; To repeat the previous command once, type C-x z. |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
44 ;; To repeat it a second time immediately after, type just z. |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
45 ;; By typing z again and again, you can repeat the command over and over. |
22131 | 46 |
47 ;; This works correctly inside a keyboard macro as far as recording and | |
48 ;; playback go, but `edit-kbd-macro' gets it wrong. That shouldn't really | |
49 ;; matter; if you need to edit something like | |
50 ;; C-x ] ;; forward-page | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
51 ;; C-x z ;; repeat |
22131 | 52 ;; zz ;; self-insert-command * 2 |
53 ;; C-x ;; Control-X-prefix | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
54 ;; you can just kill the bogus final 2 lines, then duplicate the repeat line |
22131 | 55 ;; as many times as it's really needed. Also, `edit-kbd-macro' works |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
56 ;; correctly if `repeat' is invoked through a rebinding to a single keystroke |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
57 ;; and the global variable repeat-on-final-keystroke is set to a value |
22131 | 58 ;; that doesn't include that keystroke. For example, the lines |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
59 ;; (global-set-key "\C-z" 'repeat) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
60 ;; (setq repeat-on-final-keystroke "z") |
22131 | 61 ;; in your .emacs would allow `edit-kbd-macro' to work correctly when C-z was |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
62 ;; used in a keyboard macro to invoke `repeat', but would still allow C-x z |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
63 ;; to be used for `repeat' elsewhere. The real reason for documenting this |
22131 | 64 ;; isn't that anybody would need it for the `edit-kbd-macro' problem, but |
65 ;; that there might be other unexpected ramifications of re-executing on | |
66 ;; repetitions of the final keystroke, and this shows how to do workarounds. | |
67 | |
68 ;; If the preceding command had a prefix argument, that argument is applied | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
69 ;; to the repeat command, unless the repeat command is given a new prefix |
22131 | 70 ;; argument, in which case it applies that new prefix argument to the |
71 ;; preceding command. This means a key sequence like C-u - C-x C-t can be | |
72 ;; repeated. (It shoves the preceding line upward in the buffer.) | |
73 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
74 ;; Here are some other key sequences with which repeat might be useful: |
22131 | 75 ;; C-u - C-t [shove preceding character backward in line] |
76 ;; C-u - M-t [shove preceding word backward in sentence] | |
77 ;; C-x ^ enlarge-window [one line] (assuming frame has > 1 window) | |
78 ;; C-u - C-x ^ [shrink window one line] | |
79 ;; C-x ` next-error | |
80 ;; C-u - C-x ` [previous error] | |
81 ;; C-x DEL backward-kill-sentence | |
82 ;; C-x e call-last-kbd-macro | |
83 ;; C-x r i insert-register | |
84 ;; C-x r t string-rectangle | |
85 ;; C-x TAB indent-rigidly [one character] | |
86 ;; C-u - C-x TAB [outdent rigidly one character] | |
87 ;; C-x { shrink-window-horizontally | |
88 ;; C-x } enlarge-window-horizontally | |
89 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
90 ;; This command was first called `vi-dot', because |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
91 ;; it was inspired by the `.' command in the vi editor, |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
92 ;; but it was renamed to make its name more meaningful. |
22131 | 93 |
94 ;;; Code: | |
95 | |
96 (eval-when-compile (require 'cl)) | |
97 | |
98 ;;;;; ************************* USER OPTIONS ************************** ;;;;; | |
99 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
100 (defcustom repeat-too-dangerous '(kill-this-buffer) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
101 "Commands too dangerous to repeat with \\[repeat]." |
22132 | 102 :group 'convenience |
103 :type '(repeat function)) | |
22131 | 104 |
105 ;; If the last command was self-insert-command, the char to be inserted was | |
106 ;; obtained by that command from last-command-char, which has now been | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
107 ;; clobbered by the command sequence that invoked `repeat'. We could get it |
22131 | 108 ;; from (recent-keys) & set last-command-char to that, "unclobbering" it, but |
109 ;; this has the disadvantage that if the user types a sequence of different | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
110 ;; chars then invokes repeat, only the final char will be inserted. In vi, |
22131 | 111 ;; the dot command can reinsert the entire most-recently-inserted sequence. |
112 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
113 (defvar repeat-message-function nil |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
114 "If non-nil, function used by `repeat' command to say what it's doing. |
22131 | 115 Message is something like \"Repeating command glorp\". |
22132 | 116 To disable such messages, set this variable to `ignore'. To customize |
22131 | 117 display, assign a function that takes one string as an arg and displays |
118 it however you want.") | |
119 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
120 (defcustom repeat-on-final-keystroke t |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
121 "Allow `repeat' to re-execute for repeating lastchar of a key sequence. |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
122 If this variable is t, `repeat' determines what key sequence |
22131 | 123 it was invoked by, extracts the final character of that sequence, and |
124 re-executes as many times as that final character is hit; so for example | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
125 if `repeat' is bound to C-x z, typing C-x z z z repeats the previous command |
22131 | 126 3 times. If this variable is a sequence of characters, then re-execution |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
127 only occurs if the final character by which `repeat' was invoked is a |
22132 | 128 member of that sequence. If this variable is nil, no re-execution occurs." |
129 :group 'convenience | |
130 :type 'boolean) | |
22131 | 131 |
132 ;;;;; ****************** HACKS TO THE REST OF EMACS ******************* ;;;;; | |
133 | |
134 ;; The basic strategy is to use last-command, a variable built in to Emacs. | |
135 ;; There are 2 issues that complicate this strategy. The first is that | |
136 ;; last-command is given a bogus value when any kill command is executed; | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
137 ;; this is done to make it easy for `yank-pop' to know that it's being invoked |
22131 | 138 ;; after a kill command. The second is that the meaning of the command is |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
139 ;; often altered by the prefix arg, but although Emacs (19.34) has a |
22131 | 140 ;; builtin prefix-arg specifying the arg for the next command, as well as a |
141 ;; builtin current-prefix-arg, it has no builtin last-prefix-arg. | |
142 | |
143 ;; There's a builtin (this-command-keys), the return value of which could be | |
144 ;; executed with (command-execute), but there's no (last-command-keys). | |
145 ;; Using (last-command-keys) if it existed wouldn't be optimal, however, | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
146 ;; since it would complicate checking membership in repeat-too-dangerous. |
22131 | 147 |
148 ;; It would of course be trivial to implement last-prefix-arg & | |
149 ;; true-last-command by putting something in post-command-hook, but that | |
150 ;; entails a performance hit; the approach taken below avoids that. | |
151 | |
152 ;; First cope with (kill-region). It's straightforward to advise it to save | |
153 ;; the true value of this-command before clobbering it. | |
154 | |
155 (require 'advice) | |
156 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
157 (defvar repeat-last-kill-command nil |
22131 | 158 "True value of `this-command' before (`kill-region') clobbered it.") |
159 | |
160 ;; Coping with strings of self-insert commands gets hairy when they interact | |
161 ;; with auto-filling. Most problems are eliminated by remembering what we're | |
162 ;; self-inserting, so we only need to get it from the undo information once. | |
163 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
164 (defvar repeat-last-self-insert nil |
22131 | 165 "If last repeated command was `self-insert-command', it inserted this.") |
166 | |
167 ;; That'll require another keystroke count so we know we're in a string of | |
168 ;; repetitions of self-insert commands: | |
169 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
170 (defvar repeat-num-input-keys-at-self-insert -1 |
22131 | 171 "# key sequences read in Emacs session when `self-insert-command' repeated.") |
172 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
173 ;;;;; *************** ANALOGOUS HACKS TO `repeat' ITSELF **************** ;;;;; |
22131 | 174 |
175 ;; That mechanism of checking num-input-keys to figure out what's really | |
176 ;; going on can be useful to other commands that need to fine-tune their | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
177 ;; interaction with repeat. Instead of requiring them to advise repeat, we |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
178 ;; can just defvar the value they need here, & setq it in the repeat command: |
22131 | 179 |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
180 (defvar repeat-num-input-keys-at-repeat -1 |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
181 "# key sequences read in Emacs session when `repeat' last invoked.") |
22131 | 182 |
183 ;; Also, we can assign a name to the test for which that variable is | |
184 ;; intended, which thereby documents here how to use it, & makes code that | |
185 ;; uses it self-documenting: | |
186 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
187 (defsubst repeat-is-really-this-command () |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
188 "Return t if this command is happening because user invoked `repeat'. |
22131 | 189 Usually, when a command is executing, the Emacs builtin variable |
190 `this-command' identifies the command the user invoked. Some commands modify | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
191 that variable on the theory they're doing more good than harm; `repeat' does |
22131 | 192 that, and usually does do more good than harm. However, like all do-gooders, |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
193 sometimes `repeat' gets surprising results from its altruism. The value of |
22131 | 194 this function is always whether the value of `this-command' would've been |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
195 'repeat if `repeat' hadn't modified it." |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
196 (= repeat-num-input-keys-at-repeat num-input-keys)) |
22131 | 197 |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
198 ;; An example of the use of (repeat-is-really-this-command) may still be |
22131 | 199 ;; available in <http://www.eskimo.com/~seldon/dotemacs.el>; search for |
200 ;; "defun wm-switch-buffer". | |
201 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
202 ;;;;; ******************* THE REPEAT COMMAND ITSELF ******************* ;;;;; |
22131 | 203 |
204 ;;;###autoload | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
205 (defun repeat (repeat-arg) |
22131 | 206 "Repeat most recently executed command. |
207 With prefix arg, apply new prefix arg to that command; otherwise, maintain | |
208 prefix arg of most recently executed command if it had one. | |
209 This command is named after the `.' command in the vi editor. | |
210 | |
211 If this command is invoked by a multi-character key sequence, it can then | |
212 be repeated by repeating the final character of that sequence. This behavior | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
213 can be modified by the global variable `repeat-on-final-keystroke'." |
22131 | 214 ;; The most recently executed command could be anything, so surprises could |
215 ;; result if it were re-executed in a context where new dynamically | |
216 ;; localized variables were shadowing global variables in a `let' clause in | |
217 ;; here. (Remember that GNU Emacs 19 is dynamically localized.) | |
218 ;; To avoid that, I tried the `lexical-let' of the Common Lisp extensions, | |
219 ;; but that entails a very noticeable performance hit, so instead I use the | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
220 ;; "repeat-" prefix, reserved by this package, for *local* variables that |
22131 | 221 ;; might be visible to re-executed commands, including this function's arg. |
222 (interactive "P") | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
223 (setq this-command real-last-command |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
224 repeat-num-input-keys-at-repeat num-input-keys) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
225 (when (eq real-last-command 'mode-exit) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
226 (error "real-last-command is mode-exit & can't be repeated")) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
227 (when (memq real-last-command repeat-too-dangerous) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
228 (error "Command %S too dangerous to repeat automatically" real-last-command)) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
229 (when (null repeat-arg) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
230 (setq repeat-arg last-prefix-arg)) |
22131 | 231 ;; Now determine whether to loop on repeated taps of the final character |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
232 ;; of the key sequence that invoked repeat. The Emacs global |
22131 | 233 ;; last-command-char contains the final character now, but may not still |
234 ;; contain it after the previous command is repeated, so the character | |
235 ;; needs to be saved. | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
236 (let ((repeat-repeat-char |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
237 (if (eq repeat-on-final-keystroke t) |
22131 | 238 ;; allow any final input event that was a character |
239 (when (eq last-command-char | |
240 last-command-event) | |
241 last-command-char) | |
242 ;; allow only specified final keystrokes | |
243 (car (memq last-command-char | |
244 (listify-key-sequence | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
245 repeat-on-final-keystroke)))))) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
246 (if (memq real-last-command '(exit-minibuffer |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
247 minibuffer-complete-and-exit |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
248 self-insert-and-exit)) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
249 (let ((repeat-command (car command-history))) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
250 (repeat-message "Repeating %S" repeat-command) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
251 (eval repeat-command)) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
252 (if (null repeat-arg) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
253 (repeat-message "Repeating command %S" real-last-command) |
22467
1fd9b569c5b4
(repeat): Don't set obsolete var repeat-num-input-keys-at-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
22439
diff
changeset
|
254 (setq current-prefix-arg repeat-arg) |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
255 (repeat-message "Repeating command %S %S" repeat-arg real-last-command)) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
256 (if (eq real-last-command 'self-insert-command) |
22131 | 257 (let ((insertion |
258 (if (<= (- num-input-keys | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
259 repeat-num-input-keys-at-self-insert) |
22131 | 260 1) |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
261 repeat-last-self-insert |
22131 | 262 (let ((range (nth 1 buffer-undo-list))) |
263 (condition-case nil | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
264 (setq repeat-last-self-insert |
22131 | 265 (buffer-substring (car range) |
266 (cdr range))) | |
267 (error (error "%s %s %s" ;Danger, Will Robinson! | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
268 "repeat can't intuit what you" |
22131 | 269 "inserted before auto-fill" |
270 "clobbered it, sorry"))))))) | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
271 (setq repeat-num-input-keys-at-self-insert num-input-keys) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
272 (loop repeat (prefix-numeric-value repeat-arg) do |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
273 (repeat-self-insert insertion))) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
274 (call-interactively real-last-command))) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
275 (when repeat-repeat-char |
22131 | 276 ;; A simple recursion here gets into trouble with max-lisp-eval-depth |
277 ;; on long sequences of repetitions of a command like `forward-word' | |
278 ;; (only 32 repetitions are possible given the default value of 200 for | |
279 ;; max-lisp-eval-depth), but if I now locally disable the repeat char I | |
280 ;; can iterate indefinitely here around a single level of recursion. | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
281 (let (repeat-on-final-keystroke) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
282 (while (eq (read-event) repeat-repeat-char) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
283 (repeat repeat-arg)) |
22131 | 284 (setq unread-command-events (list last-input-event)))))) |
285 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
286 (defun repeat-self-insert (string) |
22132 | 287 (let ((i 0)) |
288 (while (< i (length string)) | |
289 (let ((last-command-char (aref string i))) | |
290 (self-insert-command 1)) | |
291 (setq i (1+ i))))) | |
292 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
293 (defun repeat-message (format &rest args) |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
294 "Like `message' but displays with `repeat-message-function' if non-nil." |
22131 | 295 (let ((message (apply 'format format args))) |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
296 (if repeat-message-function |
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
297 (funcall repeat-message-function message) |
22131 | 298 (message "%s" message)))) |
299 | |
300 ;; OK, there's one situation left where that doesn't work correctly: when the | |
301 ;; most recent self-insertion provoked an auto-fill. The problem is that | |
302 ;; unravelling the undo information after an auto-fill is too hard, since all | |
303 ;; kinds of stuff can get in there as a result of comment prefixes etc. It'd | |
304 ;; be possible to advise do-auto-fill to record the most recent | |
305 ;; self-insertion before it does its thing, but that's a performance hit on | |
306 ;; auto-fill, which already has performance problems; so it's better to just | |
307 ;; leave it like this. If text didn't provoke an auto-fill when the user | |
308 ;; typed it, this'll correctly repeat its self-insertion, even if the | |
309 ;; repetition does cause auto-fill. | |
310 | |
311 ;; If you wanted perfection, probably it'd be necessary to hack do-auto-fill | |
312 ;; into 2 functions, maybe-do-auto-fill & really-do-auto-fill, because only | |
313 ;; really-do-auto-fill should be advised. As things are, either the undo | |
314 ;; information would need to be scanned on every do-auto-fill invocation, or | |
315 ;; the code at the top of do-auto-fill deciding whether filling is necessary | |
316 ;; would need to be duplicated in the advice, wasting execution time when | |
317 ;; filling does turn out to be necessary. | |
318 | |
319 ;; I thought maybe this story had a moral, something about functional | |
320 ;; decomposition; but now I'm not even sure of that, since a function | |
321 ;; call per se is a performance hit, & even the code that would | |
322 ;; correspond to really-do-auto-fill has performance problems that | |
323 ;; can make it necessary to stop typing while Emacs catches up. | |
324 ;; Maybe the real moral is that perfection is a chimera. | |
325 | |
326 ;; Ah, hell, it's all going to fall into a black hole someday anyway. | |
327 | |
328 ;;;;; ************************* EMACS CONTROL ************************* ;;;;; | |
329 | |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
330 (provide 'repeat) |
22131 | 331 |
22439
3dc0b9f57ff6
Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents:
22132
diff
changeset
|
332 ;;; repeat.el ends here |