emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/clojure-ts-mode b96d85d0d4 2/5: Merge pull request #21 fro


From: ELPA Syncer
Subject: [nongnu] elpa/clojure-ts-mode b96d85d0d4 2/5: Merge pull request #21 from rrudakov/main
Date: Fri, 15 Sep 2023 00:59:17 -0400 (EDT)

branch: elpa/clojure-ts-mode
commit b96d85d0d4ceff56f2bc9d32e4abd96392b1f739
Merge: 5f16fb8dbc 5231c348e5
Author: Danny Freeman <dannyfreeman@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #21 from rrudakov/main
    
    Highlight methods in some forms
---
 CHANGELOG.md       |  4 +++-
 clojure-ts-mode.el | 45 +++++++++++++++++++++++++++++++++++++++++----
 test/test.clj      | 43 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 86 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33254bb63f..8fd787924f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,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
 
@@ -28,7 +30,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 54a808eb44..6b588e60af 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 ae25da855a..ce4c0292aa 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])))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]