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

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

[nongnu] elpa/clojure-ts-mode b8c860d26a: Use treesit-thing-at-point to


From: ELPA Syncer
Subject: [nongnu] elpa/clojure-ts-mode b8c860d26a: Use treesit-thing-at-point to id nodes as s-expressions
Date: Mon, 4 Sep 2023 12:59:02 -0400 (EDT)

branch: elpa/clojure-ts-mode
commit b8c860d26a7e6794ce8e4af6063017d8ed02f0fd
Author: Danny Freeman <danny@dfreeman.email>
Commit: Danny Freeman <danny@dfreeman.email>

    Use treesit-thing-at-point to id nodes as s-expressions
    
    This lets us not treat smaller sub-nodes like sym_name and sym_ns as
    s-expressions, which allows for proper transposition as described in
    issue #17
    
    Thanks to casouri and sogaiu for their help on this.
---
 CHANGELOG.md       |  2 ++
 clojure-ts-mode.el | 23 ++++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8283f0b5f8..5d532bc032 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
 
 ## main (unreleased)
 
+- Re-enable treesit-transpose-sexps on Emacs 30 after fixes released by 
@casouri.
+
 ## 0.1.5
 
 - Disable treesit-transpose-sexps on Emacs 30 in favor of the default 
implementation (#17) 
[623c98292f9207a95169cdeae6f8595c016c6320](https://github.com/clojure-emacs/clojure-ts-mode/commit/623c98292f9207a95169cdeae6f8595c016c6320)
diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index a6142243cc..658894bd6e 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -567,6 +567,23 @@ See `clojure-ts--standard-definition-node-name' for the 
implementation used.")
      ((parent-is "list_lit") parent 1)
      ((parent-is "set_lit") parent 2))))
 
+(defvar clojure-ts--sexp-nodes
+  '("#_" ;; transpose-sexp near a discard macro moves it around.
+    "num_lit" "sym_lit" "kwd_lit" "nil_lit" "bool_lit"
+    "regex_lit" "str_lit" "char_lit"
+    "list_lit" "map_lit" "vec_lit" "set_lit" "ns_map_lit"
+    "anon_fn_lit" "read_cond_lit"
+    "var_quoting_lit" "sym_val_lit" "evaling_lit"
+    "tagged_or_ctor_lit" "splicing_read_cond_lit"
+    "derefing_lit" "quoting_lit" "syn_quoting_lit"
+    "unquote_splicing_lit" "unquoting_lit")
+  "A regular expression that matches nodes that can be treated as 
s-expressions.")
+
+(defvar clojure-ts--thing-settings
+  `((clojure
+     ((sexp ,(regexp-opt clojure-ts--sexp-nodes))
+      (text ,(regexp-opt '("comment")))))))
+
 (defvar clojure-ts-mode-map
   (let ((map (make-sparse-keymap)))
     ;(set-keymap-parent map clojure-mode-map)
@@ -619,13 +636,13 @@ See `clojure-ts--standard-definition-node-name' for the 
implementation used.")
                 '((comment string char number)
                   (keyword constant symbol bracket builtin)
                   (deref quote metadata definition variable type doc regex 
tagged-literals)))
+    (when (boundp 'treesit-thing-settings) ;; Emacs 30+
+      (setq-local treesit-thing-settings clojure-ts--thing-settings))
     (when clojure-ts--debug
       (setq-local treesit--indent-verbose t
                   treesit--font-lock-verbose t)
       (treesit-inspect-mode))
-    (treesit-major-mode-setup)
-    (when (fboundp 'transpose-sexps-default-function)
-      (setq-local transpose-sexps-function 
#'transpose-sexps-default-function))))
+    (treesit-major-mode-setup)))
 
 ;;;###autoload
 (define-derived-mode clojurescript-ts-mode clojure-ts-mode "ClojureScript[TS]"



reply via email to

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