clojure-vim/clojure.vim

Is it possible to highlight function docStrings?

Closed this issue · 2 comments

Was wondering if it is possible to target the doc strings that are in a defn form separately from normal Strings?
(defn my-function "This is the doc string I am talking about. It would be great if this can be highlighted differently from regular Strings" [arg 1 arg2] ...
I probably need a syntax region, but I am lost with the syntax file format. Thanks

axvr commented

Hi @scotts777,

It is technically possible, however I wouldn't say it is worth the pain of adding it. There are several reasons I say this:

  1. For consistency, the same syntax highlighting of doc-strings should happen for def, defonce, defn, defn-, defmacro, defmulti, defprotocol, defrecord, defstruct, deftype and definline. Some of these have different rules for where doc-strings appear.
  2. The regular expressions to make it work would be very complex and difficult to write/maintain. Just differentiating between these two things with regular expressions, is far more difficult than you would initially think:
    (def foo
      "regular string")
    
    (def bar
      "doc-string"
      nil)
  3. For yet more consistency, I think there would need to be a way to configure the same highlighting on custom macros such as defrule in Clara rules. I have no idea how this could be accomplished.
  4. Doc-strings are actually just strings.

As far as I'm aware, for these reasons (and maybe others), no other editor supports this. However, you can of course add the syntax highlight rules for it to your personal Vim config overriding our defaults. Unfortunately I'm not entirely sure how you would go about writing those syntax rules.

Yes, that makes good sense.