Skip to content

Commit dcb3403

Browse files
committed
fixup! Fix indentation of subforms inside letfn forms
1 parent 66be8ea commit dcb3403

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ the default list below.
140140

141141
```vim
142142
" Default
143-
let g:clojure_special_indent_words = 'deftype,defrecord,reify,proxy,extend-type,extend-protocol'
143+
let g:clojure_special_indent_words = 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'
144144
```
145145

146146
#### `g:clojure_align_multiline_strings`

indent/clojure.vim

+33-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if exists("*searchpairpos")
4040
endif
4141

4242
if !exists('g:clojure_special_indent_words')
43-
let g:clojure_special_indent_words = 'deftype,defrecord,reify,proxy,extend-type,extend-protocol'
43+
let g:clojure_special_indent_words = 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'
4444
endif
4545

4646
if !exists('g:clojure_align_multiline_strings')
@@ -169,7 +169,39 @@ 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+
" Undo cursor traversal
195+
call cursor(next_paren)
196+
call search('\S', 'W')
197+
198+
" If the located square brackets are not the same,
199+
" don't use special-case formatting.
200+
if outer_bracket != letfn_bracket
201+
return 0
202+
endif
203+
endif
204+
173205
return 1
174206
endif
175207

0 commit comments

Comments
 (0)