casouri / vundo

Visualize the undo tree.
413 stars 20 forks source link

vundo-next doesn't work for me? #12

Closed indigoviolet closed 2 years ago

indigoviolet commented 2 years ago

This is an awesome package. I am attempting to use it with undo-fu, and it draws the tree fine; <back> and <forward> work as expected. However, I am unable to move off the main stem with undo-next.

image

I don't see any errors or messages, can you help/suggest some next steps to debug this?

casouri commented 2 years ago

When you are at a parent and have multiple children that you can move to, you want to move to the first child by f (vundo-forward) and then you can switch between each children with n/p (vundo-previous/vundo-next). Admittedly that isn't the most intuitive UI, suggestions welcome ;-)

BTW the nodes in your buffer doesn't seem to be aligned, you probably want to find a monospace font that contains those Unicode characters, or you can use ASCII mode. See vundo-glyph-alist and vundo-ascii-symbols.

indigoviolet commented 2 years ago

Thanks, I was able to resolve my problem by switching fonts: as you pointed out, the nodes weren't aligned so I was hitting n/p at the wrong nodes.

  1. Why do you think my font didn't work? I'm using patched "nerd fonts" from https://github.com/ryanoasis/nerd-fonts (specifically, JetBrains Mono), and they work in all other contexts requiring monospaced text, so I was surprised by this. I experimented a bit and found that several fonts from there don't work (eg IBMPlexMono, UbuntuMono), but some do (eg. VictorMono).

I think it is worth configuring this so that it works out of the box -- I expect many people will encounter this issue. Even in ascii mode, I think there are some subtle ideas that can be taken from the undo-tree UI linked below, such as using bold to indicate active stem, using x instead of * for active node.

image

image

  1. In terms of "intuitive UI", my suggestion would be to imitate the well-known undo-tree UI. Specifically, indicating the active stem, and then using n/p to switch the active stem, keeping f/b for moving along a stem.

I feel like this package in combination with undo-fu can become the replacement for undo-tree in the emacs community, something people have been wanting for a long time.

indigoviolet commented 2 years ago

A couple more thoughts:

  1. making the tree vertical will work better as the undo list grows. It is easy to reach a wrapped state that is hard to grok

  2. ~I suggest trying to remove the need for commit: exiting the buffer should commit~ (setq vundo-roll-back-on-quit nil)

casouri commented 2 years ago

Why do you think my font didn't work?

Probably because your font doesn't have the glyph for some of the characters like , , . Emacs finds fall back font that does contain those characters and use that font for the character. Now you have glyphs from different fonts that do not necessarily have the same width and thus do not align properly.

I think it is worth configuring this so that it works out of the box -- I expect many people will encounter this issue.

I agree. I'll make ascii mode the default.

Even in ascii mode, I think there are some subtle ideas that can be taken from the undo-tree UI linked below, such as using bold to indicate active stem, using x instead of * for active node.

Keeping the active branch and switching between them isn't a trivial feature to add, because of the way we store the undo history. Let me think about that. As for x vs *, maybe x is better, I don't really have a preference. It is customizable too.

making the tree vertical will work better as the undo list grows. It is easy to reach a wrapped state that is hard to grok

One of my complains about undo-tree is displaying the tree vertically in a full-sized buffer. So when I wrote vundo I made it display the tree in a slender buffer at the bottom. Could you give an example of a wrapped state? Maybe it can be improved without using vertical trees.

indigoviolet commented 2 years ago

Thanks again for the detailed response. You were indeed correct that some of the glyphs in vundo-unicode-symbols were from different fonts. I went down this fontset rabbit hole and eventually emerged with this to ensure that all of them were being chosen from the same font:

(setq use-default-font-for-symbols nil)

;; We use unicode-fonts for the definition of Unicode block ranges
(use-package! unicode-fonts
  :config

  ;; Set Symbola for a bunch of blocks used in vundo so they are all the same
  ;; font (https://github.com/casouri/vundo/issues/12#issuecomment-1075991819)
  (dolist (unicode-block '(
                           "Box Drawing"
                           "Geometric Shapes"
                           "Geometric Shapes Extended"))
    (let* (
           (char-range (cdr (assoc unicode-block unicode-fonts-blocks)))
           (start (car char-range))
           (end (cadr char-range)))
      (set-fontset-font "fontset-startup" (cons start end) (font-spec :family "Symbola"))))
   <...snip..>
)

And to fix the wrapping and commit on quit (these are in doom-emacs, but easy enough to adapt to any config):

(use-package! vundo
  :custom
  (vundo-roll-back-on-quit nil)
  ;; (vundo-glyph-alist vundo-ascii-symbols)
  :after-call after-find-file
  :bind ("C-x u" . vundo))

(add-hook! 'vundo--mode-hook (visual-line-mode -1))

Active branch tracking would be nice, but as of now I am satisfied with my vundo setup. Cheers 🍺. Also excited for undo-hl!

casouri commented 2 years ago

Cheers! You can have a look at this article for fontsets: https://idiocy.org/emacs-fonts-and-fontsets.html. IIRC you want to use fontset-default rather than fontset-startup.

indigoviolet commented 2 years ago

Thanks, I did use your article and it was very helpful!

Just for the record, I realized after using the above setup that it has a flaw: the box drawing/geometric shapes are Symbola in all buffers, and this interferes with things like ascii art in comments - because the text, space etc are from my main programming font.

A fix with a smaller surface area is as follows:

(defun vi/vundo-setup ()
  (visual-line-mode -1) ;; prevent wrapping
  (turn-off-solaire-mode) ;; https://github.com/hlissner/emacs-solaire-mode/issues/8
  (buffer-face-set :font-family "Symbola") ;; ensure all the symbols are from Symbola
  )

(add-hook! 'vundo--mode-hook #'vi/vundo-setup)

This forces vundo-mode buffers to use Symbola entirely; and keeps all the others on the base config. I will play around and see if this has any significant issues.

Re: fontset-default vs fontset-startup: I read about this, but fontset-startup has the property that it responds and is connected to the system monospace font, which for me is in Gnome settings. I like this and wanted to avoid fixing Emacs's font independently.

casouri commented 2 years ago

Cool. For the record the article is by Alan, not me ;-) I added some detail to README explaining stuff you brought up in this issue, thanks!

On the second note, I wonder why (visual-line-mode -1) is necessary, because vundo--mode runs (setq truncate-lines t) which should nullify any word-wrapping effect. Plus vundo--mode is derived from special-mode which means it shouldn't inherit any hook from text-mode or prog-mode. Also I just remembered that you can simply set the font for vundo-default face which is used for all text in vundo buffers.

indigoviolet commented 2 years ago

For the record the article is by Alan, not me ;-)

Ah, I was thinking of https://archive.casouri.cat/note/2021/fontset/, which was also helpful!

Re: (visual-line-mode -1): it is true that (setq truncate-lines t) makes that unnecessary, but for some reason in my set up, truncate-lines is nil in the vundo buffer. I can help provide any info to debug that, if you like.

I will try tweaking the vundo-default face, that is surely an even simpler fix.

casouri commented 2 years ago

Oh cool, now I know my blog posts are actually read by other people 😄

(visual-line-mode -1): it is true that (setq truncate-lines t) makes that unnecessary, but for some reason in my set up, truncate-lines is nil in the vundo buffer. I can help provide any info to debug that, if you like.

Are you using evil? Evil probably turns on visual-line-mode which overwrites truncate-lines.