reddit / emacs
Vundo is great! (visual undo-tree for emacs-28)
ideasman_42 路 2022-04-06 21:34
Recently I've been using Vundo (an undo-tree that can be traversed visually, it works with Emacs-default undo system, undo-fu etc).
It's really great, it doesn't need to run in the background - it's very stable, and provides a quick way to navigate down branches of a tree (when basic undo/redo isn't enough).
I've been testing it and reported a few bugs that were fixed by `casouri`, I've also made some minor contributions & optimizations myself.
I think this package is ready for general use, recommend others give it a go.
See: https://github.com/casouri/vundo
Also, my config with vim-motion keys for the key-map.
(use-package vundo
:commands (vundo)
:straight (vundo :type git :host github :repo "casouri/vundo")
:config
;; Take less on-screen space.
(setq vundo-compact-display t)
;; Better contrasting highlight.
(custom-set-faces
'(vundo-node ((t (:foreground "#808080"))))
'(vundo-stem ((t (:foreground "#808080"))))
'(vundo-highlight ((t (:foreground "#FFFF00")))))
;; Use `HJKL` VIM-like motion, also Home/End to jump around.
(define-key vundo-mode-map (kbd "l") #'vundo-forward)
(define-key vundo-mode-map (kbd "<right>") #'vundo-forward)
(define-key vundo-mode-map (kbd "h") #'vundo-backward)
(define-key vundo-mode-map (kbd "<left>") #'vundo-backward)
(define-key vundo-mode-map (kbd "j") #'vundo-next)
(define-key vundo-mode-map (kbd "<down>") #'vundo-next)
(define-key vundo-mode-map (kbd "k") #'vundo-previous)
(define-key vundo-mode-map (kbd "<up>") #'vundo-previous)
(define-key vundo-mode-map (kbd "<home>") #'vundo-stem-root)
(define-key vundo-mode-map (kbd "<end>") #'vundo-stem-end)
(define-key vundo-mode-map (kbd "q") #'vundo-quit)
(define-key vundo-mode-map (kbd "C-g") #'vundo-quit)
(define-key vundo-mode-map (kbd "RET") #'vundo-confirm))
(with-eval-after-load 'evil (evil-define-key 'normal 'global (kbd "C-M-u") 'vundo))
whudwl 路 2022-04-06 22:01
How does it compare to https://www.emacswiki.org/emacs/UndoTree
ideasman_42 路 2022-04-06 22:32
Not sure, I stopped using undo-tree as it kept [corrupting my undo history](https://emacs.stackexchange.com/q/31438/2418) which is a deal breaker.
Vundo only provides tree navigation (no diffing view for e.g.), not sure what else undo-tree supports that users may miss.
I'd happily trade features for reliability, although I know some users didn't seem to hit bugs as often as I managed to - YMMV.
collapsing_spacetime 路 2022-04-07 00:06
yea, i had to explicitly use `undo-tree`'s undo commands in order to prevent corruption. mixing them with emac's commands breaks things... though, isnt `undo-tree` part of core emacs now? 馃
MangyCanine 路 2022-04-07 00:22
I鈥檝e been using undo-tree with the 28 alphas, betas, and now 28.1, and I鈥檝e never had my undo corrupted. I鈥檝e also enabled undo-tree鈥檚 persistent undo, and it鈥檚 been awesome.
josior 路 2022-04-07 01:01
Thanks for sharing the project! Does it support undo-region? It's something I miss when using undo-tree.
markasoftware 路 2022-04-07 01:34
I've never had a corrupted undo either.
Hooxen 路 2022-04-07 04:00
persistent undo?
karthink 路 2022-04-07 05:35
undo-tree supports undo-in-region, see `undo-tree-enable-undo-in-region`. I think the behavior is subtly different from what you might expect, though.
ideasman_42 路 2022-04-07 07:13
It's not part of core.
Regarding mixing emacs undo command - I only ever used undo trees undo/redo and got errors still on a reasonably regular basis.
ideasman_42 路 2022-04-07 07:14
[undo-fu-session](https://gitlab.com/ideasman42/emacs-undo-fu-session) can be used for persistent undo with emacs built-in undo.
ideasman_42 路 2022-04-07 07:18
According to `casouri` while it does work it could be better supported (can't find a reference for this though).
asymptotically508 路 2022-04-07 07:45
Congratulations on releasing 1.0.0, /u/casouri! :)
thetemp_ 路 2022-04-07 07:58
Is there some way to highlight the changed area? It's especially difficult to see what's changed, when it moves to a different part of the buffer. Might be a good use-case for the built-in "pulse.el" package.
ideasman_42 路 2022-04-07 08:05
Not built-in, I was thinking we could have `vundo-before-change-hook` and `vundo-after-change-hook` which would allow this to be supported by adding in custom functions.
nagora 路 2022-04-07 09:14
undo-tree's corruption was fixed some time ago and it has been rock-solid for me ever since.
ideasman_42 路 2022-04-07 10:09
That's good to hear... I'm not totally convinced about this after reading: https://www.dr-qubit.org/Lost_undo-tree_history.html
From this post there seems to be an inherent limitation with how undo tree stores it's undo data and emacs garbage collection which could always free some of these undo steps.
Since I've managed to get things working without undo-tree I'm happy to continue using `undo-fu` (undo/redo), `undo-fu-session` (for persistent undo), and `Vundo` for tree navigation. As all of these are light weight packages that seem less error prone.
andreyorst 路 2022-04-07 15:54
Thanks for sharing, I wanted to try out some alternatives to undo-tree but didn't know of any. BTW, undo-tree can be traveled visually as well via `unde-tree-visualise`.
MangyCanine 路 2022-04-07 16:02
undo-tree has an option to save the undo data into a file when you stop editing a file or exit emacs. This way, you can re-edit a file or restart emacs and still have access to all of the old undo data. Of course, this only works as long as all changes to a file occurs inside emacs; if something else changes the file, the undo data becomes invalid (and this is properly detected).
MangyCanine 路 2022-04-07 16:04
Emacs' built-in undo really isn't all that great. Undo-tree (and Vundo, I assume) makes undo sane again.
casouri 路 2022-04-07 17:31
Thanks :-)
casouri 路 2022-04-07 17:34
You can use undo-in-region just fine, but they are regarded as regular modifications to the buffer, rather than an undo that reverts the buffer to a previous state.
ideasman_42 路 2022-04-07 21:35
Yep, I'm aware of undo tree, just not such a fan of having to replace my undo system since it's a heavy solution which has yielded difficult to solve bugs in the past.
Hooxen 路 2022-04-07 21:48
wow it鈥檚 like version control but without it sounds pretty awesome with potentially a ton of state accumulating though鈥ill try it out thanks for the description!
ideasman_42 路 2022-04-07 21:50
Emacs 28 can do `undo-only` and `undo-redo` - exposing undo as linear which is fine for almost all uses. When it's not and I want to access some other part of the undo history, I can launch Vundo - I find this works nicely.
MangyCanine 路 2022-04-08 00:31
Well, kinda, sorta. I wouldn't use it as a replacement for version control -- the undo data is just too fragile. If anything touches the file outside of Emacs, the undo data becomes invalid.
However, just the other day, I was working on a single file when I realized that I made too many changes (I wanted to make an intermediate commit as a baseline for some new changes). There were a fair amount of changes. With undo-tree, I just unwound the changes way back, committed the file, and then walked back down the tree to the point I wanted to be. It was awesome.
Yes, I could have done that with plain undo, but it's risky. If you use plain undo, you have to be super-careful to never do anything that moves point. If you do while hitting the undo key, you're screwed as you're now in undo-undo (redo) mode. With undo-tree, I can undo changes, move around the file, look at other files, etc., without having to worry about the stupid undo/redo state.
MangyCanine 路 2022-04-08 00:43
Plain undo is only linear as long as you don't move the cursor. If you move the cursor while undoing changes, you're now screwed because you just switched from undo to undo-undo (redo) mode (and it gets much worse if you further move the cursor while undoing). Being able to move the cursor, etc., while undoing is extremely useful because you can now view other files, examine commit logs/changes, etc.. Undo-tree gives you all that (and I assume Vundo does also).
ideasman_42 路 2022-04-08 02:03
I can't redo this behavior, moving the cursor doesn't cause any problems for me - with evil mode at least.
thetemp_ 路 2022-04-08 05:20
Hey, I just found [undo-hl](https://github.com/casouri/undo-hl), which is also by casouri, and looks to be less than a month old. I assume they plan to integrate it with vundo? I haven't figured out which vundo function to add to `undo-hl-undo-commands`.
I'm liking both of these packages a lot. I also gave up on undo-tree after losing some data a while back. It was nothing major, but it caused me to distrust anything that tries to re-implement the Emacs undo system. A "simple" visualization of the existing `buffer-undo-list` is a great idea!
ideasman_42 路 2022-04-08 06:02
`undo-hl` works really nicely with vundo, although making it ONLY work with vundo was a bit more involved.
Submitted a [PR to simplify that](https://github.com/casouri/vundo/pull/44).
MangyCanine 路 2022-04-08 17:17
Ah, that's how standard emacs works. Evil mode must have improved upon it (or maybe that's just how vim works).
ideasman_42 路 2022-04-09 00:38
If you want undo/redo with vanilla emacs (27 even), you could use undo-fu, it works the same as emacs built-in undo-redo.
Bodertz 路 2022-04-09 02:06
I think you can use `undo-only` for that.
[deleted] 路 2022-04-09 02:09
[deleted]
_noctuid 路 2022-04-09 02:17
I tried it after the changes and still had corruption. I'm sticking with undo-fu and will definitely check out vundo. Thanks for pointing it out.
ideasman_42 路 2022-04-09 02:23
Persistent undo is pretty nice but you don't need undo-tree for this functionality, see [undo-fu-session](https://gitlab.com/ideasman42/emacs-undo-fu-session) for a stand-alone package.
ideasman_42 路 2022-04-09 02:25
> Yes, I could have done that with plain undo, but it's risky. If you use plain undo, you have to be super-careful to never do anything that moves point.
Try [undo-fu](https://gitlab.com/ideasman42/emacs-undo-fu), it's a thin wrapper on emacs built-in undo/redo but doesn't have this limitation.
CodyChan 路 2022-04-09 16:51
For me, the real issue of undo-tree is the performance, I'm using Spacemacs, it saves the undo-tree history files (`undo-tree-make-history-save-file-name`) into `~/.emacs.d/.cache/undo`, if I edit a file for quite a while such as taking notes for a PDF, the cache file for this buffer will be about tens of MB, and Emacs will be slow to respond once you try to undo the editing for the buffer, `undo-limit/undo-strong-limit/undo-outer-limit` don't seem to fix it. I have to delete the cache file and toggle undo-tree-mode on and off to solve the sluggish issue.
I've tried several times to search for an alternative and I saw many people complaining about undo-tree and the package is not actively maintained.
Do you try to completely replace undo-tree, I mean visual-undo-tree + history file + good performance?
ideasman_42 路 2022-04-10 01:18
So firstly, I never really got into undo-tree, it was breaking for me early on so I looked into an alternative (which became ``undo-fu``).
After that some people requested persistent undo, which I'd never used, so I looked into this and created ``undo-fu-session`` (based on the unmaintained ``undohist``w/ fixes and support for storing the tree-structure).
I've never run into performance issues, although I enable ``undo-fu-session-linear`` which only saves linear undo steps (removing branches than are later undone), which tends to reduce the size of the data stored. I can't recall ever needing to access this undo information so I don't mind loosing it on file reload.
But you could set the limits and I assume this would work without problems as this is just emacs default undo.
Only recently I looked into ``Vundo``, so I suppose now I have replaced most of undo-tree's functionality. I much rater do this with small well maintained packages though. I ran into 2 fairly bad bugs with Vundo early on which /u/casouri fixed, now as far as I can see the package is bug-free - something its only reasonably to expect for packages below a certain level of complexity.
[deleted] 路 2022-04-12 06:48
[deleted]