Skip to content

Commit 4e13b46

Browse files
committed
Extract implicit fuzzy indent blacklist patterns
Meikel started the fuzzy indent feature as a simple match against def.*, let.*, and with.*. Then he added exceptions for syms ending in -fn, and then a special case match for 'with-meta'. After this, the fuzzy indent patterns were made a public option, but the hardcoded exceptions remained. This commit finishes this refactoring and gives full control to the user. The new blacklist, and the former pattern whitelist are now lists by default to allow for any kind of pattern (e.g. '\V\cFOO'), instead of an implicitly anchored one that cannot be preceded by pattern modifiers. The old string options are supported for backwards compatibility. Addresses #7
1 parent 2b8c2dc commit 4e13b46

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

indent/clojure.vim

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ 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')
@@ -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("%")
@@ -271,14 +287,9 @@ if exists("*searchpairpos")
271287
endif
272288

273289
if g:clojure_fuzzy_indent
274-
\ && ww != 'with-meta'
275-
for pat in split(g:clojure_fuzzy_indent_patterns, ",")
276-
if ww =~ '^' . pat . '$'
277-
\ && ww !~ '^' . pat . '\*$'
278-
\ && ww !~ '^' . pat . '-fn$'
279-
return paren[1] + &shiftwidth - 1
280-
endif
281-
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
282293
endif
283294

284295
normal! W

0 commit comments

Comments
 (0)