Open
Description
Expected behavior
When standing at the beginning of a form that is the last one in the buffer and pressing C-k
(which is bound to paredit-kill
when Paredit is enabled), the form should be killed like any other form.
Actual behavior
Emacs freezes and spins CPU at 100%. Pressing C-g
gets it out of this, but the form still remains.
Steps to reproduce the problem
Go to any Clojure file, enable Paredit, perform paredit-kill
on the last form, e.g.:

Environment & Version information
- MacOS Sequioia 15.3.2
- Emacs 30.1.50 (built from https://github.com/jdtsmith/emacs-mac)
- Latest clojure-ts-mode from unstable MELPA
clojure-ts-mode version
clojure-ts-mode 0.4.0-snapshot (package: 20250415.804)
tree-sitter-clojure grammar version
Not sure.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
rrudakov commentedon Apr 15, 2025
Looks like a Emacs bug (or paredit bug).
it's only reproducible if there are one or more empty lines after the last expression. In normal
clojure-mode
whenforward-sexp
is called, the job is delegated toforward-sexp-default-function
, which moves point to the end of the buffer if point is currently after the last sexp:In
clojure-ts-mode
the job is done bytreesit-forward-sexp
, which doesn't move point to the end of the buffer, but keep it after the last closing paren of the last sexp.When
paredit-kill
is called, at some point the functionparedit-forward-sexps-to-kill
callsforward-sexp
until it reaches the end of the buffer:I'm not sure on which level this issue should be fixed, ideally
treesit-forward-sexp
should be fully compatible withforward-sexp-default-function
, so maybe we should report it to Emacs bug tracker, I doubt though, that the fix will be installed to Emacs-30.bbatsov commentedon Apr 15, 2025
Yeah, I think this is an Emacs bug. Those are still quite common, when it comes to TreeSitter unfortunately.
rrudakov commentedon Apr 16, 2025
I've just checked, and it's not reproducible on the latest Emacs master. We use correct
treesit-things-settings
inclojure-ts-mode
andforward-sexp-function
is set toforward-sexp-list
, which behaves in a compatible way withforward-sexp-default-function
.I was planning to report this to Emacs bug tracker, but now it's not necessary.
bbatsov commentedon Apr 16, 2025
@rrudakov Let's just add a note about this in the Caveats then.
rrudakov commentedon Apr 16, 2025
OK, will do. I tried to come up with some advice function to fix it for Emacs-30, but I couldn't do it quickly.
rrudakov commentedon Apr 16, 2025
@alexander-yakushev could you please try to add this to your init file and check if it solves the issue?