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

No way to recognize additional function definition macros #15

Open
jasonjckn opened this issue Aug 13, 2023 · 2 comments
Open

No way to recognize additional function definition macros #15

jasonjckn opened this issue Aug 13, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@jasonjckn
Copy link
Contributor

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
Copy link

sogaiu commented Aug 13, 2023

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
Copy link
Contributor

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 dannyfreeman added the enhancement New feature or request label Aug 17, 2023
dannyfreeman added a commit that referenced this issue Sep 15, 2023
This also begins the process of making our symbol matching regular
expressions user extensible (see issue #15). There are more to convert
from regexps to normal lists, but I want to take my time and make sure I
get the names down correctly. It is important to get maximum reuse so
users don't have to add their fancy def-whatever to 4 different lists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants