2

I want to activate checking for scons files in vim + syntastic.

My .vimrc includes:

    au BufNewFile,BufRead SCons* set filetype=scons
    let g:syntastic_scons_checkers = ['flake8']

Opening a scons file and :SyntasticInfo

    Syntastic version: 3.6.0-86 (Vim 704, Linux)
    Info for filetype: scons
    Global mode: active
    Filetype scons is active
    The current file will be checked automatically
    Available checkers: -
    Currently enabled checkers: -

The checker is not listet here. How could I activate it?

remark: flake8 works fine for python files.

Knut
  • 431
  • 4
  • 14

2 Answers2

1

Make the scons filetype an alias to python:

let g:syntastic_filetype_map = { 'scons': 'python' }

Edit: Also add this autocmd:

autocmd BufNewFile,BufRead SCons* let b:syntastic_checkers=['flake8']
lcd047
  • 5,731
  • 2
  • 28
  • 38
  • That is not really what I'm searching for. I want to have different checkers active for python and for scons. – Knut Jun 04 '15 at 12:09
  • Then in addition to the above set `au BufNewFile,BufRead SCons* let b:syntastic_checkers=['flake8']` (or whatever). – lcd047 Jun 04 '15 at 12:13
  • ok this works, thanx! It looks a bit quircky to me, what is the problem with g:syntastic_scons_checkers? – Knut Jun 04 '15 at 12:22
  • The problem is `g:` variables are global. And some day along the road you'll want to edit both `scons` and `python` files in the same session. – lcd047 Jun 04 '15 at 12:26
  • I don't get your point. In my setup I can edit both types at the same time because the have different `filetype`s. I don't understand why I can use `g:syntastic_python_checkers` for python files but can not use `g:syntastic_scons_checkers` for scons files. – Knut Jun 04 '15 at 12:41
  • Because you can load a `python` file in a window, and a `scons` file in another window, and there's a single `g:syntastic_scons_checkers` variable, that would take effect for both. Like I said: `g:` variables are global. You could write `autocmd`s to update `g:syntastic_scons_checkers` when you switch windows, but that's more complicated than the above, and it's also fragile. – lcd047 Jun 04 '15 at 12:49
  • ok, the global variable is available in both buffers, but used is only one namely `g:syntastic__checkers` – Knut Jun 04 '15 at 12:57
  • This is effectively the same solution as the one I posted. (Though maybe better since vim will report the file type is scons instead of python.) Both python and scons files will be treated the same by syntastic, with the extra line @lcd047 is suggesting you put in, you are setting a local variable in the buffer for scons files to use the 'flake8' syntax checker. – Kenneth E. Bellock Jun 04 '15 at 15:21
  • @KennethE.Bellock Not quite. Please read the exchange above. – lcd047 Jun 04 '15 at 15:49
  • @lcd047, my comment was regarding the exchange above, could you clarify where I am in error? – Kenneth E. Bellock Jun 04 '15 at 15:57
  • @KennethE.Bellock Your solution doesn't address the problem of using dfferent checkers for `scons` and for `python`. – lcd047 Jun 04 '15 at 16:07
  • @lcd047, that wasn't the point I was trying to make in my first comment. Your original solution `let g:syntastic_filetype_map = { 'scons': 'python' }`, is effectively the same solution as mine, both python files and scons files will be treated the same by syntastic. Your edit `autocmd BufNewFile,BufRead SCons* let b:syntastic_checkers=['flake8']`, is the real fix, and will work probably without the `let g:syntastic_filetype_map = { 'scons': 'python' }`. – Kenneth E. Bellock Jun 04 '15 at 16:32
  • @lcd047 My intent was not to state that one answer was better than the other. Knut expressed some confusion, and my comment was an attempt to clarify. – Kenneth E. Bellock Jun 04 '15 at 16:32
  • This suggestion may work, but still I think this is a hack and the proper way should be different. Syntastics offers `g:syntastic__checkers` variables. While `g:syntastic_python _checkers` works for `python`, `g:syntastic_scons_checkers` does not work for `scons`. It seems that the filetype `scons` needs some kind of activation first. I tried to add `scons` to `DEFAULT_CHECKER` in `syntastic/registry.vim` but this didn't change the output of `:SyntasticInfo` – Knut Jun 10 '15 at 10:11
  • @Knut There is no special support for `scons` in syntastic. `scons` is not an official filetype supported by Vim, and it's virtually identical to Python. For this reason, there won't be any special support for `scons` in syntastic in the foreseeable future. The above solution is your best bet. – lcd047 Jun 10 '15 at 10:22
0

I just set SCons file type to be python at load with something similar to what you have. It then works for me.

" Display scons files with python syntax
autocmd BufReadPre,BufNewFile SConstruct set filetype=python
autocmd BufReadPre,BufNewFile SConscript set filetype=python

Another bit that might be hanging you up... if you have a snippet in your .vimrc like this...

au BufWinLeave * silent! mkview
au BufWinEnter * silent! loadview

Then you will need to remove the view file for the file you are trying to open before it will set the correct filetype on file open.

  • That is not really what I'm searching for. I want to have different checkers (and syntax) active for python and for scons, thus I want to have filetype=scons. And I don't use views. – Knut Jun 04 '15 at 12:11