Skip to content

Commit b974eb0

Browse files
committed
Fix indentation of subforms inside letfn forms
Fixes: guns/vim-clojure-static#56 Related: guns/vim-clojure-static#83
1 parent 15ce7f6 commit b974eb0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

indent/clojure.vim

+28
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,35 @@ if exists("*searchpairpos")
169169

170170
call search('\S', 'W')
171171
let w = s:strip_namespace_and_macro_chars(s:current_word())
172+
172173
if g:clojure_special_indent_words =~# '\V\<' . w . '\>'
174+
175+
" `letfn` is a special-special-case.
176+
if w ==# 'letfn'
177+
" Earlier code left the cursor at:
178+
" (letfn [...] ...)
179+
" ^
180+
181+
" Search and get coordinates of first `[`
182+
" (letfn [...] ...)
183+
" ^
184+
call search('\[', 'W')
185+
let pos = getcurpos()
186+
let letfn_bracket = [pos[1], pos[2]]
187+
188+
" Move cursor to start of the form this function was
189+
" initially called on. Grab the coordinates of the
190+
" closest outer `[`.
191+
call cursor(a:position)
192+
let outer_bracket = s:match_pairs('\[', '\]', 0)
193+
194+
" If the located square brackets are not the same,
195+
" don't use special-case formatting.
196+
if outer_bracket != letfn_bracket
197+
return 0
198+
endif
199+
endif
200+
173201
return 1
174202
endif
175203

0 commit comments

Comments
 (0)