@@ -46,6 +46,10 @@ let s:cmake_indent_close_regex = '^' . s:cmake_regex_arguments .
4646let s: cmake_indent_begin_regex = ' ^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*('
4747let s: cmake_indent_end_regex = ' ^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*('
4848
49+ if ! exists (' g:cmake_indent_no_command_argument_align' )
50+ let g: cmake_indent_no_command_argument_align = 0
51+ endif
52+
4953fun ! CMakeGetIndent (lnum)
5054 let this_line = getline (a: lnum )
5155
@@ -74,16 +78,22 @@ fun! CMakeGetIndent(lnum)
7478 if previous_line = ~? s: cmake_indent_open_regex " open parenthesis
7579 if previous_line !~? s: cmake_indent_close_regex " closing parenthesis is not on the same line
7680 call cursor (lnum, 1 )
77- let s = searchpos (' (' ) " find first ( which is by cmake-design not a string
78- if strlen (previous_line) == s [ 1 ] " if ( is the last char on this line, do not align with ( but use sw()
81+ let s = searchpos (' (\s*$ ' ) " find '(' with nothing or only spaces until the end of the line
82+ if s [ 0 ] == lnum
7983 let ind += shiftwidth ()
80- else
81- let ind = s [1 ]
84+ else " an argument after the keyword
85+ call cursor (lnum, 1 )
86+ let s = searchpos (' (' ) " find position of first '('
87+ if g: cmake_indent_no_command_argument_align == 1 " old behavior
88+ let ind += shiftwidth ()
89+ else
90+ let ind = s [1 ]
91+ endif
8292 endif
8393 endif
8494 elseif previous_line = ~? s: cmake_indent_close_regex " close parenthesis
8595 call cursor (lnum, strlen (previous_line))
86- let pairpos = searchpos (s: cmake_indent_open_regex , ' nbz' )
96+ let pairpos = searchpos (s: cmake_indent_open_regex , ' nbz' ) " find corresponding open paren
8797 if pairpos[0 ] != 0
8898 let ind = indent (pairpos[0 ])
8999 endif
0 commit comments