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

Highlight methods in some forms #21

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- Highlight "\`quoted-symbols\` in docs strings like this."
- This feature uses a nested markdown parser.
If the parser is not available this feature should be silently disabled.
- Highlight methods for `deftype`, `defrecord`, `defprotocol`, `reify` and `definterface`
forms ([#20](https://github.com/clojure-emacs/clojure-ts-mode/issues/20)).

## 0.1.5

Expand All @@ -29,7 +31,7 @@

## 0.1.2

- Add a syntax table from clojure-mode. [712dc772fd38111c1e35fe60e4dbe7ac83032bd6](https://github.com/clojure-emacs/clojure-ts-mode/commit/712dc772fd38111c1e35fe60e4dbe7ac83032bd6).
- Add a syntax table from clojure-mode. [712dc772fd38111c1e35fe60e4dbe7ac83032bd6](https://github.com/clojure-emacs/clojure-ts-mode/commit/712dc772fd38111c1e35fe60e4dbe7ac83032bd6).
- Better support for `thing-at-point` driven functionality.
- Thank you @jasonjckn for this contribution.
- Add 3 derived major modes [4dc853df16ba09d10dc3a648865e681679c17606](https://github.com/clojure-emacs/clojure-ts-mode/commit/4dc853df16ba09d10dc3a648865e681679c17606)
Expand Down
45 changes: 41 additions & 4 deletions clojure-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Only intended for use at development time.")
(defconst clojure-ts--definition-symbol-regexp
(rx
line-start
(or (group (or "ns" "fn"))
(or (group "fn")
(group "def"
(+ (or alnum
;; What are valid characters for symbols?
Expand Down Expand Up @@ -347,9 +347,42 @@ with the markdown_inline grammar."
:language 'clojure
`(((list_lit :anchor (sym_lit (sym_name) @def)
:anchor (sym_lit (sym_name) @font-lock-function-name-face))
(:match ,clojure-ts--definition-symbol-regexp @def))
(:match ,(rx-to-string
`(seq bol
(or
"defn"
"defn-"
"defmulti"
"defmethod"
"deftest"
"deftest-"
"defmacro"
"definline")
eol))
@def))
((anon_fn_lit
marker: "#" @font-lock-property-face)))
marker: "#" @font-lock-property-face))
;; Methods implementation
((list_lit
((sym_lit name: (sym_name) @def)
((:match ,(rx-to-string
`(seq bol
(or
"defrecord"
"definterface"
"deftype"
"defprotocol")
eol))
@def)))
:anchor
(sym_lit (sym_name) @font-lock-type-face)
(list_lit
(sym_lit name: (sym_name) @font-lock-function-name-face))))
((list_lit
((sym_lit name: (sym_name) @def)
((:equal "reify" @def)))
(list_lit
(sym_lit name: (sym_name) @font-lock-function-name-face)))))

:feature 'variable ;; def, defonce
:language 'clojure
Expand All @@ -370,7 +403,11 @@ with the markdown_inline grammar."
value: (sym_lit (sym_name) @font-lock-type-face))
(old_meta_lit
marker: "#^" @font-lock-operator-face
value: (sym_lit (sym_name) @font-lock-type-face)))
value: (sym_lit (sym_name) @font-lock-type-face))
;; Highlight namespace
((list_lit :anchor (sym_lit (sym_name) @def)
:anchor (sym_lit (sym_name) @font-lock-type-face))
(:equal "ns" @def)))

:feature 'metadata
:language 'clojure
Expand Down
43 changes: 42 additions & 1 deletion test/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
;; examples of valid namespace definitions
(comment
(ns .validns)

(ns =validns)
(ns .ValidNs=<>?+|?*.)
(ns ValidNs<>?+|?*.b*ar.ba*z)
Expand Down Expand Up @@ -289,3 +289,44 @@ clojure.core/map

(def ^Integer x 1)

(comment
(defrecord TestRecord [field]
AutoCloseable
(close [this]
(.close this)))

(reify
AutoCloseable
(close [this] (.close this))

(another [this arg]
(implement this arg)))

(definterface MyInterface
(^String name [])
(^double mass []))

(defmulti my-method :hello :default ::default)

(defmethod my-method :world
[_]
(println "Hi"))

(deftype ImageSelection [data]
Transferable
(getTransferDataFlavors
[this]
(into-array DataFlavor [DataFlavor/imageFlavor]))

(isDataFlavorSupported
[this flavor]
(= DataFlavor/imageFlavor flavor))

(getTransferData
[this flavor]
(when (= DataFlavor/imageFlavor flavor)
(.getImage (ImageIcon. data)))))

(defprotocol P
(foo [this])
(bar-me [this] [this y])))