emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: Undo does not work in org-agenda-todo when logging a note
@ 2008-07-18 14:19 Max Mikhanosha
  2008-07-19 15:27 ` Carsten Dominik
  0 siblings, 1 reply; 3+ messages in thread
From: Max Mikhanosha @ 2008-07-18 14:19 UTC (permalink / raw)
  To: emacs-orgmode

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. 

Regards,
  Max

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

* Re: Bug: Undo does not work in org-agenda-todo when logging a note
  2008-07-18 14:19 Bug: Undo does not work in org-agenda-todo when logging a note Max Mikhanosha
@ 2008-07-19 15:27 ` Carsten Dominik
  2008-07-19 22:46   ` Max Mikhanosha
  0 siblings, 1 reply; 3+ messages in thread
From: Carsten Dominik @ 2008-07-19 15:27 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: emacs-orgmode


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.

- Carsten

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

* Re: Bug: Undo does not work in org-agenda-todo when logging a note
  2008-07-19 15:27 ` Carsten Dominik
@ 2008-07-19 22:46   ` Max Mikhanosha
  0 siblings, 0 replies; 3+ messages in thread
From: Max Mikhanosha @ 2008-07-19 22:46 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

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
following:

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)
    checkpoint))

(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
      (undo-start)
      (while (listp pending-undo-list)
        (undo-more 1)))))

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

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


(defun undo-until-checkpoint (&optional arg)
  (interactive)
  (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?

Regards,
  Max

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

end of thread, other threads:[~2008-07-19 22:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-18 14:19 Bug: Undo does not work in org-agenda-todo when logging a note Max Mikhanosha
2008-07-19 15:27 ` Carsten Dominik
2008-07-19 22:46   ` Max Mikhanosha

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

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).