GNU bug report logs - #66719
mark-defun doesn't like function literals / the need for treesit-mark-defun

Previous Next

Package: emacs;

Reported by: Dominik Honnef <dominik <at> honnef.co>

Date: Tue, 24 Oct 2023 01:03:02 UTC

Severity: normal

To reply to this bug, email your comments to 66719 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#66719; Package emacs. (Tue, 24 Oct 2023 01:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dominik Honnef <dominik <at> honnef.co>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 24 Oct 2023 01:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dominik Honnef <dominik <at> honnef.co>
To: bug-gnu-emacs <at> gnu.org
Subject: mark-defun doesn't like function literals / the need for
 treesit-mark-defun
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. 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66719; Package emacs. (Tue, 24 Oct 2023 10:58:01 GMT) Full text and rfc822 format available.

Message #8 received at 66719 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Dominik Honnef <dominik <at> honnef.co>
Cc: 66719 <at> debbugs.gnu.org
Subject: Re: bug#66719: mark-defun doesn't like function literals / the need
 for treesit-mark-defun
Date: Tue, 24 Oct 2023 13:56:39 +0300
> From: Dominik Honnef <dominik <at> 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.




This bug report was last modified 193 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.