Skip to content

Commit 6a3d2d3

Browse files
committed
Don't use fn arg alignment indent when a keyword is in function position
Fixes indentation of reader conditional macros. May choose to remove this if function argument indentation is generally preferred by programmers when a keyword is in function position.
1 parent d87f254 commit 6a3d2d3

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(def DateTime #?(:clj org.joda.time.DateTime,
22
:cljs goog.date.UtcDateTime))
33

4-
#?(:cljs
5-
(extend-protocol ToDateTime
6-
goog.date.Date
7-
(-to-date-time [x]
8-
(goog.date.UtcDateTime. (.getYear x) (.getMonth x) (.getDate x)))))
4+
#?(:clj
5+
(defn regexp?
6+
"Returns true if x is a Java regular expression pattern."
7+
[x]
8+
(instance? java.util.regex.Pattern x)))
99

1010
#?@(:clj [5 6 7 8]
11-
:cljs [1 2 3 4])))
11+
:cljs [1 2 3 4])
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(def DateTime #?(:clj org.joda.time.DateTime,
22
:cljs goog.date.UtcDateTime))
33

4-
#?(:cljs
5-
(extend-protocol ToDateTime
6-
goog.date.Date
7-
(-to-date-time [x]
8-
(goog.date.UtcDateTime. (.getYear x) (.getMonth x) (.getDate x)))))
4+
#?(:clj
5+
(defn regexp?
6+
"Returns true if x is a Java regular expression pattern."
7+
[x]
8+
(instance? java.util.regex.Pattern x)))
99

1010
#?@(:clj [5 6 7 8]
1111
:cljs [1 2 3 4])

indent/clojure.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ function! s:ListIndent(delim_pos)
252252

253253
let base_indent = s:PosToCharCol(a:delim_pos)
254254
let ln = getline(a:delim_pos[0])
255+
let ln_content = ln[a:delim_pos[1]:]
255256
256257
let sym_match = -1
257258

@@ -268,7 +269,7 @@ function! s:ListIndent(delim_pos)
268269
" other indentation options.
269270

270271
" TODO: simplify this.
271-
let syms = split(ln[a:delim_pos[1]:], '[[:space:],;()\[\]{}@\\"^~`]', 1)
272+
let syms = split(ln_content, '[[:space:],;()\[\]{}@\\"^~`]', 1)
272273

273274
if !empty(syms)
274275
let sym = syms[0]
@@ -292,12 +293,12 @@ function! s:ListIndent(delim_pos)
292293
endif
293294

294295
" 2. Function indentation
295-
" if first operand is on the same line?
296+
" if first operand is on the same line? (and not a keyword)
296297
" - Indent subsequent lines to align with first operand.
297298
" else
298299
" - Indent 1 or 2 spaces.
299300
let indent_style = s:Conf('clojure_indent_style', 'always-align')
300-
if indent_style !=# 'always-indent'
301+
if indent_style !=# 'always-indent' && ln_content[0] !=# ':'
301302
let pos = s:FirstFnArgPos(a:delim_pos)
302303
if pos != [0, 0] | return s:PosToCharCol(pos) - 1 | endif
303304
endif

0 commit comments

Comments
 (0)