Skip to content

Commit b1b7667

Browse files
committed
autochdir will sometimes change the bufname('%') results and making it harder to tell if the buffer is belong to undotree. Switching to a buf variable would be much reliable.
1 parent a80159c commit b1b7667

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

autoload/undotree.vim

+12-6
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function! s:getUniqueID()
168168
return s:cntr
169169
endfunction
170170

171-
" Debug...
171+
" Set to 1 to enable debug log
172172
let s:debug = 0
173173
let s:debugfile = $HOME.'/undotree_debug.log'
174174
" If debug file exists, enable debug output.
@@ -307,12 +307,12 @@ endfunction
307307

308308
function! s:undotree.Action(action)
309309
call s:log("undotree.Action() ".a:action)
310-
if !self.IsVisible() || bufname("%") != self.bufname
311-
echoerr "Fatal: window does not exists."
310+
if !self.IsVisible() || !exists('b:isUndotreeBuffer')
311+
echoerr "Fatal: window does not exist."
312312
return
313313
endif
314314
if !has_key(self,'Action'.a:action)
315-
echoerr "Fatal: Action does not exists!"
315+
echoerr "Fatal: Action does not exist!"
316316
return
317317
endif
318318
silent exec 'call self.Action'.a:action.'()'
@@ -499,6 +499,11 @@ function! s:undotree.Show()
499499
endif
500500
call s:exec("silent keepalt ".cmd)
501501
call self.SetFocus()
502+
503+
" We need a way to tell if the buffer is belong to undotree,
504+
" bufname() is not always reliable.
505+
let b:isUndotreeBuffer = 1
506+
502507
setlocal winfixwidth
503508
setlocal noswapfile
504509
setlocal buftype=nowrite
@@ -538,8 +543,7 @@ function! s:undotree.Update()
538543
return
539544
endif
540545
" do nothing if we're in the undotree or diff panel
541-
let bufname = bufname('%')
542-
if bufname == self.bufname || bufname == t:diffpanel.bufname
546+
if exists('b:isUndotreeBuffer')
543547
return
544548
endif
545549
if (&bt != '' && &bt != 'acwrite') || (&modifiable == 0) || (mode() != 'n')
@@ -1172,6 +1176,8 @@ function! s:diffpanel.Show()
11721176
endif
11731177
call s:exec_silent(cmd)
11741178

1179+
let b:isUndotreeBuffer = 1
1180+
11751181
setlocal winfixwidth
11761182
setlocal winfixheight
11771183
setlocal noswapfile

0 commit comments

Comments
 (0)