From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dominik Honnef Newsgroups: gmane.emacs.bugs Subject: bug#66719: mark-defun doesn't like function literals / the need for treesit-mark-defun Date: Mon, 23 Oct 2023 22:59:35 +0200 Message-ID: <8734y1m4w8.fsf@honnef.co> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29236"; mail-complaints-to="usenet@ciao.gmane.io" To: 66719@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 24 03:02:50 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qv5on-0007Q4-F2 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Oct 2023 03:02:49 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv5oa-00036V-9z; Mon, 23 Oct 2023 21:02:36 -0400 Original-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 1qv5oX-000356-8t for bug-gnu-emacs@gnu.org; Mon, 23 Oct 2023 21:02:33 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qv5oW-0001za-WD for bug-gnu-emacs@gnu.org; Mon, 23 Oct 2023 21:02:33 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qv5p0-0005JW-7C for bug-gnu-emacs@gnu.org; Mon, 23 Oct 2023 21:03:02 -0400 X-Loop: help-debbugs@gnu.org 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-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169810932220332 (code B ref -1); Tue, 24 Oct 2023 01:03:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 24 Oct 2023 01:02:02 +0000 Original-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 Original-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 Original-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 Original-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 Original-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) Original-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) 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-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 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273070 Archived-At: 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.