clojure-ts-mode icon indicating copy to clipboard operation
clojure-ts-mode copied to clipboard

No way to recognize additional function definition macros

Open jasonjckn opened this issue 2 years ago • 2 comments
trafficstars

Libraries like https://github.com/gnl/ghostwheel have a macro >defn for defining functions, in one of my codebases i define >defn myself, but it's implemented with malli.experimental/defn

There's no way to adjust clojure-ts-mode syntax highlighting without forking the repo, e.g.

  (defconst clojure-ts--definition-keyword-regexp
    (rx
     line-start
     (or (group (or "ns" "fn"))
         (group ">def"
                (+ (or alnum
                       ;; What are valid characters for symbols? is a negative match better?
                       "-" "_" "!" "@" "#" "$" "%" "^" "&" "*" "|" "?" "<" ">" "+" "=" ":")))
         (group "def"
                (+ (or alnum
                       ;; What are valid characters for symbols? is a negative match better?
                       "-" "_" "!" "@" "#" "$" "%" "^" "&" "*" "|" "?" "<" ">" "+" "=" ":"))))
     line-end))

  (defvar clojure-ts--function-type-regexp
    (rx string-start (or ">defn" "defn" "defmethod") string-end))

There should be a general extension mechanism.


One random idea is we parse PROJECT/.clj-kondo/** edn files for :lint-as, e.g.

 :lint-as {
           mynamespace/>defn       schema.core/defn
           richelieu.core/defadvice clojure.core/defn
           }

Although doing this the proper way would probably add too much complexity.

jasonjckn avatar Aug 13 '23 02:08 jasonjckn

Sort of related to:

There should be a general extension mechanism.

FWIW, for janet-ts-mode there was a similar request:

I would like to add a customizable variable janet-ts-indent-special-words to add extra custom values to indent-special. Mainly because I have been working on a DSL which includes a lot of defn-like macros which don't start with "def", and would like to be able to get good indentation for them without modifying janet-ts-mode directly.

So we did this.

sogaiu avatar Aug 13 '23 03:08 sogaiu

Yeah we're going to have to add something similar to janet-ts-mode. Once semantic indentation is in I think I would like to consolidate some of the regular expressions and add an extension mechanism.

As for reading files, maybe reading cljfmt configuration files (based on the current project) would be worthwhile. See https://github.com/weavejester/cljfmt#configuration

dannyfreeman avatar Aug 17 '23 02:08 dannyfreeman