@@ -35,15 +35,19 @@ if exists("*searchpairpos")
3535 let g: clojure_fuzzy_indent = 1
3636 endif
3737
38- if ! exists (" g:clojure_fuzzy_indent_patterns" )
39- let g: clojure_fuzzy_indent_patterns = " with.*,def.*,let.*"
38+ if ! exists (' g:clojure_fuzzy_indent_patterns' )
39+ let g: clojure_fuzzy_indent_patterns = [' ^with' , ' ^def' , ' ^let' ]
40+ endif
41+
42+ if ! exists (' g:clojure_fuzzy_indent_blacklist' )
43+ let g: clojure_fuzzy_indent_blacklist = [' ^with-meta$' , ' -fn$' ]
4044 endif
4145
4246 if ! exists (' g:clojure_special_indent_words' )
4347 let g: clojure_special_indent_words = ' deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'
4448 endif
4549
46- if ! exists (" g:clojure_align_multiline_strings" )
50+ if ! exists (' g:clojure_align_multiline_strings' )
4751 let g: clojure_align_multiline_strings = 0
4852 endif
4953
@@ -64,6 +68,18 @@ if exists("*searchpairpos")
6468 \ s: SynIdName () !~? ' \vstring|comment'
6569 endfunction
6670
71+ " Returns 1 if string matches a pattern in 'patterns', which may be a
72+ " list of patterns, or a comma-delimited string of implicitly anchored
73+ " patterns.
74+ function ! s: MatchesOne (patterns, string )
75+ let list = type (a: patterns ) == type ([])
76+ \ ? a: patterns
77+ \ : map (split (a: patterns , ' ,' ), ' "^" . v:val . "$"' )
78+ for pat in list
79+ if a: string = ~ pat | return 1 | endif
80+ endfor
81+ endfunction
82+
6783 function ! s: SavePosition ()
6884 let [ _b, l , c , _o ] = getpos (" ." )
6985 let b = bufnr (" %" )
@@ -261,26 +277,19 @@ if exists("*searchpairpos")
261277 return paren[1 ]
262278 endif
263279
264- " Test words with any leading non-word chars stripped;
265- " e.g. #'defn should indent like defn.
266- let ww = substitute (w , ' \v\W*(\w.*)' , ' \1' , ' ' )
280+ " Test words without namespace qualifiers and leading non-word chars.
281+ "
282+ " e.g. clojure.core/defn and #'defn should both indent like defn.
283+ let ww = substitute (w , ' \v%(.*/|\W*)(.*)' , ' \1' , ' ' )
267284
268285 if &lispwords = ~ ' \<' . ww . ' \>'
269286 return paren[1 ] + &shiftwidth - 1
270287 endif
271288
272- " XXX: Slight glitch here with special cases. However it's only
273- " a heureustic. Offline we can't do more.
274289 if g: clojure_fuzzy_indent
275- \ && ww != ' with-meta'
276- \ && ww != ' clojure.core/with-meta'
277- for pat in split (g: clojure_fuzzy_indent_patterns , " ," )
278- if ww = ~ ' \(^\|/\)' . pat . ' $'
279- \ && ww !~ ' \(^\|/\)' . pat . ' \*$'
280- \ && ww !~ ' \(^\|/\)' . pat . ' -fn$'
281- return paren[1 ] + &shiftwidth - 1
282- endif
283- endfor
290+ \ && ! s: MatchesOne (g: clojure_fuzzy_indent_blacklist , ww )
291+ \ && s: MatchesOne (g: clojure_fuzzy_indent_patterns , ww )
292+ return paren[1 ] + &shiftwidth - 1
284293 endif
285294
286295 normal ! W
0 commit comments