From c97dcbfcfe77791de1312bdb21437c7a95e982de Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Sun, 17 Oct 2021 11:15:44 +0100 Subject: [PATCH 1/3] Configuration option to enable/disable highlighting of discard macro Disabled by default because we are currently unable to correctly highlight stacked discard reader macros. Related: #17 --- README.md | 10 ++++++++++ doc/clojure.txt | 21 +++++++++++++++++++-- syntax/clojure.vim | 21 +++++++++++---------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5cb0441..df7ed31 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ regions, such as rainbow parenphesis plugins.) ### Syntax options +#### `g:clojure_syntax_keywords` + Syntax highlighting of public vars in `clojure.core` is provided by default, but additional symbols can be highlighted by adding them to the `g:clojure_syntax_keywords` variable. @@ -58,6 +60,14 @@ will not be highlighted by default. This is useful for namespaces that have set `(:refer-clojure :only [])`. +#### `g:clojure_discard_macro` + +Set this variable to `1` to enable highlighting of the +"[discard reader macro](https://clojure.org/guides/weird_characters#_discard)". +Due to limitations in Vim's syntax rules we cannot correctly highlight stacked +discard macros (e.g. `#_#_`). + + ### Indent options Clojure indentation differs somewhat from traditional Lisps, due in part to diff --git a/doc/clojure.txt b/doc/clojure.txt index a063cb9..eb3566a 100644 --- a/doc/clojure.txt +++ b/doc/clojure.txt @@ -115,9 +115,11 @@ clojure-mode.el: CLOJURE *ft-clojure-syntax* + *g:clojure_syntax_keywords* + Syntax highlighting of public vars in "clojure.core" is provided by default, but additional symbols can be highlighted by adding them to the -*g:clojure_syntax_keywords* variable. The value should be a |Dictionary| of +|g:clojure_syntax_keywords| variable. The value should be a |Dictionary| of syntax group names, each containing a |List| of identifiers. > let g:clojure_syntax_keywords = { @@ -135,11 +137,26 @@ By setting the *b:clojure_syntax_without_core_keywords* variable, vars from "clojure.core" will not be highlighted by default. This is useful for namespaces that have set `(:refer-clojure :only [])` -Setting *g:clojure_fold* to `1` will enable the folding of Clojure code. Any + + *g:clojure_fold* + +Setting |g:clojure_fold| to `1` will enable the folding of Clojure code. Any list, vector or map that extends over more than one line can be folded using the standard Vim |fold-commands|. + *g:clojure_discard_macro* + +Set this variable to `1` to enable basic highlighting of Clojure's "discard +reader macro". +> + #_(defn foo [x] + (println x)) +< +Note that this option will not correctly highlight stacked discard macros +(e.g. `#_#_`). + + ABOUT *clojure-about* This document and associated runtime files are maintained at: diff --git a/syntax/clojure.vim b/syntax/clojure.vim index 5acdffa..254f5f5 100644 --- a/syntax/clojure.vim +++ b/syntax/clojure.vim @@ -136,16 +136,17 @@ syntax match clojureComment "#!.*$" syntax match clojureComment "," " Comment out discarded forms. -" TODO: stacking support and/or option to enable/disable this. -syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*/ end=/[, \t\n()\[\]{}";]/me=e-1 -syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*"/ skip=/\\[\\"]/ end=/"/ -syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*(/ end=/)/ contains=clojureDiscardForm -syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*\[/ end=/\]/ contains=clojureDiscardForm -syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*{/ end=/}/ contains=clojureDiscardForm - -syntax region clojureDiscardForm start="(" end=")" contained contains=clojureDiscardForm -syntax region clojureDiscardForm start="{" end="}" contained contains=clojureDiscardForm -syntax region clojureDiscardForm start="\[" end="\]" contained contains=clojureDiscardForm +if exists('g:clojure_discard_macro') && g:clojure_discard_macro + syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*/ end=/[, \t\n()\[\]{}";]/me=e-1 + syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*"/ skip=/\\[\\"]/ end=/"/ + syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*(/ end=/)/ contains=clojureDiscardForm + syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*\[/ end=/\]/ contains=clojureDiscardForm + syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*{/ end=/}/ contains=clojureDiscardForm + + syntax region clojureDiscardForm start="(" end=")" contained contains=clojureDiscardForm + syntax region clojureDiscardForm start="{" end="}" contained contains=clojureDiscardForm + syntax region clojureDiscardForm start="\[" end="\]" contained contains=clojureDiscardForm +endif " -*- TOP CLUSTER -*- " Generated from https://github.com/clojure-vim/clojure.vim/blob/%%RELEASE_TAG%%/clj/src/vim_clojure_static/generate.clj From a3391581188f36f21bdd4a67c9eafdad31cabdbb Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Tue, 26 Oct 2021 15:01:20 +0100 Subject: [PATCH 2/3] fixup! Configuration option to enable/disable highlighting of discard macro --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df7ed31..4c52e71 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,8 @@ set `(:refer-clojure :only [])`. Set this variable to `1` to enable highlighting of the "[discard reader macro](https://clojure.org/guides/weird_characters#_discard)". -Due to limitations in Vim's syntax rules we cannot correctly highlight stacked -discard macros (e.g. `#_#_`). +Due to limitations in Vim's syntax rules we currently cannot highlight stacked +discard macros (e.g. `#_#_`), hence this option is disabled by default. ### Indent options From 5c19b834095e8aaf2688dca13abb2675f4fd5baa Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Tue, 26 Oct 2021 15:07:11 +0100 Subject: [PATCH 3/3] fixup! fixup! Configuration option to enable/disable highlighting of discard macro --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4c52e71..febc9cc 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,9 @@ set `(:refer-clojure :only [])`. Set this variable to `1` to enable highlighting of the "[discard reader macro](https://clojure.org/guides/weird_characters#_discard)". -Due to limitations in Vim's syntax rules we currently cannot highlight stacked -discard macros (e.g. `#_#_`), hence this option is disabled by default. +Due to current limitations in Vim's syntax rules, this option won't highlight +stacked discard macros (e.g. `#_#_`). This inconsitency is why this option is +disabled by default. ### Indent options