@@ -45,28 +45,25 @@ 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
+ return v: operator == # ' =' && state (' o' ) == # ' o'
54
50
endfunction
55
51
56
52
function ! s: GetStringIndent (delim_pos, regex)
57
53
" Mimic multi-line string indentation behaviour in VS Code and Emacs.
58
54
let m = mode ()
59
- if m == # ' i' || (m == # ' n' && ! ( v: operator == # ' = ' && state ( ' o ' ) == # ' o ' ))
55
+ if m == # ' i' || (m == # ' n' && ! s: EqualsOperatorInEffect ( ))
60
56
" If in insert mode, or (in normal mode and last operator is
61
57
" not "=" and is not currently active.
62
- let rule = s: ShouldAlignMultiLineStrings ( )
58
+ let rule = s: Conf ( ' clojure_align_multiline_strings ' , 0 )
63
59
if rule == -1
64
- return 0 " No indent.
60
+ " Indent along left edge, like traditional Lisps.
61
+ return 0
65
62
elseif rule == 1
66
- " Align with start of delimiter.
63
+ " Indent in alignment with end of the string start delimiter.
67
64
return a: delim_pos [1 ]
68
65
else
69
- " Align with end of delimiter.
66
+ " Indent in alignment with string start delimiter.
70
67
return a: delim_pos [1 ] - (a: regex ? 2 : 1 )
71
68
endif
72
69
else
@@ -86,27 +83,31 @@ function! s:CheckPair(name, start, end, SkipFn)
86
83
endif
87
84
endfunction
88
85
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 ))
86
+ function ! s: GetCurrentSynName (lnum)
87
+ if empty (getline (a: lnum ))
94
88
" Improves the accuracy of string detection when a newline is
95
89
" entered while in insert mode.
96
- let strline = v : lnum - 1
97
- let synname = s: GetSynIdName (strline, strlen (getline (strline)))
90
+ let strline = a : lnum - 1
91
+ return s: GetSynIdName (strline, strlen (getline (strline)))
98
92
else
99
- let synname = s: GetSynIdName (v : lnum , 1 )
93
+ return s: GetSynIdName (a : lnum , 1 )
100
94
endif
95
+ endfunction
96
+
97
+ function ! s: GetClojureIndent ()
98
+ " Move cursor to the first column of the line we want to indent.
99
+ call cursor (v: lnum , 1 )
100
+
101
+ let synname = s: GetCurrentSynName (v: lnum )
101
102
102
103
let s: best_match = [' top' , [0 , 0 ]]
103
104
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