Open
Description
In regular clojure-mode
, calling the commands up-list
and backward-up-list
in a position without an enclosing form results in a no-op, raising a user error
At top level
E.g. with point at :here
in the following, press C-M-u
(backward-up-list) / M-x up-list
repeatedly to move out of successive forms.
(first "expression")
(:you {:are [:here]})
(last "expression")
Upon reaching the top level (beginning/end of line), the expected behavior is for the point to remain stationary (and a user error to be thrown)
In clojure-ts-mode
, this results instead in the point moving all the way to the beginning or end of the buffer, which can be quite disconcerting.
Additional note: This affects various navigation commands in other packages like Paredit and Lispy, which ultimately delegate to (backward)-up-list.
Activity
rrudakov commentedon Mar 6, 2025
It looks like an Emacs bug.
In
treesit.el
intreesit-major-mode-setup
it sets customforward-sexp-function
:which in turn triggers a branch in
up-list-default-function
https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/lisp.el#n292Looks like this code just calls this
treesit-forward-sexp
until it reaches the end/beginning of the buffer.I think it should be reported to Emacs' bug tracker.
rrudakov commentedon Mar 6, 2025
I've found a solution. We should set custom
up-list-function
duringclojure-ts-mode
setup:This fixes the problem.
rrudakov commentedon Mar 6, 2025
We might also consider setting the following to improve user experience:
yuhan0 commentedon Mar 6, 2025
Hmm, it seems like the functions you've linked to haven't been merged into a release branch of Emacs - I'm on the latest 30.1 release and there's no sign of a
up-list-function
. Git-blaming points to the following commits and bug report:https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=ec8dd27f008bca810209354a189d241479fe4d32
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=687ff86e802c9883f292f58a890178d08311a821
https://lists.gnu.org/archive/html/bug-gnu-emacs/2024-09/msg01410.html
I wonder if this hasn't already been solved on the latest master branch - @rrudakov are you running Emacs directly off HEAD?
bbatsov commentedon Mar 6, 2025
Yeah, I was about to say that's the first time I hear of those functions.
rrudakov commentedon Mar 6, 2025
Ah, sorry, indeed, I'm on master :)
yuhan0 commentedon Mar 6, 2025
In any case it appears that (the master branch version of) treesit.el already performs the above duties of setting
up-list-function
etc. as long as somelist
thing is definedhttps://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/treesit.el#n4232
rrudakov commentedon Mar 6, 2025
Yes, but
list
thing is not defined for clojure-ts-mode, onlysexp
andtext
, so it should either be defined explicitly, or we should setup-list-function
ourselves.yuhan0 commentedon Mar 6, 2025
Yeah, I don't know enough about treesitter integration to judge which approach is better, and also if we should be making changes against 'unreleased' APIs in the first place?
I'd vote to close this issue for now and revisit it when
up-list-function
etc. actually gets introduced.bbatsov commentedon Mar 6, 2025
Let's keep the issue open and investigate options. I've been spending more time playing with TreeSitter lately (even wrote a simple TS mode for OCaml https://github.com/bbatsov/neocaml) and I plan to double down on
clojure-ts-mode
this year.rrudakov commentedon Mar 6, 2025
Probably the issue still could be reported to Emacs' bug tracker? There is a chance that it could be fixed in version 30.2.
rrudakov commentedon Mar 6, 2025
I guess we could try setting
forward-sexp-function
tonil
to fallback to the original behavior ofup-list
.bbatsov commentedon Mar 6, 2025
@rrudakov Yeah, I think we can't go wrong to report this. Would you mind doing this?
10 remaining items