Skip to content

Commit

Permalink
Replace the old multi-line string config option
Browse files Browse the repository at this point in the history
  • Loading branch information
axvr committed Oct 5, 2024
1 parent 3487e07 commit 688d5a4
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 35 deletions.
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ offers ways to adjust the indentaion.
> The indentation code has recently been rebuilt which included the removal of
> the following configuration options:
>
> - `clojure_align_multiline_strings`
> - `clojure_fuzzy_indent`
> - `clojure_fuzzy_indent_blacklist`
> - `clojure_special_indent_words`
Expand All @@ -92,36 +93,33 @@ let b:clojure_indent_style = 'traditional' " ...or override the default per-buf

### Indentation rules

`clojure_indent_rules`
> [!NOTE]
> These options are ignored if an indentation style of "uniform" is selected.
`clojure_indent_rules` & `clojure_fuzzy_indent_patterns`


### Multi-line strings

Control alignment of _new_ lines within Clojure multi-line strings and regular
expressions with `clojure_align_multiline_strings`.
expressions with `clojure_indent_multiline_strings`.

> [!NOTE]
> Indenting with `=` will not alter the indentation within multi-line strings,
> as this could break intentional formatting.
```clojure
;; let g:clojure_align_multiline_strings = 0 " Default
(def default
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.")

;; let g:clojure_align_multiline_strings = 1
(def aligned
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.")

;; let g:clojure_align_multiline_strings = -1
(def traditional
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.")
```
Pick from the following multi-line string indent styles:

| Value | Default | Description |
|-------|---------|-------------|
| `standard` || Align to the _front_ of the `"` or `#"` delimiter. Ideal for doc-strings. |
| `pretty` | | Align to the _back_ of the `"` or `#"` delimiter. |
| `traditional` | | No indent: align to left edge of file. |

There is also a buffer-local (`b:`) version of this option.
```vim
let g:clojure_indent_multiline_strings = 'pretty' " Set the default indent style...
let b:clojure_indent_multiline_strings = 'traditional' " ...or override the default per-buffer.
```


## Code folding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:extra-cmds ["let g:clojure_align_multiline_strings = 0"
{:extra-cmds ["let g:clojure_indent_multiline_strings = 'pretty'"
"normal! G"
"normal! o\u000atest \"hello\u000aworld\""
"normal! o\u000aregex #\"asdf\u000abar\""]}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:extra-cmds ["let g:clojure_align_multiline_strings = 1"
{:extra-cmds ["let g:clojure_indent_multiline_strings = 'standard'"
"normal! G"
"normal! o\u000atest \"hello\u000aworld\""
"normal! o\u000aregex #\"asdf\u000abar\""]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:extra-cmds ["let g:clojure_indent_multiline_strings = 'traditional'"
"normal! G"
"normal! o\u000atest \"hello\u000aworld\""
"normal! o\u000aregex #\"asdf\u000abar\""]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"foo
bar"

asdf dfa sdfasdf "
asdf"

(asdf [foo]
"hel
lo asd
fasdfa
sdf
asdf
as
as
asdf
df
df
world")

#{:foo :bar
:biz
"ba
z"}

#"foo
bar
biz"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"foo
bar"

asdf dfa sdfasdf "
asdf"

(asdf [foo]
"hel
lo asd
fasdfa
sdf
asdf
as
as
asdf
df
df
world")

#{:foo :bar
:biz
"ba
z"}

#"foo
bar
biz"

test "hello
world"

regex #"asdf
bar"
22 changes: 8 additions & 14 deletions indent/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,14 @@ function! s:Conf(opt, fallback) abort
return get(b:, a:opt, get(g:, a:opt, a:fallback))
endfunction

" Available options:
" - standard (Emacs equiv: always-align)
" - traditional (Emacs equiv: align-arguments)
" - uniform (Emacs equiv: always-indent)
call s:SConf('clojure_indent_style', 'standard')
call s:SConf('clojure_align_multiline_strings', 0)
call s:SConf('clojure_indent_multiline_strings', 'standard')
call s:SConf('clojure_fuzzy_indent_patterns', [
\ '^with-\%(meta\|in-str\|out-str\|loading-context\)\@!',
\ '^def',
\ '^let'
\ ])

" NOTE: When in "uniform" mode, ignores the "indent_style" and "indent_patterns" options.

" FIXME: fix reader conditional tests. Include (:require [...]) test cases.
" Is it possible to fix reader conditional indentation?

Expand Down Expand Up @@ -237,13 +231,13 @@ function! s:StringIndent(delim_pos)
let m = mode()
if m ==# 'i' || (m ==# 'n' && ! s:EqualsOperatorInEffect())
" If in insert mode, or normal mode but "=" is not in effect.
let alignment = s:Conf('clojure_align_multiline_strings', s:clojure_align_multiline_strings)
" -1: Indent along left edge, like traditional Lisps.
" 0: Indent in alignment with end of the string start delimiter.
" 1: Indent in alignment with string start delimiter.
if alignment == -1 | return 0
elseif alignment == 1 | return s:PosToCharCol(a:delim_pos)
else
let alignment = s:Conf('clojure_indent_multiline_strings', s:clojure_indent_multiline_strings)
" standard: Indent in alignment with end of the string start delimiter.
" traditional: Indent along left edge, like traditional Lisps.
" pretty: Indent in alignment with string start delimiter.
if alignment ==# 'traditional' | return 0
elseif alignment ==# 'pretty' | return s:PosToCharCol(a:delim_pos)
else " standard
let col = a:delim_pos[1]
let is_regex = col > 1 && getline(a:delim_pos[0])[col - 2] ==# '#'
return s:PosToCharCol(a:delim_pos) - (is_regex ? 2 : 1)
Expand Down

0 comments on commit 688d5a4

Please sign in to comment.