From unknown Tue Jun 24 05:14:33 2025 X-Loop: help-debbugs@gnu.org Subject: bug#66719: mark-defun doesn't like function literals / the need for treesit-mark-defun Resent-From: Dominik Honnef Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Oct 2023 01:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66719 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 66719@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.169810932220332 (code B ref -1); Tue, 24 Oct 2023 01:03:02 +0000 Received: (at submit) by debbugs.gnu.org; 24 Oct 2023 01:02:02 +0000 Received: from localhost ([127.0.0.1]:52592 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qv5o1-0005Hf-Q0 for submit@debbugs.gnu.org; Mon, 23 Oct 2023 21:02:02 -0400 Received: from lists.gnu.org ([2001:470:142::17]:46846) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qv225-0001Wc-Cu for submit@debbugs.gnu.org; Mon, 23 Oct 2023 17:00:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qv21W-0002lK-NE for bug-gnu-emacs@gnu.org; Mon, 23 Oct 2023 16:59:42 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qv21V-0005eO-12 for bug-gnu-emacs@gnu.org; Mon, 23 Oct 2023 16:59:42 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-313e742a787so2146597f8f.1 for ; Mon, 23 Oct 2023 13:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=honnef-co.20230601.gappssmtp.com; s=20230601; t=1698094778; x=1698699578; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=xCxHsUmDvi0i2XxWPciQlDiMKklfpOqrL0lTyw5guFI=; b=Y5Ji7uABte69vjtLaQQyZo1egycz9OCCoVURTJXn/xGczVnfCxRA0MeCNKv3tA/wB5 neMy4OcRQfpHXgQvbCCJgHz1UIGVV56Tcm1SZMSYgdXQzQH5nQGsJOaPOQg1qMiBlw5/ bCjbLKEdZQadZd4WT801AMglUZO5p0sFXfUYPw6ZN41g+rwDDFUw9iiJM/WZXqVT9AHj YPezZjpj7l6XuLgSebEGNi4FfrGKSvH9TmRgoLV4CsmNWJli1lxXcr+fsylyvENV6Pt5 9CD/pdBC4DLIWKAEmsxf5ukLOKcqbAcjttMRSVNk82zM7ledzjHt/mnrxvX6dYWVuGSk nBWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698094778; x=1698699578; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xCxHsUmDvi0i2XxWPciQlDiMKklfpOqrL0lTyw5guFI=; b=uhlXeaLvAU9wtcCB0M16Hox56GYc0EeS2wygzjbu8TnrjxY3mTtWbmajwSt7RT1wGH UtoyzhnNQbGFayuwLhgnEWduqMzv1B9t6ML+sD9j1aEAKP4rm35Gr8lFXHWOUa9Bpa8X GdD/B6dCM1ouVQoA49rk9pgRgVPAZRI1JJzcozdD40D5jW7QUJUVWgX9B7omUKbu/iPz rqQsOl+17npwfrwuYyaxqrSrrkQ4xH2+dDHVysRsCIkigbnezWFADmX8Bjx7eaUZ7hw8 2RjHlN4S1xXXpJsfDShWiO1oqBjxSQcjmT2MaSX0/1bWnYwkwkUFOb/sTxxWxODhLqH4 xpCQ== X-Gm-Message-State: AOJu0Yyt+14M/CVUrZeQToSotvYaNO2L5o8POrAtuvySPqioh3jWFMIN onXOgTsK6NSLHW9YZYxVZH44zfU767K4/JFABTk= X-Google-Smtp-Source: AGHT+IHZDsf6gg2mh272RKWi8JyCmiGVUled9Sqmk6UeS2JlmuVUGhYAX0oRx/pg+Dm1wreJ8Vb8pQ== X-Received: by 2002:adf:9cc6:0:b0:31f:f8a7:a26c with SMTP id h6-20020adf9cc6000000b0031ff8a7a26cmr11019321wre.25.1698094777778; Mon, 23 Oct 2023 13:59:37 -0700 (PDT) Received: from localhost (ip-176-199-155-051.um44.pools.vodafone-ip.de. [176.199.155.51]) by smtp.gmail.com with ESMTPSA id x17-20020a5d60d1000000b0032d8f075810sm8542306wrt.10.2023.10.23.13.59.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 13:59:36 -0700 (PDT) From: Dominik Honnef Date: Mon, 23 Oct 2023 22:59:35 +0200 Message-ID: <8734y1m4w8.fsf@honnef.co> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: none client-ip=2a00:1450:4864:20::436; envelope-from=dominik@honnef.co; helo=mail-wr1-x436.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.0 (/) X-Mailman-Approved-At: Mon, 23 Oct 2023 21:02:01 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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. From unknown Tue Jun 24 05:14:33 2025 X-Loop: help-debbugs@gnu.org Subject: bug#66719: mark-defun doesn't like function literals / the need for treesit-mark-defun Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Oct 2023 10:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66719 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Dominik Honnef Cc: 66719@debbugs.gnu.org Received: via spool by 66719-submit@debbugs.gnu.org id=B66719.169814503617333 (code B ref 66719); Tue, 24 Oct 2023 10:58:01 +0000 Received: (at 66719) by debbugs.gnu.org; 24 Oct 2023 10:57:16 +0000 Received: from localhost ([127.0.0.1]:53266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qvF62-0004VU-Sf for submit@debbugs.gnu.org; Tue, 24 Oct 2023 06:57:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51500) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qvF5z-0004VF-47 for 66719@debbugs.gnu.org; Tue, 24 Oct 2023 06:57:13 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvF5P-0002ua-2C; Tue, 24 Oct 2023 06:56:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=sxJz4vZwTaQYrPribntwirAIvr2LzzjVkZ9E2dqtSaM=; b=NXZYG+ig0ytK HFis18BM4MOXwsUQwLw1OiID4BxYX/HBDx0POOoKP1apxUfW1eF2BRtMfx9SyxGkcf5C4qRG0aiWs xPi5UxJH2EDb/qrMbhAp6X66ZJ99seAHN8kehGod5240y6ukJtmwvRM7OUsZlpqip2MGgRn4cTHj+ iLHmQykcXjUnONG5T1m/jn+gNtGF8tmTsENUQho4EcIiC+qdmyFGIJI2nLoIwhi81lGTxMHGKzJcE x/ddRWG9LKiqo57gQRO9vM+sggALgnVmcH+e/UTsrJBoxC0D6g+d5Qb/+FfAG85F2uqdwCGxX8C7L RdxNklx4lGSJLkzZRgjoGA==; Date: Tue, 24 Oct 2023 13:56:39 +0300 Message-Id: <83lebsmgpk.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <8734y1m4w8.fsf@honnef.co> (message from Dominik Honnef on Mon, 23 Oct 2023 22:59:35 +0200) References: <8734y1m4w8.fsf@honnef.co> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Dominik Honnef > 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.