* undo-tree: restore state from register for different buffer?
@ 2014-06-11 15:44 Thorsten Jolitz
2014-06-11 17:24 ` Thorsten Jolitz
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Jolitz @ 2014-06-11 15:44 UTC (permalink / raw)
To: help-gnu-emacs
Hi List,
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.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: undo-tree: restore state from register for different buffer?
2014-06-11 15:44 undo-tree: restore state from register for different buffer? Thorsten Jolitz
@ 2014-06-11 17:24 ` Thorsten Jolitz
0 siblings, 0 replies; 2+ messages in thread
From: Thorsten Jolitz @ 2014-06-11 17:24 UTC (permalink / raw)
To: help-gnu-emacs
Thorsten Jolitz <tjolitz@gmail.com> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-11 17:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-11 15:44 undo-tree: restore state from register for different buffer? Thorsten Jolitz
2014-06-11 17:24 ` Thorsten Jolitz
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).