Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c13ada8

Browse files
committedOct 5, 2024·
Replace the old multi-line string config option
1 parent 3487e07 commit c13ada8

File tree

11 files changed

+91
-35
lines changed

11 files changed

+91
-35
lines changed
 

‎README.md

+17-19
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ offers ways to adjust the indentaion.
6666
> The indentation code has recently been rebuilt which included the removal of
6767
> the following configuration options:
6868
>
69+
> - `clojure_align_multiline_strings`
6970
> - `clojure_fuzzy_indent`
7071
> - `clojure_fuzzy_indent_blacklist`
7172
> - `clojure_special_indent_words`
@@ -92,36 +93,33 @@ let b:clojure_indent_style = 'traditional' " ...or override the default per-buf
9293

9394
### Indentation rules
9495

95-
`clojure_indent_rules`
96+
> [!NOTE]
97+
> These options are ignored if an indentation style of "uniform" is selected.
98+
99+
`clojure_indent_rules` & `clojure_fuzzy_indent_patterns`
96100

97101

98102
### Multi-line strings
99103

100104
Control alignment of _new_ lines within Clojure multi-line strings and regular
101-
expressions with `clojure_align_multiline_strings`.
105+
expressions with `clojure_indent_multiline_strings`.
102106

103107
> [!NOTE]
104108
> Indenting with `=` will not alter the indentation within multi-line strings,
105109
> as this could break intentional formatting.
106110
107-
```clojure
108-
;; let g:clojure_align_multiline_strings = 0 " Default
109-
(def default
110-
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
111-
eiusmod tempor incididunt ut labore et dolore magna aliqua.")
112-
113-
;; let g:clojure_align_multiline_strings = 1
114-
(def aligned
115-
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
116-
eiusmod tempor incididunt ut labore et dolore magna aliqua.")
117-
118-
;; let g:clojure_align_multiline_strings = -1
119-
(def traditional
120-
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
121-
eiusmod tempor incididunt ut labore et dolore magna aliqua.")
122-
```
111+
Pick from the following multi-line string indent styles:
123112

124-
There is also a buffer-local (`b:`) version of this option.
113+
| Value | Default | Description |
114+
|-------|---------|-------------|
115+
| `standard` || Align to the _front_ of the `"` or `#"` delimiter. Ideal for doc-strings. |
116+
| `pretty` | | Align to the _back_ of the `"` or `#"` delimiter. |
117+
| `traditional` | | No indent: align to left edge of file. |
118+
119+
```vim
120+
let g:clojure_indent_style = 'pretty' " Set the default indent style...
121+
let b:clojure_indent_style = 'traditional' " ...or override the default per-buffer.
122+
```
125123

126124

127125
## Code folding
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{:extra-cmds ["let g:clojure_align_multiline_strings = 0"
1+
{:extra-cmds ["let g:clojure_indent_multiline_strings = 'pretty'"
22
"normal! G"
33
"normal! o\u000atest \"hello\u000aworld\""
44
"normal! o\u000aregex #\"asdf\u000abar\""]}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{:extra-cmds ["let g:clojure_align_multiline_strings = 1"
1+
{:extra-cmds ["let g:clojure_indent_multiline_strings = 'standard'"
22
"normal! G"
33
"normal! o\u000atest \"hello\u000aworld\""
44
"normal! o\u000aregex #\"asdf\u000abar\""]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{:extra-cmds ["let g:clojure_indent_multiline_strings = 'traditional'"
2+
"normal! G"
3+
"normal! o\u000atest \"hello\u000aworld\""
4+
"normal! o\u000aregex #\"asdf\u000abar\""]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"foo
2+
bar"
3+
4+
asdf dfa sdfasdf "
5+
asdf"
6+
7+
(asdf [foo]
8+
"hel
9+
lo asd
10+
fasdfa
11+
sdf
12+
asdf
13+
as
14+
as
15+
asdf
16+
df
17+
df
18+
world")
19+
20+
#{:foo :bar
21+
:biz
22+
"ba
23+
z"}
24+
25+
#"foo
26+
bar
27+
biz"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"foo
2+
bar"
3+
4+
asdf dfa sdfasdf "
5+
asdf"
6+
7+
(asdf [foo]
8+
"hel
9+
lo asd
10+
fasdfa
11+
sdf
12+
asdf
13+
as
14+
as
15+
asdf
16+
df
17+
df
18+
world")
19+
20+
#{:foo :bar
21+
:biz
22+
"ba
23+
z"}
24+
25+
#"foo
26+
bar
27+
biz"
28+
29+
test "hello
30+
world"
31+
32+
regex #"asdf
33+
bar"

‎indent/clojure.vim

+8-14
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,14 @@ function! s:Conf(opt, fallback) abort
3535
return get(b:, a:opt, get(g:, a:opt, a:fallback))
3636
endfunction
3737

38-
" Available options:
39-
" - standard (Emacs equiv: always-align)
40-
" - traditional (Emacs equiv: align-arguments)
41-
" - uniform (Emacs equiv: always-indent)
4238
call s:SConf('clojure_indent_style', 'standard')
43-
call s:SConf('clojure_align_multiline_strings', 0)
39+
call s:SConf('clojure_indent_multiline_strings', 'standard')
4440
call s:SConf('clojure_fuzzy_indent_patterns', [
4541
\ '^with-\%(meta\|in-str\|out-str\|loading-context\)\@!',
4642
\ '^def',
4743
\ '^let'
4844
\ ])
4945

50-
" NOTE: When in "uniform" mode, ignores the "indent_style" and "indent_patterns" options.
51-
5246
" FIXME: fix reader conditional tests. Include (:require [...]) test cases.
5347
" Is it possible to fix reader conditional indentation?
5448

@@ -237,13 +231,13 @@ function! s:StringIndent(delim_pos)
237231
let m = mode()
238232
if m ==# 'i' || (m ==# 'n' && ! s:EqualsOperatorInEffect())
239233
" If in insert mode, or normal mode but "=" is not in effect.
240-
let alignment = s:Conf('clojure_align_multiline_strings', s:clojure_align_multiline_strings)
241-
" -1: Indent along left edge, like traditional Lisps.
242-
" 0: Indent in alignment with end of the string start delimiter.
243-
" 1: Indent in alignment with string start delimiter.
244-
if alignment == -1 | return 0
245-
elseif alignment == 1 | return s:PosToCharCol(a:delim_pos)
246-
else
234+
let alignment = s:Conf('clojure_indent_multiline_strings', s:clojure_indent_multiline_strings)
235+
" standard: Indent in alignment with end of the string start delimiter.
236+
" traditional: Indent along left edge, like traditional Lisps.
237+
" pretty: Indent in alignment with string start delimiter.
238+
if alignment ==# 'traditional' | return 0
239+
elseif alignment ==# 'pretty' | return s:PosToCharCol(a:delim_pos)
240+
else " standard
247241
let col = a:delim_pos[1]
248242
let is_regex = col > 1 && getline(a:delim_pos[0])[col - 2] ==# '#'
249243
return s:PosToCharCol(a:delim_pos) - (is_regex ? 2 : 1)

0 commit comments

Comments
 (0)
Please sign in to comment.