emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Mikhanosha <max@openchat.com>
To: Carsten Dominik <dominik@uva.nl>
Cc: emacs-orgmode@gnu.org
Subject: Re: Bug: Undo does not work in org-agenda-todo when logging a note
Date: Sat, 19 Jul 2008 18:46:02 -0400	[thread overview]
Message-ID: <87r69po5lh.wl%max@openchat.com> (raw)
In-Reply-To: <489BB9A8-0D23-4295-9F16-9617A341A9E7@uva.nl>

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

      reply	other threads:[~2008-07-19 22:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r69po5lh.wl%max@openchat.com \
    --to=max@openchat.com \
    --cc=dominik@uva.nl \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).