Skip to content

Commit 51ee8a4

Browse files
rrudakovbbatsov
authored andcommitted
[#62] Define list thing to improve navigation in Emacs 31
If list thing is defined, Emacs 31 will set a few options automatically to improve navigation by lists/sexp etc. Big thanks for the patch to Juri Linkov <[email protected]>.
1 parent e0703ff commit 51ee8a4

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## main (unreleased)
44

5+
- [[#62](https://github.com/clojure-emacs/clojure-ts-mode/issues/62)]: Define `list` "thing" to improve navigation in Emacs 31.
6+
57
## 0.2.3 (2025-03-04)
68

79
- [#38]: Add support for `in-ns` forms in `clojure-ts-find-ns`.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ Here are some notable examples:
231231

232232
- On Emacs 29 the parent mode is `prog-mode`, but on Emacs 30+ it's both `prog-mode`
233233
and `clojure-mode` (this is very helpful when dealing with `derived-mode-p` checks)
234+
- Navigation by sexp/lists might work differently on Emacs versions lower
235+
than 31. Starting with version 31, Emacs uses TreeSitter 'things' settings, if
236+
available, to rebind some commands.
234237

235238
## Frequently Asked Questions
236239

clojure-ts-mode.el

+10-3
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,16 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
918918
"unquote_splicing_lit" "unquoting_lit")
919919
"A regular expression that matches nodes that can be treated as s-expressions.")
920920

921+
(defconst clojure-ts--list-nodes
922+
'("list_lit" "anon_fn_lit" "read_cond_lit" "splicing_read_cond_lit"
923+
"map_lit" "ns_map_lit" "vec_lit" "set_lit")
924+
"A regular expression that matches nodes that can be treated as lists.")
925+
921926
(defconst clojure-ts--thing-settings
922927
`((clojure
923-
(sexp ,(regexp-opt clojure-ts--sexp-nodes)
924-
text ,(regexp-opt '("comment"))))))
928+
(sexp ,(regexp-opt clojure-ts--sexp-nodes))
929+
(list ,(regexp-opt clojure-ts--list-nodes))
930+
(text ,(regexp-opt '("comment"))))))
925931

926932
(defvar clojure-ts-mode-map
927933
(let ((map (make-sparse-keymap)))
@@ -1043,7 +1049,8 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE."
10431049
;; Workaround for treesit-transpose-sexps not correctly working with
10441050
;; treesit-thing-settings on Emacs 30.
10451051
;; Once treesit-transpose-sexps it working again this can be removed
1046-
(when (fboundp 'transpose-sexps-default-function)
1052+
(when (and (fboundp 'transpose-sexps-default-function)
1053+
(< emacs-major-version 31))
10471054
(setq-local transpose-sexps-function #'transpose-sexps-default-function)))))
10481055

10491056
;; For Emacs 30+, so that `clojure-ts-mode' is treated as deriving from

0 commit comments

Comments
 (0)