highlight a form with clojure's comment macro in vim

213 Views Asked by At

In clojure, you can use #_ to comment out the next form. For example

#_(foo 2 3 4)
#_foo
#_{:a '(1 2 3) :b [1 2 3]}

will comment out the above list, symbol and map. Like Emacs, I would expect and want that the form would get the syntax highlightning of a comment.

In vim, there is no default syntax highlighting for commented-out-forms. I have also not found any plugin that does this. Have anyone tried to configure this? Thankful for any help.

1

There are 1 best solutions below

0
On

The vim-clojure-static plugin has not enabled commenting out using the #_ form because it disabled REPL integration for the commented out block (see https://github.com/guns/vim-clojure-static/issues/60).

In the issue that addresses this (linked above) @guns provided the following addition to the syntax file to enable highlighting of comments:

" WARNING: This code has the following KNOWN deficiencies: " " · Consecutive #_ macros are not matched correctly: " (list #_#_ 1 2 3) ;; => (3) " · Bracket character literals within #_ comment regions break syntax: " #_[\a \[ \] \b] ;; broken " · Compound forms preceded by reader metacharacters are unmatched: " #_'(α β γ) ;; broken " · Atomic forms preceded by reader metacharacters + whitespace are unmatched: " #_' foo ;; broken " syntax match clojureCommentAtom /\v#_[ \t\r\n]*[^()\[\]{} \t\r\n]+/ syntax region clojureCommentListContained start=/(/ end=/)/ contains=clojureCommentListContained,clojureCommentVectorContained,clojureCommentMapContained,clojureCommentStringContained contained syntax region clojureCommentVectorContained start=/\[/ end=/]/ contains=clojureCommentListContained,clojureCommentVectorContained,clojureCommentMapContained,clojureCommentStringContained contained syntax region clojureCommentMapContained start=/{/ end=/}/ contains=clojureCommentListContained,clojureCommentVectorContained,clojureCommentMapContained,clojureCommentStringContained contained syntax region clojureCommentStringContained start=/"/ skip=/\v\\\\|\\"/ end=/"/ contained syntax region clojureCommentList matchgroup=clojureCommentDelimiter start=/\v#_[ \t\r\n]*\(/ end=/)/ contains=clojureCommentListContained,clojureCommentVectorContained,clojureCommentMapContained,clojureCommentStringContained syntax region clojureCommentVector matchgroup=clojureCommentDelimiter start=/\v#_[ \t\r\n]*\[/ end=/]/ contains=clojureCommentListContained,clojureCommentVectorContained,clojureCommentMapContained,clojureCommentStringContained syntax region clojureCommentMap matchgroup=clojureCommentDelimiter start=/\v#_[ \t\r\n]*\{/ end=/}/ contains=clojureCommentListContained,clojureCommentVectorContained,clojureCommentMapContained,clojureCommentStringContained syntax region clojureCommentString matchgroup=clojureCommentDelimiter start=/\v#_[ \t\r\n]*"/ skip=/\v\\\\|\\"/ end=/"/ highlight link clojureCommentDelimiter clojureComment highlight link clojureCommentAtom clojureComment highlight link clojureCommentListContained clojureComment highlight link clojureCommentVectorContained clojureComment highlight link clojureCommentMapContained clojureComment highlight link clojureCommentStringContained clojureComment highlight link clojureCommentList clojureComment highlight link clojureCommentVector clojureComment highlight link clojureCommentMap clojureComment highlight link clojureCommentString clojureComment

I personally use Spacemacs (Emacs with Vim bindings and batteries included) with Clojure layer, and there comments and REPL integration both work fine, but I believe you are aware of this.