unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#66719: mark-defun doesn't like function literals / the need for treesit-mark-defun
@ 2023-10-23 20:59 Dominik Honnef
  2023-10-24 10:56 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Honnef @ 2023-10-23 20:59 UTC (permalink / raw)
  To: 66719

treesit.el currently defines treesit-beginning-of-defun and
treesit-end-of-defun, and binds C-M-a and C-M-e to them in addition to
setting beginning-of-defun-function and end-of-defun-function.

That way, C-M-a and C-M-e work well even for function literals, which do
not necessarily start and end on their own, dedicated lines. This
differs from beginning-of-defun, which always goes to the beginning
of the line.

The problem is that there is no treesit-mark-defun, and mark-defun calls
beginning-of-defun, via beginning-of-defun-comments. Thus, mark-defun
will mark more than the actual function literal. For example, in Go,
given

    // some comment
    someCall(func() {
        ...
    })

and a major mode that sets

    (setq-local treesit-defun-type-regexp (rx (or "function_declaration" "func_literal")))
    (setq-local end-of-defun-moves-to-eol nil)

mark-defun will also mark the call to someCall, and the comment above
it, while it should only mark the function literal.

Adding treesit-mark-defun would be a quick fix for the interactive use
case. However, this problem probably affects other functions that call
beginning-of-defun, or ones that build on top of mark-defun. I am not
sure how to address that, considering moving to the beginning of the
line is part of the contract of beginning-of-defun.





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#66719: mark-defun doesn't like function literals / the need for treesit-mark-defun
  2023-10-23 20:59 bug#66719: mark-defun doesn't like function literals / the need for treesit-mark-defun Dominik Honnef
@ 2023-10-24 10:56 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2023-10-24 10:56 UTC (permalink / raw)
  To: Dominik Honnef; +Cc: 66719

> From: Dominik Honnef <dominik@honnef.co>
> Date: Mon, 23 Oct 2023 22:59:35 +0200
> 
> treesit.el currently defines treesit-beginning-of-defun and
> treesit-end-of-defun, and binds C-M-a and C-M-e to them in addition to
> setting beginning-of-defun-function and end-of-defun-function.
> 
> That way, C-M-a and C-M-e work well even for function literals, which do
> not necessarily start and end on their own, dedicated lines. This
> differs from beginning-of-defun, which always goes to the beginning
> of the line.
> 
> The problem is that there is no treesit-mark-defun, and mark-defun calls
> beginning-of-defun, via beginning-of-defun-comments.

mark-defun is defined for Lisp and Lisp-like languages, it is not a
function that's supposed to support any major mode.  If we want a
PL-independent mark-defun function, we need first to refactor
mark-defun to allow mode-specific behavior.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-24 10:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23 20:59 bug#66719: mark-defun doesn't like function literals / the need for treesit-mark-defun Dominik Honnef
2023-10-24 10:56 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).