@@ -18,6 +18,7 @@ set cpo&vim
18
18
let s: no_colon_before = ' :\@<!'
19
19
let s: no_colon_after = ' :\@!'
20
20
let s: symbols_end = ' \]\|}'
21
+ let s: symbols_start = ' \[\|{'
21
22
let s: arrow = ' ^.*->$'
22
23
let s: pipeline = ' ^\s*|>.*$'
23
24
let s: skip_syntax = ' \%(Comment\|String\)$'
@@ -54,12 +55,19 @@ function! GetElixirIndent()
54
55
let current_line = getline (v: lnum )
55
56
let last_line = getline (lnum)
56
57
57
- let splited_line = split (last_line, ' \zs' )
58
+ let split_line = split (last_line, ' \zs' )
58
59
let opened_symbol = 0
59
- let opened_symbol += count (splited_line, ' [' ) - count (splited_line, ' ]' )
60
- let opened_symbol += count (splited_line, ' {' ) - count (splited_line, ' }' )
61
-
62
- let ind += (opened_symbol * &sw )
60
+ let opened_symbol += count (split_line, ' [' ) - count (split_line, ' ]' )
61
+ let opened_symbol += count (split_line, ' {' ) - count (split_line, ' }' )
62
+
63
+ " if start symbol is followed by a character, indent based on the
64
+ " whitespace after the symbol, otherwise use the default shiftwidth
65
+ if last_line = ~ ' \(' .s: symbols_start .' \).'
66
+ let opened_prefix = matchlist (last_line, ' \(' .s: symbols_start .' \)\s*' )[0 ]
67
+ let ind += (opened_symbol * strlen (opened_prefix))
68
+ else
69
+ let ind += (opened_symbol * &sw )
70
+ endif
63
71
64
72
if last_line = ~ ' ^\s*\(' .s: symbols_end .' \)' || last_line = ~ s: indent_keywords
65
73
let ind += &sw
0 commit comments