clojure-emacs / clojure-ts-mode

The next generation Clojure major mode for Emacs, powered by TreeSitter
GNU General Public License v3.0
129 stars 11 forks source link

No way to recognize additional function definition macros #15

Open jasonjckn opened 1 year ago

jasonjckn commented 1 year ago

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.

sogaiu commented 1 year ago

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.

dannyfreeman commented 1 year ago

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