Skip to content

Commit

Permalink
Configuration option to enable/disable highlighting of discard macro (#…
Browse files Browse the repository at this point in the history
…20)

Disabled by default because we are currently unable to correctly
highlight stacked discard reader macros.

Related: #17
  • Loading branch information
axvr authored Oct 26, 2021
1 parent 3a2183e commit 324f999
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
21 changes: 19 additions & 2 deletions doc/clojure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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:
Expand Down
21 changes: 11 additions & 10 deletions syntax/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,17 @@ syntax match clojureComment "#!.*$"
syntax match clojureComment ","

" Comment out discarded forms. <https://clojure.org/guides/weird_characters#_discard>
" 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
Expand Down

0 comments on commit 324f999

Please sign in to comment.