simnalamburt / vim-mundo

:christmas_tree: Vim undo tree visualizer

Home Page:https://simnalamburt.github.io/vim-mundo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add tags and tags switch commands

00sapo opened this issue · comments

It would be useful to have a command to tag versions (similarly to git tags) and a command to switch to a certain tag version.

For instance, when you're debugging code, you often need to observe the program behavior with different strategies, but you don't want to put wrong code on git...

To add tag support, we'll need to store the tag information somewhere. Does vim undotree have such feature?

Currently, vim-mundo is just a fancy frontend for vim's undotree feature, it doesn't have any external storage or something.

but you don't want to put wrong code on git...

Why not? You could make multiple branches with different experiments. That would allow you to quickly switch between them (including groups of files instead of individual ones), diff them, and build upon them. And when you're done, delete the branches. All without pushing that experimental code anywhere.

However, maybe mundo can better communicate what the numbers in the undotree mean. Given the graph:

o    [5] <1 min ago 
|    
o    [4] <1 min ago 
|    
| o  [3] <1 min ago 
| |  
| @  [2] 7 mins ago 
|/   
o    [1] 7 mins ago 
|    
o    [0] Original   

You can use :undo 4 to apply the change state for the node marked [4]. So the nodes are already tagged, but not with names! Adding names, tracking them in mundo, showing them in the graph, and knowing when to clear them seems like unnecessary complexity that isn't part of the goal of mundo (visualizing the undotree)).

However, if you really want to use undo instead of git, you can whip something up like so:

function! s:GetMarkList()
    let b:undomarks = get(b:, 'undomarks', {})
    return b:undomarks
endf

function! s:SetMarkList(key, val)
    let marks = s:GetMarkList()
    let marks[a:key] = a:val
endf

function! s:UndoComplete(...)
    return keys(s:GetMarkList())
endf

" These commands only apply to the current buffer, not the mundo
" buffer. (This code doesn't integrate with mundo at all.)
command! -nargs=+ UndoMark call s:SetMarkList(<q-args>, undotree().seq_cur)
command! -nargs=+ -complete=customlist,s:UndoComplete UndoJump exec 'undo' get(s:GetMarkList(), <q-args>, 'invalid mark')

Then you can :UndoMark blah and :UndoJump <Tab>