Yggdroot / indentLine

A vim plugin to display the indention levels with thin vertical lines
MIT License
4.14k stars 227 forks source link

autoResetWidth doesn't work when shiftwidth/tabstop value is changed by an autocommand #298

Open MasterMedo opened 4 years ago

MasterMedo commented 4 years ago

autoResetWidth doesn't work when shiftwidth/tabstop value is changed by an autocommand.

Steps to reproduce:

  1. create neovim config .vimrc given below
  2. create python file file.py given below
  3. open nvim with nvim -u .vimrc file.py
  4. inside nvim type :source .vimrc

nvim config .vimrc:

call plug#begin('~/.vim/plugged')
  Plug 'Yggdroot/indentline'
call plug#end()

set shiftwidth=2
set tabstop=2
set softtabstop=2
set expandtab

augroup vimrc
  autocmd!
  autocmd FileType python setlocal ts=4 sts=4 sw=4
  autocmd SourcePost  * set filetype+=
augroup END

python file file.py:

import json

def nsum(x):
    if isinstance(x, int):
        return x
    if isinstance(x, dict):
        if 'red' in x.values():
            return 0
    s = 0
    for i in x:
        if isinstance(x, (list, tuple)):
            s += nsum(i)
        elif isinstance(x, dict):
            s += nsum(x[i])
    return s

with open('../input/12.txt') as fp:
    data = json.load(fp)

print nsum(data)

after opening nvim with nvim -u .vimrc file.py:

image

after doing :source .vimrc

image

:setlocal shiftwidth? -> shiftwidth=4 :setlocal tabstop? -> tabstop=4

Doing :setlocal sw+=0 reverts indentLine to what it should be. I tried changing the autocmd SourcePost * set filetype+= line in the .vimrc to many variations to accomodate IndentLinesReset like:

  1. autocmd SourcePost * set filetype+= | IndentLinesReset
  2. autocmd SourcePost * set filetype+= | if has_key(plugs, 'indentline') | call IndentLinesReset(&shiftwidth) | endif

but I've only been running into errors:

E492: Not an editor command: IndentLinesReset E117: Unknown function: IndentLinesReset E521: Number required: '(&shiftwidth) | endif'

Can this be patched or do you have an idea for a dirty workaround?