Skip to content

Commit 0b388ae

Browse files
committed
Indent some macros a bit like functions
1 parent 7e90f09 commit 0b388ae

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Diff for: clj/resources/indent-test-cases/special_forms/in.clj

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(try (/ 1 0)
2+
(catch Exception e
3+
(foo)))
4+
5+
(try
6+
(/ 1 0)
7+
(catch Exception e
8+
(foo)))
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(try (/ 1 0)
2+
(catch Exception e
3+
(foo)))
4+
5+
(try
6+
(/ 1 0)
7+
(catch Exception e
8+
(foo)))

Diff for: indent/clojure.vim

+6-3
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ function! s:ListIndent(delim_pos)
248248
let base_indent = s:PosToCharPos(a:delim_pos)[1]
249249
let ln = getline(a:delim_pos[0])
250250
251+
let sym_match = -1
252+
251253
" 1. Macro/rule indentation
252254
" if starts with a symbol, extract it.
253255
" - Split namespace off symbol and #'/' syntax.
@@ -265,7 +267,6 @@ function! s:ListIndent(delim_pos)
265267
266268
if !empty(syms)
267269
let sym = syms[0]
268-
" TODO: if prefixed with "#'" or "'" fallback to func indent.
269270
if sym =~# '\v^%([a-zA-Z!$&*_+=|<>?-]|[^\x00-\x7F])'
270271

271272
" TODO: handle namespaced and non-namespaced variants.
@@ -281,7 +282,7 @@ function! s:ListIndent(delim_pos)
281282
let rules = s:Conf('clojure_indent_rules', {})
282283
let sym_match = get(rules, sym, -1)
283284
" TODO: handle 2+ differently?
284-
if sym_match >= 0 | return base_indent + 1 | endif
285+
if sym_match > 0 | return base_indent + 1 | endif
285286
endif
286287
endif
287288

@@ -298,7 +299,9 @@ function! s:ListIndent(delim_pos)
298299

299300
" Fallback indentation for operands. When "clojure_indent_style" is
300301
" "always-align", use 1 space indentation, else 2 space indentation.
301-
return base_indent + (indent_style !=# 'always-align')
302+
" The "sym_match" check handles the case when "clojure_indent_rules"
303+
" specified a value of "0".
304+
return base_indent + (indent_style !=# 'always-align' || sym_match == 0)
302305
endfunction
303306

304307
function! s:ClojureIndent()

0 commit comments

Comments
 (0)