diff --git a/CHANGELOG.md b/CHANGELOG.md index 59fedbd..ae421b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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) diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index 41d09be..70c7f02 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -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? @@ -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 @@ -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 diff --git a/test/test.clj b/test/test.clj index ae25da8..ce4c029 100644 --- a/test/test.clj +++ b/test/test.clj @@ -29,7 +29,7 @@ ;; examples of valid namespace definitions (comment (ns .validns) - + (ns =validns) (ns .ValidNs=<>?+|?*.) (ns ValidNs<>?+|?*.b*ar.ba*z) @@ -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])))