comparison lisp/repeat.el @ 87862:b151c81bfd6e

(repeat-undo-count): New variable. (repeat): For self-insertions make undo boundary only after 20 repetitions. Inhibit point recording when repeat-repeat-char is non-nil.
author Martin Rudalics <rudalics@gmx.at>
date Sun, 20 Jan 2008 10:34:58 +0000
parents 73661ddc7ac7
children c70e45a7acfd 1e3a407766b9
comparison
equal deleted inserted replaced
87861:da84f0918d39 87862:b151c81bfd6e
197 197
198 ;;;;; ******************* THE REPEAT COMMAND ITSELF ******************* ;;;;; 198 ;;;;; ******************* THE REPEAT COMMAND ITSELF ******************* ;;;;;
199 199
200 (defvar repeat-previous-repeated-command nil 200 (defvar repeat-previous-repeated-command nil
201 "The previous repeated command.") 201 "The previous repeated command.")
202
203 ;; The following variable counts repeated self-insertions. The idea is
204 ;; that repeating a self-insertion command and subsequently undoing it
205 ;; should have almost the same effect as if the characters were inserted
206 ;; manually. The basic difference is that we leave in one undo-boundary
207 ;; between the original insertion and its first repetition.
208 (defvar repeat-undo-count nil
209 "Number of self-insertions since last `undo-boundary'.")
202 210
203 ;;;###autoload 211 ;;;###autoload
204 (defun repeat (repeat-arg) 212 (defun repeat (repeat-arg)
205 "Repeat most recently executed command. 213 "Repeat most recently executed command.
206 With prefix arg, apply new prefix arg to that command; otherwise, 214 With prefix arg, apply new prefix arg to that command; otherwise,
244 ;; last-command-char contains the final character now, but may not still 252 ;; last-command-char contains the final character now, but may not still
245 ;; contain it after the previous command is repeated, so the character 253 ;; contain it after the previous command is repeated, so the character
246 ;; needs to be saved. 254 ;; needs to be saved.
247 (let ((repeat-repeat-char 255 (let ((repeat-repeat-char
248 (if (eq repeat-on-final-keystroke t) 256 (if (eq repeat-on-final-keystroke t)
249 ;; The following commented out since it's equivalent to
250 ;; last-comment-char (martin 2007-08-29).
251 ;;; ;; allow any final input event that was a character
252 ;;; (when (eq last-command-char
253 ;;; last-command-event)
254 ;;; last-command-char)
255 last-command-char 257 last-command-char
256 ;; allow only specified final keystrokes 258 ;; allow only specified final keystrokes
257 (car (memq last-command-char 259 (car (memq last-command-char
258 (listify-key-sequence 260 (listify-key-sequence
259 repeat-on-final-keystroke)))))) 261 repeat-on-final-keystroke))))))
291 (setq insertion (substring insertion -1)) 293 (setq insertion (substring insertion -1))
292 (let ((count (prefix-numeric-value repeat-arg)) 294 (let ((count (prefix-numeric-value repeat-arg))
293 (i 0)) 295 (i 0))
294 ;; Run pre- and post-command hooks for self-insertion too. 296 ;; Run pre- and post-command hooks for self-insertion too.
295 (run-hooks 'pre-command-hook) 297 (run-hooks 'pre-command-hook)
298 (cond
299 ((not repeat-undo-count))
300 ((< repeat-undo-count 20)
301 ;; Don't make an undo-boundary here.
302 (setq repeat-undo-count (1+ repeat-undo-count)))
303 (t
304 ;; Make an undo-boundary after 20 repetitions only.
305 (undo-boundary)
306 (setq repeat-undo-count 1)))
296 (while (< i count) 307 (while (< i count)
297 (repeat-self-insert insertion) 308 (repeat-self-insert insertion)
298 (setq i (1+ i))) 309 (setq i (1+ i)))
299 (run-hooks 'post-command-hook))) 310 (run-hooks 'post-command-hook)))
300 (let ((indirect (indirect-function last-repeatable-command))) 311 (let ((indirect (indirect-function last-repeatable-command)))
312 ;; Make each repetition undo separately.
313 (undo-boundary)
301 (if (or (stringp indirect) 314 (if (or (stringp indirect)
302 (vectorp indirect)) 315 (vectorp indirect))
303 ;; Bind real-last-command so that executing the macro does 316 ;; Bind real-last-command so that executing the macro does
304 ;; not alter it. Do the same for last-repeatable-command. 317 ;; not alter it. Do the same for last-repeatable-command.
305 (let ((real-last-command real-last-command) 318 (let ((real-last-command real-last-command)
312 ;; A simple recursion here gets into trouble with max-lisp-eval-depth 325 ;; A simple recursion here gets into trouble with max-lisp-eval-depth
313 ;; on long sequences of repetitions of a command like `forward-word' 326 ;; on long sequences of repetitions of a command like `forward-word'
314 ;; (only 32 repetitions are possible given the default value of 200 for 327 ;; (only 32 repetitions are possible given the default value of 200 for
315 ;; max-lisp-eval-depth), but if I now locally disable the repeat char I 328 ;; max-lisp-eval-depth), but if I now locally disable the repeat char I
316 ;; can iterate indefinitely here around a single level of recursion. 329 ;; can iterate indefinitely here around a single level of recursion.
317 (let (repeat-on-final-keystroke) 330 (let (repeat-on-final-keystroke
331 ;; Bind `undo-inhibit-record-point' to t in order to avoid
332 ;; recording point in `buffer-undo-list' here. We have to
333 ;; do this since the command loop does not set the last
334 ;; position of point thus confusing the point recording
335 ;; mechanism when inserting or deleting text.
336 (undo-inhibit-record-point t))
318 (setq real-last-command 'repeat) 337 (setq real-last-command 'repeat)
319 (while (eq (read-event) repeat-repeat-char) 338 (setq repeat-undo-count 1)
320 ;; Make each repetition undo separately. 339 (unwind-protect
321 (undo-boundary) 340 (while (eq (read-event) repeat-repeat-char)
322 (repeat repeat-arg)) 341 (repeat repeat-arg))
342 ;; Make sure `repeat-undo-count' is reset.
343 (setq repeat-undo-count nil))
323 (setq unread-command-events (list last-input-event)))))) 344 (setq unread-command-events (list last-input-event))))))
324 345
325 (defun repeat-self-insert (string) 346 (defun repeat-self-insert (string)
326 (let ((i 0)) 347 (let ((i 0))
327 (while (< i (length string)) 348 (while (< i (length string))