@@ -46,6 +46,10 @@ let s:cmake_indent_close_regex = '^' . s:cmake_regex_arguments .
46
46
let s: cmake_indent_begin_regex = ' ^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*('
47
47
let s: cmake_indent_end_regex = ' ^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*('
48
48
49
+ if ! exists (' g:cmake_indent_no_command_argument_align' )
50
+ let g: cmake_indent_no_command_argument_align = 0
51
+ endif
52
+
49
53
fun ! CMakeGetIndent (lnum)
50
54
let this_line = getline (a: lnum )
51
55
@@ -74,16 +78,22 @@ fun! CMakeGetIndent(lnum)
74
78
if previous_line = ~? s: cmake_indent_open_regex " open parenthesis
75
79
if previous_line !~? s: cmake_indent_close_regex " closing parenthesis is not on the same line
76
80
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
79
83
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
82
92
endif
83
93
endif
84
94
elseif previous_line = ~? s: cmake_indent_close_regex " close parenthesis
85
95
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
87
97
if pairpos[0 ] != 0
88
98
let ind = indent (pairpos[0 ])
89
99
endif
0 commit comments