From 324f99972d5da41013eed4558c27a6b6328e6373 Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Tue, 26 Oct 2021 15:09:46 +0100 Subject: [PATCH] Configuration option to enable/disable highlighting of discard macro (#20) Disabled by default because we are currently unable to correctly highlight stacked discard reader macros. Related: #17 --- README.md | 11 +++++++++++ doc/clojure.txt | 21 +++++++++++++++++++-- syntax/clojure.vim | 21 +++++++++++---------- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5cb0441..febc9cc 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,15 @@ 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 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 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