@@ -40,19 +40,28 @@ endfunction
40
40
" - traditional (Emacs equiv: align-arguments)
41
41
" - uniform (Emacs equiv: always-indent)
42
42
call s: SConf (' clojure_indent_style' , ' standard' )
43
-
44
43
call s: SConf (' clojure_align_multiline_strings' , 0 )
45
-
46
44
call s: SConf (' clojure_fuzzy_indent_patterns' , [
47
45
\ ' ^with-\%(meta\|in-str\|out-str\|loading-context\)\@!' ,
48
46
\ ' ^def' ,
49
47
\ ' ^let'
50
48
\ ])
51
49
50
+ " NOTE: When in "uniform" mode, ignores the "indent_style" and "indent_patterns" options.
51
+
52
+ " FIXME: fix reader conditional tests. Include (:require [...]) test cases.
53
+ " Is it possible to fix reader conditional indentation?
54
+
55
+ " TODO: make the indentation function usable from other Clojure-like languages.
56
+
57
+ " TODO: explain the different numbers. The "indent_style" option can override "0"
58
+ " - -1 Not in dictionary, follow defaults.
59
+ " - 0: Align to first argument, else 2 space indentation.
60
+ " - 1+: 2 space indentation, no alignment.
52
61
" Defaults copied from: https://github.com/clojure-emacs/clojure-mode/blob/0e62583b5198f71856e4d7b80e1099789d47f2ed/clojure-mode.el#L1800-L1875
53
62
call s: SConf (' clojure_indent_rules' , {
54
63
\ ' ns' : 1 ,
55
- \ ' fn' : 1 , ' def' : 1 , ' defn' : 1 , ' bound-fn' : 1 , ' fdef ' : 1 ,
64
+ \ ' fn' : 1 , ' def' : 1 , ' defn' : 1 , ' bound-fn' : 1 ,
56
65
\ ' let' : 1 , ' binding' : 1 , ' defmethod' : 1 ,
57
66
\ ' if' : 1 , ' if-not' : 1 , ' if-some' : 1 , ' if-let' : 1 ,
58
67
\ ' when' : 1 , ' when-not' : 1 , ' when-some' : 1 , ' when-let' : 1 , ' when-first' : 1 ,
@@ -64,14 +73,14 @@ call s:SConf('clojure_indent_rules', {
64
73
\ ' reify' : 1 , ' proxy' : 2 , ' defrecord' : 2 , ' defprotocol' : 1 , ' definterface' : 1 ,
65
74
\ ' extend' : 1 , ' extend-protocol' : 1 , ' extend-type' : 1 ,
66
75
" \ (letfn) (1 ((:defn)) nil)
67
- " \ (reify) (:defn (1))
68
76
" \ (deftype defrecord proxy) (2 nil nil (:defn))
69
77
" \ (defprotocol definterface extend-protocol extend-type) (1 (:defn))
70
78
" \ ClojureScript
71
79
\ ' this-as' : 1 , ' specify' : 1 , ' specify!' : 1 ,
72
- " \ (specify specify!) (1 :defn)
73
80
" \ clojure.test
74
81
\ ' deftest' : 1 , ' testing' : 1 , ' use-fixtures' : 1 , ' are' : 2 ,
82
+ " \ clojure.spec.alpha
83
+ \ ' fdef' : 1 ,
75
84
" \ core.async
76
85
\ ' alt!' : 0 , ' alt!!' : 0 , ' go' : 0 , ' go-loop' : 1 , ' thread' : 0 ,
77
86
" \ core.logic
@@ -217,11 +226,10 @@ function! s:InsideForm(lnum)
217
226
return [' ^' , [0 , 0 ]] " Default to top-level.
218
227
endfunction
219
228
220
- " Returns "1" when the "=" operator is currently active.
229
+ " Returns "1" when the "=" operator is currently active, else "0" .
221
230
function ! s: EqualsOperatorInEffect ()
222
231
return exists (' *state' )
223
- \ ? v: operator == # ' =' && state (' o' ) == # ' o'
224
- \ : 0
232
+ \ ? v: operator == # ' =' && state (' o' ) == # ' o' : 0
225
233
endfunction
226
234
227
235
function ! s: StringIndent (delim_pos)
@@ -249,7 +257,12 @@ function! s:ListIndent(delim_pos)
249
257
" TODO: extend "s:InsideForm" to provide information about the
250
258
" subforms being formatted to avoid second parsing step.
251
259
260
+ let indent_style = s: Conf (' clojure_indent_style' , s: clojure_indent_style )
252
261
let base_indent = s: PosToCharCol (a: delim_pos )
262
+
263
+ " Uniform indentation: just indent by 2 spaces.
264
+ if indent_style == # ' uniform' | return base_indent + 1 | endif
265
+
253
266
let ln = getline(a:delim_pos[0])
254
267
let ln_content = ln [a:delim_pos[1]:]
255
268
@@ -265,7 +278,7 @@ function! s:ListIndent(delim_pos)
265
278
" TODO: handle complex indentation (e.g. letfn) and introduce
266
279
" indentation config similar to Emacs' clojure-mode and cljfmt.
267
280
" This new config option `clojure_indent_rules` should replace most
268
- " other indentation options.
281
+ " other indentation options. Skip if "traditional" style was chosen.
269
282
270
283
" TODO: simplify this.
271
284
let syms = split (ln_content, ' [[:space:],;()\[\]{}@\\"^~`]' , 1 )
@@ -292,21 +305,18 @@ function! s:ListIndent(delim_pos)
292
305
endif
293
306
294
307
" 2. Function indentation
295
- " if first operand is on the same line? (and not a keyword)
308
+ " if first operand is on the same line?
296
309
" - Indent subsequent lines to align with first operand.
297
310
" else
298
311
" - Indent 1 or 2 spaces.
299
- let indent_style = s: Conf (' clojure_indent_style' , s: clojure_indent_style )
300
- if indent_style !=# ' uniform' && ln_content[0 ] !=# ' :'
301
- let pos = s: FirstFnArgPos (a: delim_pos )
302
- if pos != [0 , 0 ] | return s: PosToCharCol (pos) - 1 | endif
303
- endif
312
+ let pos = s: FirstFnArgPos (a: delim_pos )
313
+ if pos != [0 , 0 ] | return s: PosToCharCol (pos) - 1 | endif
304
314
305
315
" Fallback indentation for operands. When "clojure_indent_style" is
306
- " "standard ", use 1 space indentation, else 2 space indentation.
316
+ " "traditional ", use 2 space indentation, else 1 space indentation.
307
317
" The "sym_match" check handles the case when "clojure_indent_rules"
308
- " specified a value of "0".
309
- return base_indent + (indent_style != # ' standard ' || sym_match == 0 )
318
+ " specified a value of "0" for "standard" style .
319
+ return base_indent + (indent_style == # ' traditional ' || sym_match == 0 )
310
320
endfunction
311
321
312
322
function ! s: ClojureIndent ()
0 commit comments