Skip to content

Commit b8c860d

Browse files
committed
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.
1 parent 4e18177 commit b8c860d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## main (unreleased)
44

5+
- Re-enable treesit-transpose-sexps on Emacs 30 after fixes released by @casouri.
6+
57
## 0.1.5
68

79
- 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)

clojure-ts-mode.el

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,23 @@ See `clojure-ts--standard-definition-node-name' for the implementation used.")
567567
((parent-is "list_lit") parent 1)
568568
((parent-is "set_lit") parent 2))))
569569

570+
(defvar clojure-ts--sexp-nodes
571+
'("#_" ;; transpose-sexp near a discard macro moves it around.
572+
"num_lit" "sym_lit" "kwd_lit" "nil_lit" "bool_lit"
573+
"regex_lit" "str_lit" "char_lit"
574+
"list_lit" "map_lit" "vec_lit" "set_lit" "ns_map_lit"
575+
"anon_fn_lit" "read_cond_lit"
576+
"var_quoting_lit" "sym_val_lit" "evaling_lit"
577+
"tagged_or_ctor_lit" "splicing_read_cond_lit"
578+
"derefing_lit" "quoting_lit" "syn_quoting_lit"
579+
"unquote_splicing_lit" "unquoting_lit")
580+
"A regular expression that matches nodes that can be treated as s-expressions.")
581+
582+
(defvar clojure-ts--thing-settings
583+
`((clojure
584+
((sexp ,(regexp-opt clojure-ts--sexp-nodes))
585+
(text ,(regexp-opt '("comment")))))))
586+
570587
(defvar clojure-ts-mode-map
571588
(let ((map (make-sparse-keymap)))
572589
;(set-keymap-parent map clojure-mode-map)
@@ -619,13 +636,13 @@ See `clojure-ts--standard-definition-node-name' for the implementation used.")
619636
'((comment string char number)
620637
(keyword constant symbol bracket builtin)
621638
(deref quote metadata definition variable type doc regex tagged-literals)))
639+
(when (boundp 'treesit-thing-settings) ;; Emacs 30+
640+
(setq-local treesit-thing-settings clojure-ts--thing-settings))
622641
(when clojure-ts--debug
623642
(setq-local treesit--indent-verbose t
624643
treesit--font-lock-verbose t)
625644
(treesit-inspect-mode))
626-
(treesit-major-mode-setup)
627-
(when (fboundp 'transpose-sexps-default-function)
628-
(setq-local transpose-sexps-function #'transpose-sexps-default-function))))
645+
(treesit-major-mode-setup)))
629646

630647
;;;###autoload
631648
(define-derived-mode clojurescript-ts-mode clojure-ts-mode "ClojureScript[TS]"

0 commit comments

Comments
 (0)