comparison lisp/repeat.el @ 22132:082c63d626ad

Customized. (vi-self-insert): New function. (vi-dot): Use that. (vi-dot-insertion-function): Variable deleted.
author Richard M. Stallman <rms@gnu.org>
date Mon, 18 May 1998 05:40:30 +0000
parents ef5e2e61b4ea
children 3dc0b9f57ff6
comparison
equal deleted inserted replaced
22131:ef5e2e61b4ea 22132:082c63d626ad
122 122
123 (eval-when-compile (require 'cl)) 123 (eval-when-compile (require 'cl))
124 124
125 ;;;;; ************************* USER OPTIONS ************************** ;;;;; 125 ;;;;; ************************* USER OPTIONS ************************** ;;;;;
126 126
127 (defvar vi-dot-too-dangerous '(kill-this-buffer) 127 (defcustom vi-dot-too-dangerous '(kill-this-buffer)
128 "Commands too dangerous to repeat with `vi-dot'.") 128 "Commands too dangerous to repeat with `vi-dot'."
129 :group 'convenience
130 :type '(repeat function))
129 131
130 ;; If the last command was self-insert-command, the char to be inserted was 132 ;; If the last command was self-insert-command, the char to be inserted was
131 ;; obtained by that command from last-command-char, which has now been 133 ;; obtained by that command from last-command-char, which has now been
132 ;; clobbered by the command sequence that invoked vi-dot. We could get it 134 ;; clobbered by the command sequence that invoked vi-dot. We could get it
133 ;; from (recent-keys) & set last-command-char to that, "unclobbering" it, but 135 ;; from (recent-keys) & set last-command-char to that, "unclobbering" it, but
134 ;; this has the disadvantage that if the user types a sequence of different 136 ;; this has the disadvantage that if the user types a sequence of different
135 ;; chars then invokes vi-dot, only the final char will be inserted. In vi, 137 ;; chars then invokes vi-dot, only the final char will be inserted. In vi,
136 ;; the dot command can reinsert the entire most-recently-inserted sequence. 138 ;; the dot command can reinsert the entire most-recently-inserted sequence.
137 ;; To do the same thing here, we need to extract the string to insert from
138 ;; the undo information, then insert a new copy in the buffer. However, the
139 ;; built-in `insert', which takes a string as an arg, is a little different
140 ;; from `self-insert-command', which takes only a prefix arg; `insert' ignores
141 ;; `overwrite-mode'. Emacs 19.34 has no self-insert-string. But there's
142 ;; one in my dotemacs.el (on the web), so if you want to, you can define that
143 ;; in your .emacs, & it'll Just Work, as it will in any future Emaecse that
144 ;; have self-insert-string. Or users can code their own
145 ;; insert-string-with-trumpet-fanfare and use that by customizing this:
146
147 (defvar vi-dot-insert-function
148 (catch t (mapcar (lambda (f) (if (fboundp f) (throw t f)))
149 [self-insert-string
150 insert]))
151 "Function used by `vi-dot' command to re-insert a string of characters.
152 In a vanilla Emacs this will default to `insert', which doesn't respect
153 `overwrite-mode'; customize with your own insertion function, taking a single
154 string as an argument, if you have one.")
155 139
156 (defvar vi-dot-message-function nil 140 (defvar vi-dot-message-function nil
157 "If non-nil, function used by `vi-dot' command to say what it's doing. 141 "If non-nil, function used by `vi-dot' command to say what it's doing.
158 Message is something like \"Repeating command glorp\". 142 Message is something like \"Repeating command glorp\".
159 To disable such messages, assign 'ignore to this variable. To customize 143 To disable such messages, set this variable to `ignore'. To customize
160 display, assign a function that takes one string as an arg and displays 144 display, assign a function that takes one string as an arg and displays
161 it however you want.") 145 it however you want.")
162 146
163 (defvar vi-dot-repeat-on-final-keystroke t 147 (defcustom vi-dot-repeat-on-final-keystroke t
164 "Allow `vi-dot' to re-execute for repeating lastchar of a key sequence. 148 "Allow `vi-dot' to re-execute for repeating lastchar of a key sequence.
165 If this variable is t, `vi-dot' determines what key sequence 149 If this variable is t, `vi-dot' determines what key sequence
166 it was invoked by, extracts the final character of that sequence, and 150 it was invoked by, extracts the final character of that sequence, and
167 re-executes as many times as that final character is hit; so for example 151 re-executes as many times as that final character is hit; so for example
168 if `vi-dot' is bound to C-x z, typing C-x z z z repeats the previous command 152 if `vi-dot' is bound to C-x z, typing C-x z z z repeats the previous command
169 3 times. If this variable is a sequence of characters, then re-execution 153 3 times. If this variable is a sequence of characters, then re-execution
170 only occurs if the final character by which `vi-dot' was invoked is a 154 only occurs if the final character by which `vi-dot' was invoked is a
171 member of that sequence. If this variable is nil, no re-execution occurs.") 155 member of that sequence. If this variable is nil, no re-execution occurs."
156 :group 'convenience
157 :type 'boolean)
172 158
173 ;;;;; ****************** HACKS TO THE REST OF EMACS ******************* ;;;;; 159 ;;;;; ****************** HACKS TO THE REST OF EMACS ******************* ;;;;;
174 160
175 ;; The basic strategy is to use last-command, a variable built in to Emacs. 161 ;; The basic strategy is to use last-command, a variable built in to Emacs.
176 ;; There are 2 issues that complicate this strategy. The first is that 162 ;; There are 2 issues that complicate this strategy. The first is that
348 "vi-dot can't intuit what you" 334 "vi-dot can't intuit what you"
349 "inserted before auto-fill" 335 "inserted before auto-fill"
350 "clobbered it, sorry"))))))) 336 "clobbered it, sorry")))))))
351 (setq vi-dot-num-input-keys-at-self-insert num-input-keys) 337 (setq vi-dot-num-input-keys-at-self-insert num-input-keys)
352 (loop repeat (prefix-numeric-value vi-dot-arg) do 338 (loop repeat (prefix-numeric-value vi-dot-arg) do
353 (funcall vi-dot-insert-function insertion))) 339 (vi-self-insert insertion)))
354 (call-interactively last-command))) 340 (call-interactively last-command)))
355 (when vi-dot-repeat-char 341 (when vi-dot-repeat-char
356 ;; A simple recursion here gets into trouble with max-lisp-eval-depth 342 ;; A simple recursion here gets into trouble with max-lisp-eval-depth
357 ;; on long sequences of repetitions of a command like `forward-word' 343 ;; on long sequences of repetitions of a command like `forward-word'
358 ;; (only 32 repetitions are possible given the default value of 200 for 344 ;; (only 32 repetitions are possible given the default value of 200 for
361 (let (vi-dot-repeat-on-final-keystroke) 347 (let (vi-dot-repeat-on-final-keystroke)
362 (while (eq (read-event) vi-dot-repeat-char) 348 (while (eq (read-event) vi-dot-repeat-char)
363 (vi-dot vi-dot-arg)) 349 (vi-dot vi-dot-arg))
364 (setq unread-command-events (list last-input-event)))))) 350 (setq unread-command-events (list last-input-event))))))
365 351
352 (defun vi-self-insert (string)
353 (let ((i 0))
354 (while (< i (length string))
355 (let ((last-command-char (aref string i)))
356 (self-insert-command 1))
357 (setq i (1+ i)))))
358
366 (defun vi-dot-message (format &rest args) 359 (defun vi-dot-message (format &rest args)
367 "Like `message' but displays with `vi-dot-message-function' if non-nil." 360 "Like `message' but displays with `vi-dot-message-function' if non-nil."
368 (let ((message (apply 'format format args))) 361 (let ((message (apply 'format format args)))
369 (if vi-dot-message-function 362 (if vi-dot-message-function
370 (funcall vi-dot-message-function message) 363 (funcall vi-dot-message-function message)