Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration option to enable/disable highlighting of discard macro #20

Merged
merged 3 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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