From 688d5a4cfa73c9b6d569e415aff33105349ed630 Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Sat, 5 Oct 2024 15:40:09 +0100 Subject: [PATCH] Replace the old multi-line string config option --- README.md | 36 +++++++++---------- .../config.edn | 2 +- .../in.clj | 0 .../out.clj | 0 .../config.edn | 2 +- .../in.clj | 0 .../out.clj | 0 .../multi-line_strings_traditional/config.edn | 4 +++ .../multi-line_strings_traditional/in.clj | 27 ++++++++++++++ .../multi-line_strings_traditional/out.clj | 33 +++++++++++++++++ indent/clojure.vim | 22 +++++------- 11 files changed, 91 insertions(+), 35 deletions(-) rename clj/resources/indent-test-cases/{strings => multi-line_strings_pretty}/config.edn (68%) rename clj/resources/indent-test-cases/{strings => multi-line_strings_pretty}/in.clj (100%) rename clj/resources/indent-test-cases/{strings_align => multi-line_strings_pretty}/out.clj (100%) rename clj/resources/indent-test-cases/{strings_align => multi-line_strings_standard}/config.edn (67%) rename clj/resources/indent-test-cases/{strings_align => multi-line_strings_standard}/in.clj (100%) rename clj/resources/indent-test-cases/{strings => multi-line_strings_standard}/out.clj (100%) create mode 100644 clj/resources/indent-test-cases/multi-line_strings_traditional/config.edn create mode 100644 clj/resources/indent-test-cases/multi-line_strings_traditional/in.clj create mode 100644 clj/resources/indent-test-cases/multi-line_strings_traditional/out.clj diff --git a/README.md b/README.md index 8770e9c..9ea9b2f 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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 diff --git a/clj/resources/indent-test-cases/strings/config.edn b/clj/resources/indent-test-cases/multi-line_strings_pretty/config.edn similarity index 68% rename from clj/resources/indent-test-cases/strings/config.edn rename to clj/resources/indent-test-cases/multi-line_strings_pretty/config.edn index 6b367d4..a756dbb 100644 --- a/clj/resources/indent-test-cases/strings/config.edn +++ b/clj/resources/indent-test-cases/multi-line_strings_pretty/config.edn @@ -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\""]} diff --git a/clj/resources/indent-test-cases/strings/in.clj b/clj/resources/indent-test-cases/multi-line_strings_pretty/in.clj similarity index 100% rename from clj/resources/indent-test-cases/strings/in.clj rename to clj/resources/indent-test-cases/multi-line_strings_pretty/in.clj diff --git a/clj/resources/indent-test-cases/strings_align/out.clj b/clj/resources/indent-test-cases/multi-line_strings_pretty/out.clj similarity index 100% rename from clj/resources/indent-test-cases/strings_align/out.clj rename to clj/resources/indent-test-cases/multi-line_strings_pretty/out.clj diff --git a/clj/resources/indent-test-cases/strings_align/config.edn b/clj/resources/indent-test-cases/multi-line_strings_standard/config.edn similarity index 67% rename from clj/resources/indent-test-cases/strings_align/config.edn rename to clj/resources/indent-test-cases/multi-line_strings_standard/config.edn index b1aff05..ba0c5e0 100644 --- a/clj/resources/indent-test-cases/strings_align/config.edn +++ b/clj/resources/indent-test-cases/multi-line_strings_standard/config.edn @@ -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\""]} diff --git a/clj/resources/indent-test-cases/strings_align/in.clj b/clj/resources/indent-test-cases/multi-line_strings_standard/in.clj similarity index 100% rename from clj/resources/indent-test-cases/strings_align/in.clj rename to clj/resources/indent-test-cases/multi-line_strings_standard/in.clj diff --git a/clj/resources/indent-test-cases/strings/out.clj b/clj/resources/indent-test-cases/multi-line_strings_standard/out.clj similarity index 100% rename from clj/resources/indent-test-cases/strings/out.clj rename to clj/resources/indent-test-cases/multi-line_strings_standard/out.clj diff --git a/clj/resources/indent-test-cases/multi-line_strings_traditional/config.edn b/clj/resources/indent-test-cases/multi-line_strings_traditional/config.edn new file mode 100644 index 0000000..a969070 --- /dev/null +++ b/clj/resources/indent-test-cases/multi-line_strings_traditional/config.edn @@ -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\""]} diff --git a/clj/resources/indent-test-cases/multi-line_strings_traditional/in.clj b/clj/resources/indent-test-cases/multi-line_strings_traditional/in.clj new file mode 100644 index 0000000..0efd8a2 --- /dev/null +++ b/clj/resources/indent-test-cases/multi-line_strings_traditional/in.clj @@ -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" diff --git a/clj/resources/indent-test-cases/multi-line_strings_traditional/out.clj b/clj/resources/indent-test-cases/multi-line_strings_traditional/out.clj new file mode 100644 index 0000000..8860013 --- /dev/null +++ b/clj/resources/indent-test-cases/multi-line_strings_traditional/out.clj @@ -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" diff --git a/indent/clojure.vim b/indent/clojure.vim index ac41847..bfaa18e 100644 --- a/indent/clojure.vim +++ b/indent/clojure.vim @@ -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? @@ -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)