Skip to content

Commit b86a4c0

Browse files
committed
Begin refinements to configuration options
1 parent f271dca commit b86a4c0

File tree

12 files changed

+36
-20
lines changed

12 files changed

+36
-20
lines changed

Diff for: clj/resources/indent-test-cases/s-expr_align-arguments/config.edn

-1
This file was deleted.

Diff for: clj/resources/indent-test-cases/s-expr_always-indent/config.edn

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:extra-cmds ["let g:clojure_indent_style = 'traditional'"]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:extra-cmds ["let g:clojure_indent_style = 'uniform'"]}

Diff for: indent/clojure.vim

+34-18
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,36 @@ setlocal noautoindent nosmartindent nolisp
2222
setlocal softtabstop=2 shiftwidth=2 expandtab
2323
setlocal indentkeys=!,o,O
2424

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+
\ ])
3254

33-
" TODO: are all these options needed or relevant? Use "lispwords" instead?
3455
" Defaults copied from: https://github.com/clojure-emacs/clojure-mode/blob/0e62583b5198f71856e4d7b80e1099789d47f2ed/clojure-mode.el#L1800-L1875
3556
if !exists('g:clojure_indent_rules')
3657
let g:clojure_indent_rules = {
@@ -74,11 +95,6 @@ if !exists('g:clojure_indent_rules')
7495
\ })
7596
endif
7697

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-
8298
" Returns "1" if position "i_char" in "line_str" is preceded by an odd number
8399
" of backslash characters (i.e. escaped).
84100
function! s:IsEscaped(line_str, i_char)
@@ -230,7 +246,7 @@ function! s:StringIndent(delim_pos)
230246
let m = mode()
231247
if m ==# 'i' || (m ==# 'n' && ! s:EqualsOperatorInEffect())
232248
" 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')
234250
" -1: Indent along left edge, like traditional Lisps.
235251
" 0: Indent in alignment with end of the string start delimiter.
236252
" 1: Indent in alignment with string start delimiter.
@@ -297,17 +313,17 @@ function! s:ListIndent(delim_pos)
297313
" - Indent subsequent lines to align with first operand.
298314
" else
299315
" - 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] !=# ':'
302318
let pos = s:FirstFnArgPos(a:delim_pos)
303319
if pos != [0, 0] | return s:PosToCharCol(pos) - 1 | endif
304320
endif
305321

306322
" 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.
308324
" The "sym_match" check handles the case when "clojure_indent_rules"
309325
" 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)
311327
endfunction
312328

313329
function! s:ClojureIndent()

0 commit comments

Comments
 (0)