From mboxrd@z Thu Jan 1 00:00:00 1970 From: Max Mikhanosha Subject: Re: Bug: Undo does not work in org-agenda-todo when logging a note Date: Sat, 19 Jul 2008 18:46:02 -0400 Message-ID: <87r69po5lh.wl%max@openchat.com> References: <87hcancm1h.wl%max@openchat.com> <489BB9A8-0D23-4295-9F16-9617A341A9E7@uva.nl> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KKLBl-0001F6-BJ for emacs-orgmode@gnu.org; Sat, 19 Jul 2008 18:46:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KKLBk-0001Ed-OH for emacs-orgmode@gnu.org; Sat, 19 Jul 2008 18:46:04 -0400 Received: from [199.232.76.173] (port=56168 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KKLBk-0001ET-AF for emacs-orgmode@gnu.org; Sat, 19 Jul 2008 18:46:04 -0400 Received: from p84-72.acedsl.com ([66.114.84.72]:2222 helo=momoland.openchat.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KKLBj-0002hM-M6 for emacs-orgmode@gnu.org; Sat, 19 Jul 2008 18:46:03 -0400 In-Reply-To: <489BB9A8-0D23-4295-9F16-9617A341A9E7@uva.nl> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Carsten Dominik Cc: emacs-orgmode@gnu.org 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