From 354fa0e33cff72acc0182867a24b4383defd48b4 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 21 Jun 2018 01:35:16 -0400 Subject: [PATCH] Migrate to a "cplusplus" filetype for C++ in vim. This "cplusplus" filetype permits the sourcing of `cpp.vim` and `doxygen.vim` as lower-level files from itself. This should permit `doxygen.vim` to source from `cpp.vim` and avoid endless recursion, when handling code-in-comments formatting. --- vim/after/syntax/cplusplus.vim | 15 +++++++++++++++ vim/after/syntax/cpp.vim | 7 ------- vim/filetype.vim | 35 ++++++++++++++++++++++++++++++++++ vim/vimrc.fileprefs | 2 +- 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 vim/after/syntax/cplusplus.vim create mode 100644 vim/filetype.vim diff --git a/vim/after/syntax/cplusplus.vim b/vim/after/syntax/cplusplus.vim new file mode 100644 index 0000000..b0109ae --- /dev/null +++ b/vim/after/syntax/cplusplus.vim @@ -0,0 +1,15 @@ + +" This enables Basic C++ support, with my extensions. +if version < 600 + so :p:h/cpp.vim +else + runtime! syntax/cpp.vim +endif + +" This enables doxygen simultaneous with C++. +if version < 600 + so :p:h/doxygen.vim +else + runtime! syntax/doxygen.vim +endif + diff --git a/vim/after/syntax/cpp.vim b/vim/after/syntax/cpp.vim index 6644ef3..d2b3c68 100644 --- a/vim/after/syntax/cpp.vim +++ b/vim/after/syntax/cpp.vim @@ -1,12 +1,5 @@ " ADAM C++ vim syntax after extensions -" This enables doxygen simultaneous with C++. -if version < 600 - so :p:h/doxygen.vim -else - runtime! syntax/doxygen.vim -endif - syn match cxxObjects "\<[A-Z][A-Za-z0-9_]*[a-z][A-Za-z0-9_]*\>" syn match cxxMetaFunction "\<[a-z][a-z0-9]*_[a-z0-9_]*[a-z0-9]\>" diff --git a/vim/filetype.vim b/vim/filetype.vim new file mode 100644 index 0000000..4161b1e --- /dev/null +++ b/vim/filetype.vim @@ -0,0 +1,35 @@ +" Cynlib +" .cc and .cpp files can be C++ or Cynlib. +au BufNewFile,BufRead *.cc + \ if exists("cynlib_syntax_for_cc")|setf cynlib|else|setf cplusplus|endif +au BufNewFile,BufRead *.cpp + \ if exists("cynlib_syntax_for_cpp")|setf cynlib|else|setf cplusplus|endif + +" C++ +au BufNewFile,BufRead *.cxx,*.c++,*.hh,*.hxx,*.hpp,*.ipp,*.moc,*.tcc,*.inl setf cplusplus +if has("fname_case") + au BufNewFile,BufRead *.C,*.H setf cplusplus +endif + +function! CheckForADAM() + if match(getline(1, min([line("$"), 200])), '^@\(interface\|end\|class\)') > -1 + if exists("g:c_syntax_for_h") + setf objc + else + setf objcpp + endif + elseif exists("g:c_syntax_for_h") + setf c + elseif exists("g:ch_syntax_for_h") + setf ch + else + setf cplusplus + endif +endfunction + +" .h files can be C, Ch C++, ObjC or ObjC++. +" Set c_syntax_for_h if you want C, ch_syntax_for_h if you want Ch. ObjC is +" detected automatically. +au BufNewFile,BufRead *.h setf cplusplus "call CheckForADAM() +au BufNewFile,BufRead *.cxx,*.cpp,*.hpp,*.cc,*.h setf cplusplus + diff --git a/vim/vimrc.fileprefs b/vim/vimrc.fileprefs index 8eea182..c79a53b 100644 --- a/vim/vimrc.fileprefs +++ b/vim/vimrc.fileprefs @@ -5,7 +5,7 @@ au BufNewFile,BufRead *.tex map _ {!}fmt -p -s -w 70 au BufNewFile,BufRead *.tex set textwidth=78 au BufNewFile,BufRead *.java set tabstop=4 au BufNewFile,BufRead *.java set shiftwidth=4 -au BufNewFile,BufRead *.cpp,*.hpp,*.cc,*.h setf cpp +"au BufNewFile,BufRead *.cpp,*.hpp,*.cc,*.h setf cpp " Alephaish au BufNewFile,BufRead *.cpp,*.hpp,*.cc,*.h set sw=4