From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Evgeni Kolev Newsgroups: gmane.emacs.bugs Subject: bug#61617: M-x mark-defun doesn't work correctly in tree-sitter modes when comments exist between functions Date: Sun, 19 Feb 2023 10:39:07 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18949"; mail-complaints-to="usenet@ciao.gmane.io" To: 61617@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 19 09:40:19 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 1pTfF4-0004kV-01 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Feb 2023 09:40:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTfEq-0007O3-Lj; Sun, 19 Feb 2023 03:40:04 -0500 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 1pTfEp-0007Nu-I8 for bug-gnu-emacs@gnu.org; Sun, 19 Feb 2023 03:40:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTfEp-00022L-8f for bug-gnu-emacs@gnu.org; Sun, 19 Feb 2023 03:40:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pTfEo-0004Q9-5A for bug-gnu-emacs@gnu.org; Sun, 19 Feb 2023 03:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Evgeni Kolev Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 Feb 2023 08:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 61617 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.167679597816905 (code B ref -1); Sun, 19 Feb 2023 08:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Feb 2023 08:39:38 +0000 Original-Received: from localhost ([127.0.0.1]:45640 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pTfEQ-0004Ob-EV for submit@debbugs.gnu.org; Sun, 19 Feb 2023 03:39:38 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:59542) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pTfEO-0004OT-EN for submit@debbugs.gnu.org; Sun, 19 Feb 2023 03:39:37 -0500 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 1pTfEO-0007Me-8M for bug-gnu-emacs@gnu.org; Sun, 19 Feb 2023 03:39:36 -0500 Original-Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTfEM-0001zI-R1 for bug-gnu-emacs@gnu.org; Sun, 19 Feb 2023 03:39:35 -0500 Original-Received: by mail-qv1-xf2f.google.com with SMTP id nf8so319320qvb.2 for ; Sun, 19 Feb 2023 00:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1676795973; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=SAMVjMV4iDv+bw/ClQxSC8ni2+xJb0x/AX7dL+pbLkI=; b=mCNOB5f8BXglI3rhs8T+VsbXrrqYCtrj+YOUt5CmOIEZerEMlh9kjnJy9xsQn6Qpnu d0MxHjGo7VTve4eRGlkkQgkbdIQVG+wDCWeO08ydVyzuHvWx8YSYPV3KhUEfLvIS/HIq /OgMxQepq2T5IFdHi+GA+dKdN/ljI1YTK5Mw5otvJb52GNM5AE6eIwbz7me7F/c0O4tR hviS7hL8JwSqQNSSAq0qrF5qm6qdAuwmTOdWbxR937qPXXCrbYJ8rebmMIy3t1rpZ2wQ fXmhGPvHoNcBuL+pj4V0rwFGzzQPdo1qEoYGXHohjxrl495AuOKA8lQdmWQ2FDz2tH7i mUCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676795973; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SAMVjMV4iDv+bw/ClQxSC8ni2+xJb0x/AX7dL+pbLkI=; b=HQp3z4AIgd+9QF2HBqjuUl+YFti9QArFih6wRwB6IXe2g/XS0OYDH7bB6OPFf5UuC1 NrgxycN94S+q7rq2VIswr3TWKroSTuE2Mmzn3ThvHqLCYbG0c/ZxKO2E6rqhM7SU1vW6 SQ/DaddYLCP0W5iRNVKTVRztIMPfSx/t7uh333j0+NJHGu7cNreXiZzy6aGn9DJJaZWe pnEKs/LzqBOkpeiTRKpCwLAYPTOBK7ycB8LZkWCy7SmYe9p7Yb8ckH2hfQGvDq7ZrNX7 5jpN9lL1cOeWvxdBS9IQW1ZNSGL+uYnqFRuPETQelVqRoD0rkwiLVaylZ/TLnC4vrgIN dBew== X-Gm-Message-State: AO0yUKXxfo/AOf3wYtAwbPOgFM0IVpHB1E67ldbIHCj6zpPOg25KKM3X yU0G+PxX/tjBIhRbYBgzDUklaJHSfsnJUh8sm0JgJEQv4aTuFQ== X-Google-Smtp-Source: AK7set+ONQZJmpdT6MaOwAkuqujET0wtBDaafBuAt45fSQou/dqUDEH7vKqHZf6FircKt4AkVcdFMdT2CxHCFzVsndM= X-Received: by 2002:a0c:dd8d:0:b0:56e:bb64:9907 with SMTP id v13-20020a0cdd8d000000b0056ebb649907mr473498qvk.61.1676795973653; Sun, 19 Feb 2023 00:39:33 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2f; envelope-from=evgenysw@gmail.com; helo=mail-qv1-xf2f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:256037 Archived-At: M-x mark-defun doesn't work correctly when the function at point is preceded by a comment. I've noticed this bug in go-ts-mode, and have also checked it's reproduced in rust-ts-mode: To reproduce: 1. with the following code in go-ts-mode, "|" is the point (in function sum2) ``` package main func sum(a, b int) int { return a + b } // comment func sum2(a, b int) int { Ireturn a + b } ``` 2. Execute M-x mark-defun 3. The region selected is wrong - the empty line between the two functions is marked. I expect only function sum2 and the preceding comment to be marked. Observations: - The issue is reproducible with a fresh build of master, and reproducible with emacs -Q. - The issue is also reproducible in rust-ts-mode which makes me think the root cause is in treesit code (treesit.el maybe). - From what I've checked, (beginning-of-defun-comments) works correctly, but (end-of-defun) doesn't. These two (and other) functions are used by mark-defun. - The issue does not exist when the function is not preceded by a comment. In other words - the issue is not reproduced when no comments exist between the functions. Below is a Rust example which reproduces the issue, again "|" is the point (in function main2). Steps to reproduce are identical to the steps for go-ts-mode: ``` fn main() { println!("Hello World!"); } // comment fn main2() { |println!("Hello World!"); } ```