[nvim] fix some bugs with indentation detection yet again.

This commit is contained in:
Dmytro Meleshko 2021-05-22 16:22:35 +03:00
parent c62a48504f
commit f06382d651
2 changed files with 13 additions and 4 deletions

View file

@ -63,8 +63,17 @@ if exists(':Sleuth')
" shiftwidth to the unreasonable value picked above, which vim-sleuth
" internally compares with its local `s:default_shiftwidth`, sees that both
" are the same, and proceeds to execute the indent detection algorithm.
" Boom, my work here is done.
autocmd BufEnter * let &l:shiftwidth = s:fake_default_shiftwidth | Sleuth
" ALSO Note how I'm not using `BufEnter` as vim-sleuth does because
" apparently `BufWinEnter` leads to better compatibility with the
" indentLine plugin and potentially less useless invocations (see the note
" about window splits in the docs for this event). Oh, one last thing:
" vim-sleuth forgets to assign the tabstop options, which I have to do as
" well. But anyway, boom, my work here is done.
autocmd BufWinEnter *
\ let &l:shiftwidth = s:fake_default_shiftwidth
\| Sleuth
\| let &l:tabstop = &l:shiftwidth
\| let &l:softtabstop = &l:shiftwidth
augroup END
" HACK: In case you are wondering why I'm using Polyglot's bundled vim-sleuth

View file

@ -15,8 +15,8 @@ set commentstring=//%s
function SetIndent(expandtab, shiftwidth)
let &l:expandtab = a:expandtab
let &l:shiftwidth = str2nr(a:shiftwidth)
let &l:tabstop = &shiftwidth
let &l:softtabstop = &shiftwidth
let &l:tabstop = &l:shiftwidth
let &l:softtabstop = &l:shiftwidth
endfunction
command -nargs=1 Indent call SetIndent(1, <q-args>)
command -nargs=1 IndentTabs call SetIndent(0, <q-args>)