@@ -22,15 +22,36 @@ setlocal noautoindent nosmartindent nolisp
22
22
setlocal softtabstop = 2 shiftwidth = 2 expandtab
23
23
setlocal indentkeys = ! ,o ,O
24
24
25
- if ! exists (' g:clojure_fuzzy_indent_patterns' )
26
- let g: clojure_fuzzy_indent_patterns = [
27
- \ ' ^with-\%(meta\|in-str\|out-str\|loading-context\)\@!' ,
28
- \ ' ^def' ,
29
- \ ' ^let'
30
- \ ]
31
- endif
25
+ " Set a new configuration option with a default value. Assigns a script-local
26
+ " version too, which is the default fallback in case the global was "unlet".
27
+ function ! s: SConf (name, default) abort
28
+ exec ' let' ' s:' . a: name ' =' string (a: default )
29
+ let n = ' g:' . a: name
30
+ if ! exists (n ) | exec ' let' n ' =' string (a: default ) | endif
31
+ endfunction
32
+
33
+ " Get the value of a configuration option with a possible fallback. If no
34
+ " fallback is given, uses the original config option value.
35
+ function ! s: Conf (opt , fallback = v: null ) abort
36
+ return a: fallback == # v: null
37
+ \ ? get (b: , a: opt , get (g: , a: opt , get (s: , a: opt )))
38
+ \ : get (b: , a: opt , get (g: , a: opt , a: fallback ))
39
+ endfunction
40
+
41
+ " Available options:
42
+ " - standard (Emacs equiv: always-align)
43
+ " - traditional (Emacs equiv: align-arguments)
44
+ " - uniform (Emacs equiv: always-indent)
45
+ call s: SConf (' clojure_indent_style' , ' standard' )
46
+
47
+ call s: SConf (' clojure_align_multiline_strings' , 0 )
48
+
49
+ call s: SConf (' clojure_fuzzy_indent_patterns' , [
50
+ \ ' ^with-\%(meta\|in-str\|out-str\|loading-context\)\@!' ,
51
+ \ ' ^def' ,
52
+ \ ' ^let'
53
+ \ ])
32
54
33
- " TODO: are all these options needed or relevant? Use "lispwords" instead?
34
55
" Defaults copied from: https://github.com/clojure-emacs/clojure-mode/blob/0e62583b5198f71856e4d7b80e1099789d47f2ed/clojure-mode.el#L1800-L1875
35
56
if ! exists (' g:clojure_indent_rules' )
36
57
let g: clojure_indent_rules = {
@@ -74,11 +95,6 @@ if !exists('g:clojure_indent_rules')
74
95
\ })
75
96
endif
76
97
77
- " Get the value of a configuration option.
78
- function ! s: Conf (opt , default)
79
- return get (b: , a: opt , get (g: , a: opt , a: default ))
80
- endfunction
81
-
82
98
" Returns "1" if position "i_char" in "line_str" is preceded by an odd number
83
99
" of backslash characters (i.e. escaped).
84
100
function ! s: IsEscaped (line_str, i_char)
@@ -230,7 +246,7 @@ function! s:StringIndent(delim_pos)
230
246
let m = mode ()
231
247
if m == # ' i' || (m == # ' n' && ! s: EqualsOperatorInEffect ())
232
248
" If in insert mode, or normal mode but "=" is not in effect.
233
- let alignment = s: Conf (' clojure_align_multiline_strings' , 0 )
249
+ let alignment = s: Conf (' clojure_align_multiline_strings' )
234
250
" -1: Indent along left edge, like traditional Lisps.
235
251
" 0: Indent in alignment with end of the string start delimiter.
236
252
" 1: Indent in alignment with string start delimiter.
@@ -297,17 +313,17 @@ function! s:ListIndent(delim_pos)
297
313
" - Indent subsequent lines to align with first operand.
298
314
" else
299
315
" - Indent 1 or 2 spaces.
300
- let indent_style = s: Conf (' clojure_indent_style' , ' always-align ' )
301
- if indent_style !=# ' always-indent ' && ln_content[0 ] !=# ' :'
316
+ let indent_style = s: Conf (' clojure_indent_style' )
317
+ if indent_style !=# ' uniform ' && ln_content[0 ] !=# ' :'
302
318
let pos = s: FirstFnArgPos (a: delim_pos )
303
319
if pos != [0 , 0 ] | return s: PosToCharCol (pos) - 1 | endif
304
320
endif
305
321
306
322
" Fallback indentation for operands. When "clojure_indent_style" is
307
- " "always-align ", use 1 space indentation, else 2 space indentation.
323
+ " "standard ", use 1 space indentation, else 2 space indentation.
308
324
" The "sym_match" check handles the case when "clojure_indent_rules"
309
325
" specified a value of "0".
310
- return base_indent + (indent_style !=# ' always-align ' || sym_match == 0 )
326
+ return base_indent + (indent_style !=# ' standard ' || sym_match == 0 )
311
327
endfunction
312
328
313
329
function ! s: ClojureIndent ()
0 commit comments