undotree
undotree copied to clipboard
:UndoTreeToggle causes E121 and E116
Using :UndoTreeToggle after editing a file generates this error
Error detected while processing function undotree#UndotreeToggle[11]..25[13]..27[55]..23[5]..38[65]..39:
line 64:
E121: Undefined variable: matchwhat
E116: Invalid arguments for function <SNR>91_log
functionality does not seem to be affected.
Reproduced this using this config on neovim v0.4.3:
call plug#begin('~/.nvim/plugged')
Plug 'mbbil/undotree'
call plug#end()
Update: Same config does not cause error in vim
I also faced this issue in neovim and not in vim.
Above errors occurred when i do these actions: Opening UndoTree window using :UndoTreeToggle and :UndoTreeShow, opening Diff panel, toggling relative timestamp and undoing, redoing while UndoTree window open.
Strange enough, turn off the diff panel completely makes errors disappear when doing those actions.
let g:undotree_DiffAutoOpen = 0
Seems like the diff panel are the reason causing the error.
I think there's a bug with the scope of the variable matchwhat
and the following: undotree_HighlightChangedWithSign
.
I did the following in my init.lua
:
vim.g.undotree_HighlightChangedWithSign = 0
And modifed undotree.vim
adding let matchwhat = ''
just before the loop on line 1173 because on line 1205 the variable is out of scope.
git diff
diff --git a/autoload/undotree.vim b/autoload/undotree.vim
index 7e74ea6..477940e 100644
--- a/autoload/undotree.vim
+++ b/autoload/undotree.vim
@@ -1170,6 +1170,7 @@ function! s:diffpanel.ParseDiff(diffresult, targetBufnr) abort
let w:undotree_diffsigns = 0
let lineNr = 0
let l:lastLine = line('$')
+ let matchwhat = ''
for line in a:diffresult
let matchnum = matchstr(line,'^[0-9,\,]*[acd]\zs\d*\ze')
if !empty(matchnum)
@@ -1202,7 +1203,7 @@ function! s:diffpanel.ParseDiff(diffresult, targetBufnr) abort
let self.changes.add += 1
if g:undotree_HighlightChangedText
- if matchtext != ' '
+ if matchtext != ' ' && matchwhat != ''
let matchtext = '\%'.lineNr.'l\V'.escape(matchtext[1:],'"\') "remove beginning space.
call s:log("matchadd(".matchwhat.") -> ".matchtext)
call add(w:undotree_diffmatches,matchadd((matchwhat ==# 'a' ? g:undotree_HighlightSyntaxAdd : g:undotree_HighlightSyntaxChange),matchtext))
I will also add that switch from FISH to Zsh fixed everything without my changes. Now I'm thinking my problem was something to do with the way FISH works.
@Xmgplays Curious what shell you're using.
Seeing an issue related to matchwhat
variable, same E121 error code (context: following the short tutorial video from Primagen). And FWIW, I'm using fish-shell on macOS too.

In macos when using zsh shell you need the following: vim.cmd('set shellquote=') vim.cmd('set shellxquote=')