Skip to content

Commit b96d85d

Browse files
authored
Merge pull request #21 from rrudakov/main
Highlight methods in some forms
2 parents 5f16fb8 + 5231c34 commit b96d85d

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- Highlight "\`quoted-symbols\` in docs strings like this."
1111
- This feature uses a nested markdown parser.
1212
If the parser is not available this feature should be silently disabled.
13+
- Highlight methods for `deftype`, `defrecord`, `defprotocol`, `reify` and `definterface`
14+
forms ([#20](https://github.com/clojure-emacs/clojure-ts-mode/issues/20)).
1315

1416
## 0.1.5
1517

@@ -28,7 +30,7 @@
2830

2931
## 0.1.2
3032

31-
- Add a syntax table from clojure-mode. [712dc772fd38111c1e35fe60e4dbe7ac83032bd6](https://github.com/clojure-emacs/clojure-ts-mode/commit/712dc772fd38111c1e35fe60e4dbe7ac83032bd6).
33+
- Add a syntax table from clojure-mode. [712dc772fd38111c1e35fe60e4dbe7ac83032bd6](https://github.com/clojure-emacs/clojure-ts-mode/commit/712dc772fd38111c1e35fe60e4dbe7ac83032bd6).
3234
- Better support for `thing-at-point` driven functionality.
3335
- Thank you @jasonjckn for this contribution.
3436
- Add 3 derived major modes [4dc853df16ba09d10dc3a648865e681679c17606](https://github.com/clojure-emacs/clojure-ts-mode/commit/4dc853df16ba09d10dc3a648865e681679c17606)

clojure-ts-mode.el

+41-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Only intended for use at development time.")
205205
(defconst clojure-ts--definition-symbol-regexp
206206
(rx
207207
line-start
208-
(or (group (or "ns" "fn"))
208+
(or (group "fn")
209209
(group "def"
210210
(+ (or alnum
211211
;; What are valid characters for symbols?
@@ -347,9 +347,42 @@ with the markdown_inline grammar."
347347
:language 'clojure
348348
`(((list_lit :anchor (sym_lit (sym_name) @def)
349349
:anchor (sym_lit (sym_name) @font-lock-function-name-face))
350-
(:match ,clojure-ts--definition-symbol-regexp @def))
350+
(:match ,(rx-to-string
351+
`(seq bol
352+
(or
353+
"defn"
354+
"defn-"
355+
"defmulti"
356+
"defmethod"
357+
"deftest"
358+
"deftest-"
359+
"defmacro"
360+
"definline")
361+
eol))
362+
@def))
351363
((anon_fn_lit
352-
marker: "#" @font-lock-property-face)))
364+
marker: "#" @font-lock-property-face))
365+
;; Methods implementation
366+
((list_lit
367+
((sym_lit name: (sym_name) @def)
368+
((:match ,(rx-to-string
369+
`(seq bol
370+
(or
371+
"defrecord"
372+
"definterface"
373+
"deftype"
374+
"defprotocol")
375+
eol))
376+
@def)))
377+
:anchor
378+
(sym_lit (sym_name) @font-lock-type-face)
379+
(list_lit
380+
(sym_lit name: (sym_name) @font-lock-function-name-face))))
381+
((list_lit
382+
((sym_lit name: (sym_name) @def)
383+
((:equal "reify" @def)))
384+
(list_lit
385+
(sym_lit name: (sym_name) @font-lock-function-name-face)))))
353386

354387
:feature 'variable ;; def, defonce
355388
:language 'clojure
@@ -370,7 +403,11 @@ with the markdown_inline grammar."
370403
value: (sym_lit (sym_name) @font-lock-type-face))
371404
(old_meta_lit
372405
marker: "#^" @font-lock-operator-face
373-
value: (sym_lit (sym_name) @font-lock-type-face)))
406+
value: (sym_lit (sym_name) @font-lock-type-face))
407+
;; Highlight namespace
408+
((list_lit :anchor (sym_lit (sym_name) @def)
409+
:anchor (sym_lit (sym_name) @font-lock-type-face))
410+
(:equal "ns" @def)))
374411

375412
:feature 'metadata
376413
:language 'clojure

test/test.clj

+42-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
;; examples of valid namespace definitions
3030
(comment
3131
(ns .validns)
32-
32+
3333
(ns =validns)
3434
(ns .ValidNs=<>?+|?*.)
3535
(ns ValidNs<>?+|?*.b*ar.ba*z)
@@ -289,3 +289,44 @@ clojure.core/map
289289

290290
(def ^Integer x 1)
291291

292+
(comment
293+
(defrecord TestRecord [field]
294+
AutoCloseable
295+
(close [this]
296+
(.close this)))
297+
298+
(reify
299+
AutoCloseable
300+
(close [this] (.close this))
301+
302+
(another [this arg]
303+
(implement this arg)))
304+
305+
(definterface MyInterface
306+
(^String name [])
307+
(^double mass []))
308+
309+
(defmulti my-method :hello :default ::default)
310+
311+
(defmethod my-method :world
312+
[_]
313+
(println "Hi"))
314+
315+
(deftype ImageSelection [data]
316+
Transferable
317+
(getTransferDataFlavors
318+
[this]
319+
(into-array DataFlavor [DataFlavor/imageFlavor]))
320+
321+
(isDataFlavorSupported
322+
[this flavor]
323+
(= DataFlavor/imageFlavor flavor))
324+
325+
(getTransferData
326+
[this flavor]
327+
(when (= DataFlavor/imageFlavor flavor)
328+
(.getImage (ImageIcon. data)))))
329+
330+
(defprotocol P
331+
(foo [this])
332+
(bar-me [this] [this y])))

0 commit comments

Comments
 (0)