@@ -23,15 +23,9 @@ setlocal indentkeys=!,o,O
2323
2424" TODO: ignore 'lisp' and 'lispwords' options (actually, turn them off?)
2525
26- " TODO: Optional Vim9script implementations of hotspot/bottleneck functions.
26+ " TODO: Optional Vim9script implementations of hotspot/bottleneck functions?
2727" FIXME: fallback case when syntax highlighting is disabled.
2828
29- " Function to get the indentation of a line.
30- " function! s:GetIndent(lnum)
31- " let l = getline(a:lnum)
32- " return len(l) - len(trim(l, " \t", 1))
33- " endfunction
34-
3529function ! s: GetSynIdName (line , col )
3630 return synIDattr (synID (a: line , a: col , 0 ), ' name' )
3731endfunction
@@ -48,18 +42,10 @@ function! s:NotAStringDelimiter()
4842 return ! s: SyntaxMatch (' stringdelimiter' , line (' .' ), col (' .' ))
4943endfunction
5044
51- function ! s: IsInString ()
52- return s: SyntaxMatch (' string' , line (' .' ), col (' .' ))
53- endfunction
54-
5545function ! s: NotARegexpDelimiter ()
5646 return ! s: SyntaxMatch (' regexpdelimiter' , line (' .' ), col (' .' ))
5747endfunction
5848
59- function ! s: IsInRegex ()
60- return s: SyntaxMatch (' regex' , line (' .' ), col (' .' ))
61- endfunction
62-
6349function ! s: Conf (opt , default)
6450 return get (b: , a: opt , get (g: , a: opt , a: default ))
6551endfunction
@@ -68,28 +54,18 @@ function! s:ShouldAlignMultiLineStrings()
6854 return s: Conf (' clojure_align_multiline_strings' , 0 )
6955endfunction
7056
71- function ! s: ClosestMatch (match1, match2)
72- let [_, coord1] = a: match1
73- let [_, coord2] = a: match2
74- if coord1[0 ] < coord2[0 ]
75- return a: match2
76- elseif coord1[0 ] == coord2[0 ] && coord1[1 ] < coord2[1 ]
77- return a: match2
78- else
79- return a: match1
80- endif
81- endfunction
82-
8357" Wrapper around "searchpairpos" that will automatically set "s:best_match" to
8458" the closest pair match and continuously optimise the "stopline" value for
8559" later searches. This results in a significant performance gain by reducing
8660" the number of syntax lookups that need to take place.
8761function ! s: CheckPair (name, start , end , skipfn)
88- let pos = searchpairpos (a: start , ' ' , a: end , ' bznW' , a: skipfn , s: best_match [1 ][0 ])
89- let s: best_match = s: ClosestMatch (s: best_match , [a: name , pos])
62+ let prevln = s: best_match [1 ][0 ]
63+ let pos = searchpairpos (a: start , ' ' , a: end , ' bznW' , a: skipfn , prevln)
64+ if prevln < pos[0 ] || (prevln == pos[0 ] && s: best_match [1 ][1 ] < pos[1 ])
65+ let s: best_match = [a: name , pos]
66+ endif
9067endfunction
9168
92- " Only need to search up. Never down.
9369function ! s: GetClojureIndent ()
9470 let lnum = v: lnum
9571
@@ -102,9 +78,10 @@ function! s:GetClojureIndent()
10278 call s: CheckPair (' vec' , ' \[' , ' \]' , function (' <SID>IgnoredRegion' ))
10379 call s: CheckPair (' map' , ' {' , ' }' , function (' <SID>IgnoredRegion' ))
10480
105- if s: IsInString ()
81+ let synname = s: GetSynIdName (lnum, col (' .' ))
82+ if synname = ~? ' string'
10683 call s: CheckPair (' str' , ' "' , ' "' , function (' <SID>NotAStringDelimiter' ))
107- elseif s: IsInRegex ()
84+ elseif synname = ~? ' regex '
10885 call s: CheckPair (' reg' , ' #\zs"' , ' "' , function (' <SID>NotARegexpDelimiter' ))
10986 endif
11087
@@ -114,26 +91,21 @@ function! s:GetClojureIndent()
11491
11592 if formtype == ' top'
11693 " At the top level, no indent.
117- " echom 'At the top level!'
11894 return 0
11995 elseif formtype == ' lst'
120- " echom 'Special format rules!'
121- " TODO
122- " Grab text!
96+ " Inside a list.
97+ " TODO Begin analysis and apply rules!
12398 " echom getline(coord[0], lnum - 1)
124- " Begin lexing!
12599 return coord[1 ] + 1
126100 elseif formtype == ' vec' || formtype == ' map'
127101 " Inside a vector, map or set.
128102 return coord[1 ]
129- elseif formtype == ' reg'
130- " Inside a regex.
131- " echom 'Inside a regex!'
132- return coord[1 ] - (s: ShouldAlignMultiLineStrings () ? 0 : 2 )
133103 elseif formtype == ' str'
134104 " Inside a string.
135- " echom 'Inside a string!'
136105 return coord[1 ] - (s: ShouldAlignMultiLineStrings () ? 0 : 1 )
106+ elseif formtype == ' reg'
107+ " Inside a regex.
108+ return coord[1 ] - (s: ShouldAlignMultiLineStrings () ? 0 : 2 )
137109 endif
138110
139111 return 2
0 commit comments