Skip to content

Commit 632e6f8

Browse files
committed
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
1 parent 3a2183e commit 632e6f8

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ regions, such as rainbow parenphesis plugins.)
3636

3737
### Syntax options
3838

39+
#### `g:clojure_syntax_keywords`
40+
3941
Syntax highlighting of public vars in `clojure.core` is provided by default,
4042
but additional symbols can be highlighted by adding them to the
4143
`g:clojure_syntax_keywords` variable.
@@ -58,6 +60,14 @@ will not be highlighted by default. This is useful for namespaces that have
5860
set `(:refer-clojure :only [])`.
5961

6062

63+
#### `g:clojure_discard_macro`
64+
65+
Set this variable to `1` to enable highlighting of the
66+
"[discard reader macro](https://clojure.org/guides/weird_characters#_discard)".
67+
Due to limitations in Vim's syntax rules we cannot correctly highlight stacked
68+
discard macros (e.g. `#_#_`).
69+
70+
6171
### Indent options
6272

6373
Clojure indentation differs somewhat from traditional Lisps, due in part to

doc/clojure.txt

+19-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ clojure-mode.el:
115115

116116
CLOJURE *ft-clojure-syntax*
117117

118+
*g:clojure_syntax_keywords*
119+
118120
Syntax highlighting of public vars in "clojure.core" is provided by default,
119121
but additional symbols can be highlighted by adding them to the
120-
*g:clojure_syntax_keywords* variable. The value should be a |Dictionary| of
122+
|g:clojure_syntax_keywords| variable. The value should be a |Dictionary| of
121123
syntax group names, each containing a |List| of identifiers.
122124
>
123125
let g:clojure_syntax_keywords = {
@@ -135,11 +137,26 @@ By setting the *b:clojure_syntax_without_core_keywords* variable, vars from
135137
"clojure.core" will not be highlighted by default. This is useful for
136138
namespaces that have set `(:refer-clojure :only [])`
137139

138-
Setting *g:clojure_fold* to `1` will enable the folding of Clojure code. Any
140+
141+
*g:clojure_fold*
142+
143+
Setting |g:clojure_fold| to `1` will enable the folding of Clojure code. Any
139144
list, vector or map that extends over more than one line can be folded using
140145
the standard Vim |fold-commands|.
141146

142147

148+
*g:clojure_discard*
149+
150+
Set this variable to `1` to enable basic highlighting of Clojure's "discard
151+
reader macro".
152+
>
153+
#_(defn foo [x]
154+
(println x))
155+
<
156+
Note that this option will not correctly highlight stacked discard macros
157+
(e.g. `#_#_`).
158+
159+
143160
ABOUT *clojure-about*
144161

145162
This document and associated runtime files are maintained at:

syntax/clojure.vim

+11-10
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,17 @@ syntax match clojureComment "#!.*$"
136136
syntax match clojureComment ","
137137

138138
" Comment out discarded forms. <https://clojure.org/guides/weird_characters#_discard>
139-
" TODO: stacking support and/or option to enable/disable this.
140-
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*/ end=/[, \t\n()\[\]{}";]/me=e-1
141-
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*"/ skip=/\\[\\"]/ end=/"/
142-
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*(/ end=/)/ contains=clojureDiscardForm
143-
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*\[/ end=/\]/ contains=clojureDiscardForm
144-
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*{/ end=/}/ contains=clojureDiscardForm
145-
146-
syntax region clojureDiscardForm start="(" end=")" contained contains=clojureDiscardForm
147-
syntax region clojureDiscardForm start="{" end="}" contained contains=clojureDiscardForm
148-
syntax region clojureDiscardForm start="\[" end="\]" contained contains=clojureDiscardForm
139+
if exists('g:clojure_discard_macro') && g:clojure_discard_macro
140+
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*/ end=/[, \t\n()\[\]{}";]/me=e-1
141+
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*"/ skip=/\\[\\"]/ end=/"/
142+
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*(/ end=/)/ contains=clojureDiscardForm
143+
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*\[/ end=/\]/ contains=clojureDiscardForm
144+
syntax region clojureDiscard matchgroup=clojureDiscard start=/#_[ ,\t\n`'~]*{/ end=/}/ contains=clojureDiscardForm
145+
146+
syntax region clojureDiscardForm start="(" end=")" contained contains=clojureDiscardForm
147+
syntax region clojureDiscardForm start="{" end="}" contained contains=clojureDiscardForm
148+
syntax region clojureDiscardForm start="\[" end="\]" contained contains=clojureDiscardForm
149+
endif
149150

150151
" -*- TOP CLUSTER -*-
151152
" Generated from https://github.com/clojure-vim/clojure.vim/blob/%%RELEASE_TAG%%/clj/src/vim_clojure_static/generate.clj

0 commit comments

Comments
 (0)