We tried that initially, but end-of-defun doesn’t have the notion of nested
defuns, which leads to problems when end-of-defun-function recognizes nested
defuns. In the following code
(defun xxx ()
|
(defun yyy () ...)
(defun zzz () ...)
)
If point is at “|” and you call end-of-defun, you’d expect point to move to the
end of yyy, but instead it moves to the end of xxx. That’s because end-of-defun
first runs (beginning-of-defun -1) followed by (end-of-defun 1) to check if the
starting point is in a defun or between two defuns. This is fine in non-nested
defuns, but in this example, the point first goes to the beginning of xxx, then
goes to the end of xxx. And end-of-defun thinks that we started in a defun and
now is at an end of defun, job’s done, and finishes.
The plan is to improve end-of-defun to support nested defuns in Emacs 30. For
now we rebind end-of-defun to treesit-end-of-defun.