unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* timers and undo
@ 2004-12-24 22:32 Luc Teirlinck
  2004-12-27  4:09 ` Richard Stallman
  0 siblings, 1 reply; 4+ messages in thread
From: Luc Teirlinck @ 2004-12-24 22:32 UTC (permalink / raw)


The way timers treat undo is really peculiar.

Do `emacs -q'.  Then:

M-: (run-at-time 5 5 (lambda () (with-current-buffer "*scratch*"
(insert "aaaaaaa\n"))))

Wait till enough lines are inserted.  C-/.  The entire block of
inserted lines gets deleted all at once.  This apparently causes
problems with undo-outer-limit as I pointed out before.

But there is more.

Wait until once more a bunch of lines are inserted.  I now expected
that C-/ would get rid of these inserted lines once more.  But no.
It deletes the introductory comment lines.  The "aaaaaaa" lines
stay and they are impossible to undo after repaeting C-/

undo-more: No further undo information

It seems hard to consider this a deliberate "feature".

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: timers and undo
  2004-12-24 22:32 timers and undo Luc Teirlinck
@ 2004-12-27  4:09 ` Richard Stallman
  2004-12-27 22:33   ` Stefan Monnier
  2004-12-29  4:04   ` Luc Teirlinck
  0 siblings, 2 replies; 4+ messages in thread
From: Richard Stallman @ 2004-12-27  4:09 UTC (permalink / raw)
  Cc: emacs-devel

    Wait until once more a bunch of lines are inserted.  I now expected
    that C-/ would get rid of these inserted lines once more.  But no.
    It deletes the introductory comment lines.  The "aaaaaaa" lines
    stay and they are impossible to undo after repaeting C-/

This is because it sees that the previous command was also `undo'.
So it continues the undo sequence previously started.

One fix is to make the command `undo' defensively notice that the undo
list has changed since its previous execution.  Does the fix below
give good results?

One drawback of this patch is that the space in the undo list
will still be wasted if buffer-undo-list is cleared out

*** simple.el	20 Dec 2004 15:37:08 -0500	1.673
--- simple.el	26 Dec 2004 15:12:32 -0500	
*** 1215,1220 ****
--- 1234,1243 ----
  (defvar undo-no-redo nil
    "If t, `undo' doesn't go through redo entries.")
  
+ (defvar undo-list-saved nil
+   "The value of `buffer-undo-list' saved by the last undo command.")
+ (make-variable-buffer-local 'undo-list-saved)
+ 
  (defun undo (&optional arg)
    "Undo some previous changes.
  Repeat this command to undo more changes.
***************
*** 1237,1243 ****
      ;; So set `this-command' to something other than `undo'.
      (setq this-command 'undo-start)
  
!     (unless (eq last-command 'undo)
        (setq undo-in-region
  	    (if transient-mark-mode mark-active (and arg (not (numberp arg)))))
        (if undo-in-region
--- 1260,1267 ----
      ;; So set `this-command' to something other than `undo'.
      (setq this-command 'undo-start)
  
!     (unless (and (eq last-command 'undo)
! 		 (eq undo-list-saved buffer-undo-list))
        (setq undo-in-region
  	    (if transient-mark-mode mark-active (and arg (not (numberp arg)))))
        (if undo-in-region
***************
*** 1289,1295 ****
  	      (setq tail (cdr tail)))
  	    (setq tail nil)))
  	(setq prev tail tail (cdr tail))))
! 
      (and modified (not (buffer-modified-p))
  	 (delete-auto-save-file-if-necessary recent-save))))
  
--- 1313,1319 ----
  	      (setq tail (cdr tail)))
  	    (setq tail nil)))
  	(setq prev tail tail (cdr tail))))
!     (setq saved-undo-list buffer-undo-list)
      (and modified (not (buffer-modified-p))
  	 (delete-auto-save-file-if-necessary recent-save))))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: timers and undo
  2004-12-27  4:09 ` Richard Stallman
@ 2004-12-27 22:33   ` Stefan Monnier
  2004-12-29  4:04   ` Luc Teirlinck
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2004-12-27 22:33 UTC (permalink / raw)
  Cc: Luc Teirlinck, emacs-devel

> This is because it sees that the previous command was also `undo'.
> So it continues the undo sequence previously started.

> One fix is to make the command `undo' defensively notice that the undo
> list has changed since its previous execution.  Does the fix below
> give good results?

You could use the info that's already in undo-equiv-table (and which uses
a weak hash table so there's no impact on the GC behavior) to check whether
changes have occured since the last undo command or not (I use it here to
allow the user to continue a previous undo sequence even if it was
interrupted by some cursor movement).


        Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: timers and undo
  2004-12-27  4:09 ` Richard Stallman
  2004-12-27 22:33   ` Stefan Monnier
@ 2004-12-29  4:04   ` Luc Teirlinck
  1 sibling, 0 replies; 4+ messages in thread
From: Luc Teirlinck @ 2004-12-29  4:04 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman wrote:

   One fix is to make the command `undo' defensively notice that the undo
   list has changed since its previous execution.  Does the fix below
   give good results?

Sorry for waiting nearly two days to check this.  But yes, the fix you
already committed to simple.el seems to work, as long as the timer
puts in undo boundaries before and after modification of the buffer,
as it should.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-12-29  4:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-24 22:32 timers and undo Luc Teirlinck
2004-12-27  4:09 ` Richard Stallman
2004-12-27 22:33   ` Stefan Monnier
2004-12-29  4:04   ` Luc Teirlinck

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).