@@ -45,28 +45,26 @@ function! s:Conf(opt, default)
45
45
return get (b: , a: opt , get (g: , a: opt , a: default ))
46
46
endfunction
47
47
48
- function ! s: ShouldAlignMultiLineStrings ()
49
- " Possible Values: (default is 0)
50
- " -1: Indent of 0, along left edge, like traditional Lisps.
51
- " 0: Indent in alignment with string start delimiter.
52
- " 1: Indent in alignment with end of the string start delimiter.
53
- return s: Conf (' clojure_align_multiline_strings' , 0 )
48
+ function ! s: EqualsOperatorInEffect ()
49
+ " Returns 1 when the previous operator used is "=" and is currently in
50
+ " effect (i.e. "state" includes "o").
51
+ return v: operator == # ' =' && state (' o' ) == # ' o'
54
52
endfunction
55
53
56
54
function ! s: GetStringIndent (delim_pos, regex)
57
55
" Mimic multi-line string indentation behaviour in VS Code and Emacs.
58
56
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 ()
57
+ if m == # ' i' || (m == # ' n' && ! s: EqualsOperatorInEffect ())
58
+ " If in insert mode, or normal mode but "=" is not in effect.
59
+ let rule = s: Conf (' clojure_align_multiline_strings' , 0 )
63
60
if rule == -1
64
- return 0 " No indent.
61
+ " Indent along left edge, like traditional Lisps.
62
+ return 0
65
63
elseif rule == 1
66
- " Align with start of delimiter.
64
+ " Indent in alignment with end of the string start delimiter.
67
65
return a: delim_pos [1 ]
68
66
else
69
- " Align with end of delimiter.
67
+ " Indent in alignment with string start delimiter.
70
68
return a: delim_pos [1 ] - (a: regex ? 2 : 1 )
71
69
endif
72
70
else
@@ -86,27 +84,30 @@ function! s:CheckPair(name, start, end, SkipFn)
86
84
endif
87
85
endfunction
88
86
89
- function ! s: GetClojureIndent ()
90
- " Move cursor to the first column of the line we want to indent.
91
- call cursor (v: lnum , 1 )
92
-
93
- if empty (getline (v: lnum ))
87
+ function ! s: GetCurrentSynName (lnum)
88
+ if empty (getline (a: lnum ))
94
89
" Improves the accuracy of string detection when a newline is
95
90
" entered while in insert mode.
96
- let strline = v : lnum - 1
97
- let synname = s: GetSynIdName (strline, strlen (getline (strline)))
91
+ let strline = a : lnum - 1
92
+ return s: GetSynIdName (strline, strlen (getline (strline)))
98
93
else
99
- let synname = s: GetSynIdName (v : lnum , 1 )
94
+ return s: GetSynIdName (a : lnum , 1 )
100
95
endif
96
+ endfunction
97
+
98
+ function ! s: GetClojureIndent ()
99
+ " Move cursor to the first column of the line we want to indent.
100
+ call cursor (v: lnum , 1 )
101
101
102
102
let s: best_match = [' top' , [0 , 0 ]]
103
103
104
+ let synname = s: GetCurrentSynName (v: lnum )
104
105
if synname = ~? ' string'
106
+ call s: CheckPair (' str' , ' "' , ' "' , function (' <SID>NotStringDelimiter' ))
105
107
" Sometimes, string highlighting does not kick in correctly,
106
108
" until after this first "s:CheckPair" call, so we have to
107
109
" detect and attempt an automatic correction.
108
- call s: CheckPair (' str' , ' "' , ' "' , function (' <SID>NotStringDelimiter' ))
109
- let new_synname = s: GetSynIdName (v: lnum , 1 )
110
+ let new_synname = s: GetCurrentSynName (v: lnum )
110
111
if new_synname !=# synname
111
112
echoerr ' Misdetected string! Retrying...'
112
113
let s: best_match = [' top' , [0 , 0 ]]
0 commit comments