vim-jp / vim-cpp

c or cpp syntax files
145 stars 44 forks source link

c_no_curly_error does not work on lambdas if filetype is not exactly 'cpp' #11

Closed bmerry closed 10 years ago

bmerry commented 11 years ago

I often edit code with filetype set to 'cpp.doxygen', which gives C++ syntax highlighting for the code and doxygen highlighting on the comments. However, the lines

if exists("c_no_curly_error")
  if &filetype ==# 'cpp' && !exists("cpp_no_cpp11")

do not match a filetype of cpp.doxygen, so lambda functions still have the {} marked as errors. If I change the filetype to cpp then they are no longer marked as errors.

Unfortunately I don't know enough about the vim scripting language to be able to suggest a fix.

mattn commented 10 years ago

This change was merged

isobit commented 7 years ago

What if the filetype is something like arduino? I'm currently having an issue with the vim-polyglot arduino syntax where lambda brackets are marked as errors. Should the arduino filetype be renamed cpp.arduino to be compatible, or is there another way of doing this filetype check?

It would be nice to be able to set some global option that tells vim-cpp that a file is explicitly a cpp file as an override.

mattn commented 7 years ago

How about to setlocal filetype=cpp syntax=arduino ?

isobit commented 7 years ago

Hm, no-go. Just tried it, &ft still ends up being 'arduino' and thus isn't matched. I also tried set ft=cpp.arduino and set ft=arduino.cpp to no avail, both only use one of the syntaxes (cpp and arduino, respectively).

mattn commented 7 years ago

What problem with setlocal filetype=cpp syntax=arduino?

isobit commented 7 years ago

It doesn't work. Still highlights the file as if it were just arduino.

mattn commented 7 years ago

Do you set let c_no_curly_error=1 in your vimrc?

isobit commented 7 years ago

Ah okay, got it to work. I'm not actually sure why it wasn't working for me before, but setlocal filetype=cpp syntax=arduino does work for me now. Thanks for the help!

If anyone else finds this thread, here's what I ended up putting in my vimrc:

" properly indent c++11 lambdas
autocmd FileType cpp setlocal cindent cino=j1,(0,ws,Ws

" force cpp filetype for arduino syntax
autocmd FileType arduino setlocal filetype=cpp syntax=arduino