1" Coding guidelines check for Haiku.
2" Copyright 2010-2014 Haiku, Inc.
3" Distributed under the terms of the MIT licence.
4"
5" Insert this into your vimrc or as some autoloaded file. It will register
6" several matchadd regular expressions to try to catch common style violations:
7" lines longer than 80 chars, missing space around operators or after keywords,
8" indentation with spaces instead of tabs, and so on. Potential problems are
9" highlighted with a beautiful red background.
10"
11" This regex-based method is not perfect: there may be some false positive and
12" some cases are not checked. Feel free to improve on this.
13"
14" The matches are only enabled when starting vim from /Donnees/Dev/Haiku/haiku
15" or a subdirectory of it. This way it doesn't get in the way when working on
16" other projects. FuncHaikuCheck() can also be called manually to enable the
17" matches in other directories.
18
19:highlight Style ctermbg=red guibg=red
20:fu FuncHaikuCheck()
21	call matchadd('Style', '\%>80v.\+', -1) " line over 80 char
22	call matchadd('Style', '^\s* \s*', -1)  " spaces instead of tabs
23	call matchadd('Style', '[\t ]\(for\|if\|select\|switch\|while\|catch\)(', -1)
24		"missing space after control statement
25	call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*//\S', -1)
26		" Missing space at comment start
27
28	call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*\w[,=>+\-*;]\w', -1)
29	call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*\w\(<<\|>>\)\w', -1)
30		"operator without space around it (without false positive on
31		"templated<type>)
32	call matchadd('Style', '^[^#]^\(\(?!\/\/\|\/\*\).\)*[^<]\zs\w*/\w', -1)
33		"operator without space around it (without false positive on
34		"#include <dir/file.h>)
35	call matchadd('Style', '^[^/]\{2}.*\zs[^*][=/+\-< ]$', -1)
36		"operator at end of line (without false positives on /* and */, nor
37		"char*\nClass::method())
38	call matchadd('Style', '^[^#].*\zs[^<]>$', -1)
39		" > operator at EOL (without false positive on #include <file.h>)
40	call matchadd('Style', '){', -1) " Missing space after method header
41	call matchadd('Style', '}\n\s*else', -1) " Malformed else
42	call matchadd('Style', '}\n\s*catch', -1) " Malformed catch
43	call matchadd('Style', '\s$', -1) "Spaces at end of line
44	call matchadd('Style', ',\S', -1) " Missing space after comma
45	call matchadd('Style', '^}\n\{1,2}\S', -1)
46		" Less than 2 lines between functions
47	call matchadd('Style', '^}\n\{4,}\S', -1)
48		" More than 2 lines between functions
49:endfu
50
51if stridx(getcwd(), '/Donnees/Dev/Haiku/haiku') == 0
52	" Webkit indentation rules
53	call FuncHaikuCheck()
54endif
55