Skip to content

Commit 679b666

Browse files
ethewaltguns
authored andcommitted
Add indent special case for dispatch macro, #
1 parent 064741d commit 679b666

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(#(foo)
2+
bar)
3+
4+
(#(foo
5+
bar))
6+
7+
(#(foo bar
8+
a))
9+
10+
(#(foo bar)
11+
a)
12+
13+
(#{foo}
14+
bar)
15+
16+
(#{foo
17+
bar})
18+
19+
(#{foo bar}
20+
a)
21+
22+
(#_(foo)
23+
bar)
24+
25+
(#_(foo
26+
bar))
27+
28+
(#_(foo bar)
29+
a)
30+
31+
;; vim:ft=clojure:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(#(foo)
2+
bar)
3+
4+
(#(foo
5+
bar))
6+
7+
(#(foo bar
8+
a))
9+
10+
(#(foo bar)
11+
a)
12+
13+
(#{foo}
14+
bar)
15+
16+
(#{foo
17+
bar})
18+
19+
(#{foo bar}
20+
a)
21+
22+
(#_(foo)
23+
bar)
24+
25+
(#_(foo
26+
bar))
27+
28+
(#_(foo bar)
29+
a)
30+
31+
;; vim:ft=clojure:

clj/test/vim_clojure_static/indent_test.clj

+5
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@
2828
(test-indent "reader conditionals are indented like maps"
2929
:in "test-reader-conditional-indent.in"
3030
:out "test-reader-conditional-indent.out"))
31+
32+
(deftest test-dispatch-macro-indent
33+
(test-indent "dispatch macro indentation is handled correctly"
34+
:in "test-dispatch-macro-indent.in"
35+
:out "test-dispatch-macro-indent.out"))

indent/clojure.vim

+33
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,27 @@ if exists("*searchpairpos")
196196

197197
return 0
198198
endfunction
199+
200+
" Check if keyword is an anonymous function, prefixed by #(, or a set,
201+
" prefixed by #{
202+
function! s:is_anonymous_function_or_set(word)
203+
if a:word[0:1] == "#("
204+
return 1
205+
elseif a:word[0:1] == "#{"
206+
return 1
207+
endif
208+
209+
return 0
210+
endfunction
211+
212+
" Check if keyword is ignored, that is, prefixed by #_
213+
function! s:is_ignored(word)
214+
if a:word[0:1] == "#_"
215+
return 1
216+
endif
217+
218+
return 0
219+
endfunction
199220

200221
" Returns 1 for opening brackets, -1 for _anything else_.
201222
function! s:bracket_type(char)
@@ -292,6 +313,18 @@ if exists("*searchpairpos")
292313
return paren
293314
endif
294315

316+
" If the keyword begins with #, check if it is an anonymous
317+
" function or set, in which case we indent by the shiftwidth
318+
" (minus one if g:clojure_align_subforms = 1), or if it is
319+
" ignored, in which case we use the ( position for indent.
320+
if w[0] == "#"
321+
if s:is_anonymous_function_or_set(w)
322+
return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)]
323+
elseif s:is_ignored(w)
324+
return paren
325+
endif
326+
endif
327+
295328
" Test words without namespace qualifiers and leading reader macro
296329
" metacharacters.
297330
"

0 commit comments

Comments
 (0)