Skip to content

Commit 2661397

Browse files
committed
indent: fix #15
1 parent e828aee commit 2661397

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ add_custom_target(
5050
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
5151
```
5252

53+
By setting `g:cmake_indent_no_command_argument_align` to 1 in your vimrc-file the old behavior is activated:
54+
55+
```cmake
56+
add_custom_target(TARGET name
57+
DEPENDS target
58+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
59+
```
60+
5361
## Test
5462

5563
There is a ever growing test-suite based on ctest located in test/

indent/cmake.vim

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ let s:cmake_indent_close_regex = '^' . s:cmake_regex_arguments .
4646
let s:cmake_indent_begin_regex = '^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*('
4747
let 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+
4953
fun! 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

Comments
 (0)