help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: undo-tree: restore state from register for different buffer?


From: Thorsten Jolitz
Subject: Re: undo-tree: restore state from register for different buffer?
Date: Wed, 11 Jun 2014 19:24:51 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Thorsten Jolitz <address@hidden> writes:


> I create a temporary buffer *FOO* and modify it in a program. I would
> like to use undo-tree to
>
> ,---------------------------------
> | undo-tree-save-state-to-register
> `---------------------------------
>
> and later 
>
> ,--------------------------------------
> | undo-tree-restore-state-from-register
> `--------------------------------------
>
> but not for the same buffer, i.e. *FOO* is killed after the state is
> saved to say register ?u, but later on a new identical (or almost
> identical) temporary buffer named *FOO* too is created, and in this
> buffer the saved state should be restored form register ?u. 
>
> That does not work out of the box, rather a user-error is thrown because
>
> ,------------------------------------------------------------------
> | (not (eq (current-buffer) (undo-tree-register-data-buffer data)))
> `------------------------------------------------------------------
>
> I copied & modified the undo-tree sources and changed this user error to
> a simple message and tried to aset (current-buffer) as first element of
> 'data' (the saved-state vector), but to no avail, there is no error
> anymore, but nothing happens.
>
> On a lower level there are `buffer-undo-list' and `buffer-undo-tree'
> that could be stored before killing original *FOO*, but I could not figure
> out if its possible - and how to - restore the state of new *FOO* using
> this list or tree. 

I think I more or less figured it out myself, here is some pseudocode:
      
#+BEGIN_SRC emacs-lisp pseudocode
  ;; [in buffer *FOO*]
  (undo-tree-mode t)
  (call-interactively fun))
  (undo-tree-visualize)   ; HACK (buffer-undo-tree is nil initially)
  (undo-tree-visualizer-quit)
  (setq saved-undo-tree buffer-undo-tree)
  ;; [kill *FOO*]
  ;; [create new *FOO*]
  (undo-tree-mode t)
  (org-set-local 'buffer-undo-tree saved-undo-tree)
  (undo-tree-undo (undo-tree-count buffer-undo-tree))
#+END_SRC

Maybe there are better ways, but this works already.

-- 
cheers,
Thorsten




reply via email to

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