1ec28f7117
* Avoids highlighting some matches when inside C++ comments * Add operators << and >> * Automatic initialization when opening Vim in the Haiku source directory (if you use the same directory layout as me) * Matches are highlighted in red, rather than reusing the "Search" match group. You can pick another color by editing the "highlight Style" definition. Improvements are still welcome.
54 lines
2.4 KiB
VimL
54 lines
2.4 KiB
VimL
" Coding guidelines check for Haiku.
|
|
" Copyright 2010-2014 Haiku, Inc.
|
|
" Distributed under the terms of the MIT licence.
|
|
"
|
|
" Insert this into your vimrc or as some autoloaded file. It will register
|
|
" several matchadd regular expressions to try to catch common style violations:
|
|
" lines longer than 80 chars, missing space around operators or after keywords,
|
|
" indentation with spaces instead of tabs, and so on. Potential problems are
|
|
" highlighted with a beautiful red background.
|
|
"
|
|
" This regex-based method is not perfect: there may be some false positive and
|
|
" some cases are not checked. Feel free to improve on this.
|
|
"
|
|
" The matches are only enabled when starting vim from /Donnees/Dev/Haiku/haiku
|
|
" or a subdirectory of it. This way it doesn't get in the way when working on
|
|
" other projects. FuncHaikuCheck() can also be called manually to enable the
|
|
" matches in other directories.
|
|
|
|
:highlight Style ctermbg=red guibg=red
|
|
:fu FuncHaikuCheck()
|
|
call matchadd('Style', '\%>80v.\+', -1) " line over 80 char
|
|
call matchadd('Style', '^\s* \s*', -1) " spaces instead of tabs
|
|
call matchadd('Style', '\(for\|if\|select\|while\)(', -1)
|
|
"missing space after control statement
|
|
call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*//\S', -1)
|
|
" Missing space at comment start
|
|
|
|
call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*\w[,=>+\-*;]\w', -1)
|
|
call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*\w\(<<\|>>\)\w', -1)
|
|
"operator without space around it (without false positive on
|
|
"templated<type>)
|
|
call matchadd('Style', '^[^#]^\(\(?!\/\/\|\/\*\).\)*[^<]\zs\w*/\w', -1)
|
|
"operator without space around it (without false positive on
|
|
"#include <dir/file.h>)
|
|
call matchadd('Style', '^[^/]\{2}.*\zs[^*][=/+\-< ]$', -1)
|
|
"operator at end of line (without false positives on /* and */, nor
|
|
"char*\nClass::method())
|
|
call matchadd('Style', '^[^#].*\zs[^<]>$', -1)
|
|
" > operator at EOL (without false positive on #include <file.h>)
|
|
call matchadd('Style', '){', -1) " Missing space after method header
|
|
call matchadd('Style', '}\n\s*else', -1) " Malformed else
|
|
call matchadd('Style', '\s$', -1) "Spaces at end of line
|
|
call matchadd('Style', ',\S', -1) " Missing space after comma
|
|
call matchadd('Style', '^}\n\{1,2}\S', -1)
|
|
" Less than 2 lines between functions
|
|
call matchadd('Style', '^}\n\{4,}\S', -1)
|
|
" More than 2 lines between functions
|
|
:endfu
|
|
|
|
if stridx(getcwd(), '/Donnees/Dev/Haiku/haiku') == 0
|
|
" Webkit indentation rules
|
|
call FuncHaikuCheck()
|
|
endif
|