Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define list thing to improve navigation in Emacs 31 #65

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## main (unreleased)

- [[#62](https://github.com/clojure-emacs/clojure-ts-mode/issues/62)]: Define `list` "thing" to improve navigation in Emacs 31.

## 0.2.3 (2025-03-04)

- [#38]: Add support for `in-ns` forms in `clojure-ts-find-ns`.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ Here are some notable examples:

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

## Frequently Asked Questions

Expand Down
13 changes: 10 additions & 3 deletions clojure-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,16 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
"unquote_splicing_lit" "unquoting_lit")
"A regular expression that matches nodes that can be treated as s-expressions.")

(defconst clojure-ts--list-nodes
'("list_lit" "anon_fn_lit" "read_cond_lit" "splicing_read_cond_lit"
"map_lit" "ns_map_lit" "vec_lit" "set_lit")
"A regular expression that matches nodes that can be treated as lists.")

(defconst clojure-ts--thing-settings
`((clojure
(sexp ,(regexp-opt clojure-ts--sexp-nodes)
text ,(regexp-opt '("comment"))))))
(sexp ,(regexp-opt clojure-ts--sexp-nodes))
(list ,(regexp-opt clojure-ts--list-nodes))
(text ,(regexp-opt '("comment"))))))

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

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