annotate lisp/repeat.el @ 76563:68ddc580d34e

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 19 Mar 2007 05:42:21 +0000
parents e3694f1cb928
children 9355f9b7bbff 95d0cdf160ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
74442
b2e5081b9320 Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
3 ;; Copyright (C) 1998, 2001, 2002, 2003, 2004, 2005,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74442
diff changeset
4 ;; 2006, 2007 Free Software Foundation, Inc.
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: Will Mengarini <seldon@eskimo.com>
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: Mo 02 Mar 98
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Version: 0.51, We 13 May 98
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
9 ;; Keywords: convenience, vi, repeat
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
38401
64d8d90d180d Fix license commentary.
Gerd Moellmann <gerd@gnu.org>
parents: 36029
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
38401
64d8d90d180d Fix license commentary.
Gerd Moellmann <gerd@gnu.org>
parents: 36029
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 61585
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 61585
diff changeset
26 ;; Boston, MA 02110-1301, USA.
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; Sometimes the fastest way to get something done is just to lean on a key;
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; moving forward through a series of words by leaning on M-f is an example.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; But 'forward-page is orthodoxily bound to C-x ], so moving forward through
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; several pages requires
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Loop until desired page is reached:
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; Hold down control key with left pinkie.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; Tap <x>.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Lift left pinkie off control key.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; Tap <]>.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; This is a pain in the ass.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; 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
42 ;; 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
43 ;; 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
44 ;; 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
45 ;; 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
46 ;; By typing z again and again, you can repeat the command over and over.
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; This works correctly inside a keyboard macro as far as recording and
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; playback go, but `edit-kbd-macro' gets it wrong. That shouldn't really
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; matter; if you need to edit something like
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; C-x ] ;; forward-page
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
52 ;; C-x z ;; repeat
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; zz ;; self-insert-command * 2
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; C-x ;; Control-X-prefix
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
55 ;; you can just kill the bogus final 2 lines, then duplicate the repeat line
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; 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
57 ;; 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
58 ;; and the global variable repeat-on-final-keystroke is set to a value
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; 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
60 ;; (global-set-key "\C-z" 'repeat)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
61 ;; (setq repeat-on-final-keystroke "z")
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; 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
63 ;; 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
64 ;; to be used for `repeat' elsewhere. The real reason for documenting this
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; isn't that anybody would need it for the `edit-kbd-macro' problem, but
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; that there might be other unexpected ramifications of re-executing on
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; repetitions of the final keystroke, and this shows how to do workarounds.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; 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
70 ;; to the repeat command, unless the repeat command is given a new prefix
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; argument, in which case it applies that new prefix argument to the
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; preceding command. This means a key sequence like C-u - C-x C-t can be
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; repeated. (It shoves the preceding line upward in the buffer.)
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
75 ;; Here are some other key sequences with which repeat might be useful:
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; C-u - C-t [shove preceding character backward in line]
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; C-u - M-t [shove preceding word backward in sentence]
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; C-x ^ enlarge-window [one line] (assuming frame has > 1 window)
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; C-u - C-x ^ [shrink window one line]
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; C-x ` next-error
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; C-u - C-x ` [previous error]
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; C-x DEL backward-kill-sentence
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; C-x e call-last-kbd-macro
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; C-x r i insert-register
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; C-x r t string-rectangle
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; C-x TAB indent-rigidly [one character]
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; C-u - C-x TAB [outdent rigidly one character]
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; C-x { shrink-window-horizontally
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; C-x } enlarge-window-horizontally
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
91 ;; This command was first called `vi-dot', because
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
92 ;; 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
93 ;; but it was renamed to make its name more meaningful.
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;; Code:
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;;;; ************************* USER OPTIONS ************************** ;;;;;
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
99 (defcustom repeat-too-dangerous '(kill-this-buffer)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
100 "Commands too dangerous to repeat with \\[repeat]."
22132
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
101 :group 'convenience
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
102 :type '(repeat function))
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; If the last command was self-insert-command, the char to be inserted was
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; 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
106 ;; clobbered by the command sequence that invoked `repeat'. We could get it
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;; from (recent-keys) & set last-command-char to that, "unclobbering" it, but
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; 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
109 ;; chars then invokes repeat, only the final char will be inserted. In vi,
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; the dot command can reinsert the entire most-recently-inserted sequence.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
112 (defvar repeat-message-function nil
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
113 "If non-nil, function used by `repeat' command to say what it's doing.
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 Message is something like \"Repeating command glorp\".
22132
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
115 To disable such messages, set this variable to `ignore'. To customize
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 display, assign a function that takes one string as an arg and displays
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 it however you want.")
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
119 (defcustom repeat-on-final-keystroke t
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
120 "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
121 If this variable is t, `repeat' determines what key sequence
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 it was invoked by, extracts the final character of that sequence, and
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 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
124 if `repeat' is bound to C-x z, typing C-x z z z repeats the previous command
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 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
126 only occurs if the final character by which `repeat' was invoked is a
22132
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
127 member of that sequence. If this variable is nil, no re-execution occurs."
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
128 :group 'convenience
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
129 :type 'boolean)
49597
e88404e8f2cf Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38401
diff changeset
130
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;;;;; ****************** HACKS TO THE REST OF EMACS ******************* ;;;;;
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;; The basic strategy is to use last-command, a variable built in to Emacs.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;; There are 2 issues that complicate this strategy. The first is that
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;; 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
136 ;; this is done to make it easy for `yank-pop' to know that it's being invoked
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; 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
138 ;; often altered by the prefix arg, but although Emacs (19.34) has a
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;; builtin prefix-arg specifying the arg for the next command, as well as a
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; builtin current-prefix-arg, it has no builtin last-prefix-arg.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;; There's a builtin (this-command-keys), the return value of which could be
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 ;; executed with (command-execute), but there's no (last-command-keys).
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;; 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
145 ;; since it would complicate checking membership in repeat-too-dangerous.
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;; It would of course be trivial to implement last-prefix-arg &
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;; true-last-command by putting something in post-command-hook, but that
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;; entails a performance hit; the approach taken below avoids that.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; Coping with strings of self-insert commands gets hairy when they interact
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ;; with auto-filling. Most problems are eliminated by remembering what we're
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ;; self-inserting, so we only need to get it from the undo information once.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
155 (defvar repeat-last-self-insert nil
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 "If last repeated command was `self-insert-command', it inserted this.")
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;; That'll require another keystroke count so we know we're in a string of
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ;; repetitions of self-insert commands:
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
161 (defvar repeat-num-input-keys-at-self-insert -1
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 "# key sequences read in Emacs session when `self-insert-command' repeated.")
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
164 ;;;;; *************** ANALOGOUS HACKS TO `repeat' ITSELF **************** ;;;;;
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; That mechanism of checking num-input-keys to figure out what's really
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; 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
168 ;; 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
169 ;; can just defvar the value they need here, & setq it in the repeat command:
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
171 (defvar repeat-num-input-keys-at-repeat -1
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
172 "# key sequences read in Emacs session when `repeat' last invoked.")
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; Also, we can assign a name to the test for which that variable is
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 ;; intended, which thereby documents here how to use it, & makes code that
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 ;; uses it self-documenting:
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
178 (defsubst repeat-is-really-this-command ()
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
179 "Return t if this command is happening because user invoked `repeat'.
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 Usually, when a command is executing, the Emacs builtin variable
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 `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
182 that variable on the theory they're doing more good than harm; `repeat' does
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 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
184 sometimes `repeat' gets surprising results from its altruism. The value of
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 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
186 'repeat if `repeat' hadn't modified it."
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
187 (= repeat-num-input-keys-at-repeat num-input-keys))
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
189 ;; An example of the use of (repeat-is-really-this-command) may still be
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;; available in <http://www.eskimo.com/~seldon/dotemacs.el>; search for
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; "defun wm-switch-buffer".
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
193 ;;;;; ******************* THE REPEAT COMMAND ITSELF ******************* ;;;;;
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
23098
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
195 (defvar repeat-previous-repeated-command nil
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
196 "The previous repeated command.")
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
197
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 ;;;###autoload
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
199 (defun repeat (repeat-arg)
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 "Repeat most recently executed command.
23109
f47c04fb4aab (repeat): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 23098
diff changeset
201 With prefix arg, apply new prefix arg to that command; otherwise, use
f47c04fb4aab (repeat): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 23098
diff changeset
202 the prefix arg that was used before (if any).
23098
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
203 This command is like the `.' command in the vi editor.
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 If this command is invoked by a multi-character key sequence, it can then
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 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
207 can be modified by the global variable `repeat-on-final-keystroke'."
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;; The most recently executed command could be anything, so surprises could
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;; result if it were re-executed in a context where new dynamically
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; localized variables were shadowing global variables in a `let' clause in
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; here. (Remember that GNU Emacs 19 is dynamically localized.)
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ;; To avoid that, I tried the `lexical-let' of the Common Lisp extensions,
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 ;; 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
214 ;; "repeat-" prefix, reserved by this package, for *local* variables that
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 ;; might be visible to re-executed commands, including this function's arg.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (interactive "P")
23098
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
217 (when (eq real-last-command 'repeat)
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
218 (setq real-last-command repeat-previous-repeated-command))
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
219 (when (null real-last-command)
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
220 (error "There is nothing to repeat"))
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
221 (when (eq real-last-command 'mode-exit)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
222 (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
223 (when (memq real-last-command repeat-too-dangerous)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
224 (error "Command %S too dangerous to repeat automatically" real-last-command))
23098
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
225 (setq this-command real-last-command
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
226 repeat-num-input-keys-at-repeat num-input-keys)
7fd17414e625 (repeat): Doc fix.
Dave Love <fx@gnu.org>
parents: 22935
diff changeset
227 (setq repeat-previous-repeated-command this-command)
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
228 (when (null repeat-arg)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
229 (setq repeat-arg last-prefix-arg))
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; 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
231 ;; of the key sequence that invoked repeat. The Emacs global
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 ;; last-command-char contains the final character now, but may not still
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 ;; contain it after the previous command is repeated, so the character
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 ;; needs to be saved.
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
235 (let ((repeat-repeat-char
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
236 (if (eq repeat-on-final-keystroke t)
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 ;; allow any final input event that was a character
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (when (eq last-command-char
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 last-command-event)
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 last-command-char)
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ;; allow only specified final keystrokes
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (car (memq last-command-char
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (listify-key-sequence
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
244 repeat-on-final-keystroke))))))
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
245 (if (memq real-last-command '(exit-minibuffer
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
246 minibuffer-complete-and-exit
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
247 self-insert-and-exit))
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
248 (let ((repeat-command (car command-history)))
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
249 (repeat-message "Repeating %S" repeat-command)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
250 (eval repeat-command))
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
251 (if (null repeat-arg)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
252 (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
253 (setq current-prefix-arg repeat-arg)
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
254 (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
255 (if (eq real-last-command 'self-insert-command)
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (let ((insertion
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (if (<= (- num-input-keys
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
258 repeat-num-input-keys-at-self-insert)
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 1)
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
260 repeat-last-self-insert
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (let ((range (nth 1 buffer-undo-list)))
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (condition-case nil
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
263 (setq repeat-last-self-insert
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (buffer-substring (car range)
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (cdr range)))
49597
e88404e8f2cf Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38401
diff changeset
266 (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
267 "repeat can't intuit what you"
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 "inserted before auto-fill"
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 "clobbered it, sorry")))))))
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
270 (setq repeat-num-input-keys-at-self-insert num-input-keys)
23474
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
271 ;; If the self-insert had a repeat count, INSERTION
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
272 ;; includes that many copies of the same character.
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
273 ;; So use just the first character
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
274 ;; and repeat it the right number of times.
24531
6f36bb11c7a5 Don't require advice.
Karl Heuer <kwzh@gnu.org>
parents: 24401
diff changeset
275 (setq insertion (substring insertion -1))
23474
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
276 (let ((count (prefix-numeric-value repeat-arg))
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
277 (i 0))
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
278 (while (< i count)
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
279 (repeat-self-insert insertion)
242836a572c4 (repeat): Handle keyboard macros properly.
Richard M. Stallman <rms@gnu.org>
parents: 23109
diff changeset
280 (setq i (1+ i)))))
24531
6f36bb11c7a5 Don't require advice.
Karl Heuer <kwzh@gnu.org>
parents: 24401
diff changeset
281 (let ((indirect (indirect-function real-last-command)))
6f36bb11c7a5 Don't require advice.
Karl Heuer <kwzh@gnu.org>
parents: 24401
diff changeset
282 (if (or (stringp indirect)
6f36bb11c7a5 Don't require advice.
Karl Heuer <kwzh@gnu.org>
parents: 24401
diff changeset
283 (vectorp indirect))
36029
e536d2c83d02 (repeat): Don't let execute-kbd-macro alter real-last-command.
Richard M. Stallman <rms@gnu.org>
parents: 24531
diff changeset
284 ;; Bind real-last-command so that executing the macro
e536d2c83d02 (repeat): Don't let execute-kbd-macro alter real-last-command.
Richard M. Stallman <rms@gnu.org>
parents: 24531
diff changeset
285 ;; does not alter it.
e536d2c83d02 (repeat): Don't let execute-kbd-macro alter real-last-command.
Richard M. Stallman <rms@gnu.org>
parents: 24531
diff changeset
286 (let ((real-last-command real-last-command))
e536d2c83d02 (repeat): Don't let execute-kbd-macro alter real-last-command.
Richard M. Stallman <rms@gnu.org>
parents: 24531
diff changeset
287 (execute-kbd-macro real-last-command))
61585
d5d321d5c34f (repeat): Invoke pre-command-hook and post-command-hook.
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
288 (run-hooks 'pre-command-hook)
d5d321d5c34f (repeat): Invoke pre-command-hook and post-command-hook.
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
289 (call-interactively real-last-command)
d5d321d5c34f (repeat): Invoke pre-command-hook and post-command-hook.
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
290 (run-hooks 'post-command-hook)))))
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
291 (when repeat-repeat-char
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 ;; A simple recursion here gets into trouble with max-lisp-eval-depth
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 ;; on long sequences of repetitions of a command like `forward-word'
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 ;; (only 32 repetitions are possible given the default value of 200 for
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 ;; max-lisp-eval-depth), but if I now locally disable the repeat char I
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 ;; 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
297 (let (repeat-on-final-keystroke)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
298 (while (eq (read-event) repeat-repeat-char)
22935
9c6f6af7919f (repeat): Make an undo boundary between repetitions.
Richard M. Stallman <rms@gnu.org>
parents: 22467
diff changeset
299 ;; Make each repetition undo separately.
9c6f6af7919f (repeat): Make an undo boundary between repetitions.
Richard M. Stallman <rms@gnu.org>
parents: 22467
diff changeset
300 (undo-boundary)
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
301 (repeat repeat-arg))
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (setq unread-command-events (list last-input-event))))))
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
304 (defun repeat-self-insert (string)
22132
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
305 (let ((i 0))
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
306 (while (< i (length string))
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
307 (let ((last-command-char (aref string i)))
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
308 (self-insert-command 1))
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
309 (setq i (1+ i)))))
082c63d626ad Customized.
Richard M. Stallman <rms@gnu.org>
parents: 22131
diff changeset
310
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
311 (defun repeat-message (format &rest args)
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
312 "Like `message' but displays with `repeat-message-function' if non-nil."
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (let ((message (apply 'format format args)))
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
314 (if repeat-message-function
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
315 (funcall repeat-message-function message)
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (message "%s" message))))
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ;; OK, there's one situation left where that doesn't work correctly: when the
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 ;; most recent self-insertion provoked an auto-fill. The problem is that
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 ;; unravelling the undo information after an auto-fill is too hard, since all
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 ;; kinds of stuff can get in there as a result of comment prefixes etc. It'd
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ;; be possible to advise do-auto-fill to record the most recent
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ;; self-insertion before it does its thing, but that's a performance hit on
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 ;; auto-fill, which already has performance problems; so it's better to just
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 ;; leave it like this. If text didn't provoke an auto-fill when the user
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 ;; typed it, this'll correctly repeat its self-insertion, even if the
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 ;; repetition does cause auto-fill.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 ;; If you wanted perfection, probably it'd be necessary to hack do-auto-fill
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 ;; into 2 functions, maybe-do-auto-fill & really-do-auto-fill, because only
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 ;; really-do-auto-fill should be advised. As things are, either the undo
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 ;; information would need to be scanned on every do-auto-fill invocation, or
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 ;; the code at the top of do-auto-fill deciding whether filling is necessary
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 ;; would need to be duplicated in the advice, wasting execution time when
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 ;; filling does turn out to be necessary.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 ;; I thought maybe this story had a moral, something about functional
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 ;; decomposition; but now I'm not even sure of that, since a function
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 ;; call per se is a performance hit, & even the code that would
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 ;; correspond to really-do-auto-fill has performance problems that
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 ;; can make it necessary to stop typing while Emacs catches up.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 ;; Maybe the real moral is that perfection is a chimera.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 ;; Ah, hell, it's all going to fall into a black hole someday anyway.
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ;;;;; ************************* EMACS CONTROL ************************* ;;;;;
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
348 (provide 'repeat)
22131
ef5e2e61b4ea Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49597
diff changeset
350 ;;; arch-tag: cd569600-a1ad-4fa7-9062-bb91dfeaf1db
22439
3dc0b9f57ff6 Renamed from vi-dot.el.
Richard M. Stallman <rms@gnu.org>
parents: 22132
diff changeset
351 ;;; repeat.el ends here