Skip to content

Commit

Permalink
Handle buffer numbers correctly in autocmd
Browse files Browse the repository at this point in the history
As far as I know this has never caused a problem but it is good to get
it right.
  • Loading branch information
airblade committed Sep 14, 2023
1 parent a5b5269 commit c08f03e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions plugin/rooter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,20 @@ command! -bar RooterToggle call <SID>toggle()

augroup rooter
autocmd!
autocmd VimEnter,BufReadPost,BufEnter * nested if !g:rooter_manual_only | Rooter | endif
autocmd BufWritePost * nested if !g:rooter_manual_only | call setbufvar('%', 'rootDir', '') | Rooter | endif
autocmd VimEnter,BufReadPost,BufEnter * nested if !g:rooter_manual_only | call <SID>rooter(+expand('<abuf>')) | endif
autocmd BufWritePost * nested if !g:rooter_manual_only | call setbufvar(+expand('<abuf>'), 'rootDir', '') | call <SID>rooter(+expand('<abuf>')) | endif
augroup END


function! s:rooter()
function! s:rooter(...)
if !s:activate() | return | endif

let root = getbufvar('%', 'rootDir')
let bufnr = a:0 ? a:1 : '%'

let root = getbufvar(bufnr, 'rootDir')
if empty(root)
let root = s:root()
call setbufvar('%', 'rootDir', root)
call setbufvar(bufnr, 'rootDir', root)
endif

if empty(root)
Expand Down

0 comments on commit c08f03e

Please sign in to comment.