@@ -28,8 +28,8 @@ let s:block_end = 'end'
28
28
let s: arrow = ' ^.*->$'
29
29
let s: pipeline = ' ^\s*|>.*$'
30
30
31
- let s: indent_keywords = ' \<\%(' . s: block_start . ' \|' . s: block_middle . ' \)$'
32
- let s: deindent_keywords = ' ^\s*\<\%(' . s: block_end . ' \|' . s: block_middle . ' \)\>'
31
+ let s: indent_keywords = ' \<\%(' . s: block_start . ' \|' . s: block_middle . ' \)$' . ' \| ' . s: arrow
32
+ let s: deindent_keywords = ' ^\s*\<\%(' . s: block_end . ' \|' . s: block_middle . ' \)\>' . ' \| ' . s: arrow
33
33
34
34
function ! GetElixirIndent (... )
35
35
let lnum = prevnonblank (v: lnum - 1 )
@@ -41,43 +41,38 @@ function! GetElixirIndent(...)
41
41
endif
42
42
43
43
if synIDattr (synID (v: lnum , 1 , 1 ), " name" ) !~ s: skip_syntax
44
- let splited_line = split (getline (lnum), ' \zs' )
45
- let opened_symbol = 0
44
+ let current_line = getline (v: lnum )
45
+ let last_line = getline (lnum)
46
+
47
+ let splited_line = split (last_line, ' \zs' )
48
+ let opened_symbol = 0
46
49
let opened_symbol += count (splited_line, ' [' ) - count (splited_line, ' ]' )
47
50
let opened_symbol += count (splited_line, ' {' ) - count (splited_line, ' }' )
48
51
49
52
let ind += opened_symbol * &sw
50
53
51
- if getline (lnum) = ~ s: indent_keywords .
52
- \ ' \|' . s: arrow
54
+ if last_line = ~ s: indent_keywords
53
55
let ind += &sw
54
56
endif
55
57
56
58
" if line starts with pipeline
57
- " and last line doesn't start with pipeline
58
- if getline (v: lnum ) = ~ s: pipeline &&
59
- \ getline (lnum) !~ s: pipeline
60
- let ind += &sw
61
- endif
62
-
63
- " if last line starts with pipeline
64
- " and currentline doesn't start with pipeline
65
- if getline (lnum) = ~ s: pipeline &&
66
- \ getline (v: lnum ) !~ s: pipeline
67
- let ind -= &sw
59
+ " and last line is an attribution
60
+ " indents pipeline in same level as attribution
61
+ if current_line = ~ s: pipeline &&
62
+ \ last_line = ~ ' ^[^=]\+=.\+$'
63
+ let b: old_ind = ind
64
+ let ind += round (match (last_line, ' =' ) / &sw ) * &sw
68
65
endif
69
66
70
67
" if last line starts with pipeline
71
68
" and current line doesn't start with pipeline
72
- " but last line started a block
73
- if getline (lnum) = ~ s: pipeline &&
74
- \ getline (v: lnum ) !~ s: pipeline &&
75
- \ getline (lnum) = ~ s: block_start
76
- let ind += &sw
69
+ " returns the indentation before the pipeline
70
+ if last_line = ~ s: pipeline &&
71
+ \ current_line !~ s: pipeline
72
+ let ind = b: old_ind
77
73
endif
78
74
79
- if getline (v: lnum ) = ~ s: deindent_keywords .
80
- \ ' \|' . s: arrow
75
+ if current_line = ~ s: deindent_keywords
81
76
let bslnum = searchpair ( ' \<\%(' . s: block_start . ' \):\@!\>' ,
82
77
\ ' \<\%(' . s: block_middle . ' \):\@!\>\zs' ,
83
78
\ ' \<:\@<!' . s: block_end . ' \>\zs' ,
@@ -86,7 +81,8 @@ function! GetElixirIndent(...)
86
81
let ind = indent (bslnum)
87
82
endif
88
83
89
- if getline (v: lnum ) = ~ s: arrow
84
+ " indent case statements '->'
85
+ if current_line = ~ s: arrow
90
86
let ind += &sw
91
87
endif
92
88
endif
0 commit comments