@@ -53,6 +53,27 @@ function! s:ShouldAlignMultiLineStrings()
53
53
return s: Conf (' clojure_align_multiline_strings' , 0 )
54
54
endfunction
55
55
56
+ function ! s: GetStringIndent (delim_pos, regex)
57
+ " Mimic multi-line string indentation behaviour in VS Code and Emacs.
58
+ let m = mode ()
59
+ if m == # ' i' || (m == # ' n' && ! (v: operator == # ' =' && state (' o' ) == # ' o' ))
60
+ " If in insert mode, or (in normal mode and last operator is
61
+ " not "=" and is not currently active.
62
+ let rule = s: ShouldAlignMultiLineStrings ()
63
+ if rule == -1
64
+ return 0 " No indent.
65
+ elseif rule == 1
66
+ " Align with start of delimiter.
67
+ return a: delim_pos [1 ]
68
+ else
69
+ " Align with end of delimiter.
70
+ return a: delim_pos [1 ] - (a: regex ? 2 : 1 )
71
+ endif
72
+ else
73
+ return -1 " Keep existing indent.
74
+ endif
75
+ endfunction
76
+
56
77
" Wrapper around "searchpairpos" that will automatically set "s:best_match" to
57
78
" the closest pair match and optimises the "stopline" value for later
58
79
" searches. This results in a significant performance gain by reducing the
@@ -104,25 +125,12 @@ function! s:GetClojureIndent()
104
125
elseif formtype == # ' vec' || formtype == # ' map'
105
126
" Inside a vector, map or set.
106
127
return coord[1 ]
107
- elseif formtype == # ' str' || formtype == # ' reg'
108
- " Mimic multi-line string indentation behaviour in VS Code and
109
- " Emacs.
110
- let m = mode ()
111
- if m == # ' i' || (m == # ' n' && ! (v: operator == # ' =' && state () = ~# ' o' ))
112
- " If in insert mode, or (in normal mode and last
113
- " operator is not "=" and is not currently active.
114
- let rule = s: ShouldAlignMultiLineStrings ()
115
- if rule == -1
116
- " No indent.
117
- return 0
118
- elseif rule == 1
119
- " Align with start of delimiter.
120
- return coord[1 ]
121
- else
122
- " Align with end of delimiter.
123
- return coord[1 ] - (formtype == # ' reg' ? 2 : 1 )
124
- endif
125
- endif
128
+ elseif formtype == # ' str'
129
+ " Inside a string.
130
+ return s: GetStringIndent (coord, 0 )
131
+ elseif formtype == # ' reg'
132
+ " Inside a regular expression.
133
+ return s: GetStringIndent (coord, 1 )
126
134
endif
127
135
128
136
" Keep existing indent.
0 commit comments