[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] Bug: Undo does not work in org-agenda-todo when logging a

From: Max Mikhanosha
Subject: Re: [Orgmode] Bug: Undo does not work in org-agenda-todo when logging a note
Date: Sat, 19 Jul 2008 18:46:02 -0400
User-agent: Wanderlust/2.15.3 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shij┼Ź) APEL/10.6 Emacs/22.0.51 (x86_64-unknown-linux-gnu) MULE/5.0 (SAKAKI)

At Sat, 19 Jul 2008 08:27:21 -0700,
Carsten Dominik wrote:
> On Jul 18, 2008, at 7:19 AM, Max Mikhanosha wrote:
> > If I press 't' in the agenda buffer and the state change is logged
> > with a note, undo in the agenda buffer only undoes a note line in the
> > org buffer, leaving the item state changed, and now being out of sync
> > with agenda.
> >
> > If there is no note, then undo works fine.
> Hmmm.  yes.  This is hard to fix, but I will take a look.

I've tried to fix it myself, and yes its non-trivial because one has
to adjust the undo boundary somehow after addinga a note.. After a few
hours of hacking I gave up on that, and instead came up with the

You seem to be playing with (undo-boundary) which records nil in the
buffer-undo-list, which makes (undo-more) stop.

It seems that one can use arbitrary markers in the undo list, not just
nil. The (primitive-undo) function ignores anything in the undo list 
that is not a consp. 

Therefore the following code that implements named/storable undo-boundaries
seems to work, you can test it in scratch buffer

(defun make-undo-checkpoint ()
  (let ((checkpoint (gensym)))
    (push checkpoint buffer-undo-list)

(defun do-undo-until-checkpoint (checkpoint)
  (let ((ptr buffer-undo-list) prev found rest-of-undo)
    (while (and ptr (not found))
      (if (not (eq (car ptr) checkpoint))
          (setq prev ptr ptr (cdr ptr))
        (setq found t)))
    (when found
      ;; rest of undo list after our tag
      (setq rest-of-undo (cdr ptr))
      ;; split the undo list by putting NIL at the place of 
      ;; our tag
      (if (not prev)
          (setq buffer-undo-list nil)) ;; our tag was the 1st element
      (setcdr prev nil)                ;; previous elemen is now last
      (while (listp pending-undo-list)
        (undo-more 1)))))

(defvar checkpoints nil)
(make-variable-buffer-local 'checkpoints)

(defun record-undo-checkpoint (&optional arg)
  (push (make-undo-checkpoint) checkpoints))

(defun undo-until-checkpoint (&optional arg)
  (do-undo-until-checkpoint (pop checkpoints)))

Now if you do M-x record-undo-checkpoint in the buffer it pushes into
a stack of undo checkpoints. The M-x undo-until-checkpoint does undo
until that checkpoint. The checkpoint itself is a unique gensym.

Would it be possible to use this in the org-agenda undo functionality?

You can simply create an undo checkpoint before doing any agenda
command, and then call (undo-until-checkpoint) and it will undo all
the changes in between regardless of undo boundaries?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]