From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu 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, 26 Feb 2023 16:42:37 -0800 Message-ID: <842751FC-8D98-4DC9-9632-43F67BCC94AD@gmail.com> References: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33351"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Theodor Thornhill , 61617@debbugs.gnu.org To: Evgeni Kolev Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 27 01:43:21 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 1pWRbt-0008Yd-73 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 Feb 2023 01:43:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWRbg-0005Ed-Db; Sun, 26 Feb 2023 19:43:08 -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 1pWRba-0005EK-Ra for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 19:43:04 -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 1pWRba-00064R-Gk for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 19:43:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pWRba-0006ID-Cw for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 19:43:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 27 Feb 2023 00:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61617 X-GNU-PR-Package: emacs Original-Received: via spool by 61617-submit@debbugs.gnu.org id=B61617.167745857724173 (code B ref 61617); Mon, 27 Feb 2023 00:43:02 +0000 Original-Received: (at 61617) by debbugs.gnu.org; 27 Feb 2023 00:42:57 +0000 Original-Received: from localhost ([127.0.0.1]:45403 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWRbV-0006Ho-9v for submit@debbugs.gnu.org; Sun, 26 Feb 2023 19:42:57 -0500 Original-Received: from mail-pl1-f169.google.com ([209.85.214.169]:40662) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWRbT-0006Ha-I9 for 61617@debbugs.gnu.org; Sun, 26 Feb 2023 19:42:56 -0500 Original-Received: by mail-pl1-f169.google.com with SMTP id u5so1674537plq.7 for <61617@debbugs.gnu.org>; Sun, 26 Feb 2023 16:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7FVXrHgpZxmxlmViQLhG22u5PfYGhQuRc5pw2JYRI7Y=; b=TMRLjKI2vLWDpbTR15TLOaCvISqA/TzS4X10s1JKScejy2MfUODwhZvTsTeT28YRCZ Gw5Jk5scPDNvNrbqrQgYpNMwg7YogSWZzrtHjOl7pXlErkmOVFcfnW96AbtOVirBr10G 9q36jyebrgQ0jMLiNm3slZYGsQohQaGEI281eNU9bHBNrbS0mjWzMRpUm//szn6GKrXL ZsNnwRq6bbIMPFjkFF5kOR2bHpWnl+FqQI0H8wpHjD1j8Pf+oJPJ16Pkgar/X71rTKSC NdaD0qWZMSKhpcdUDU8Wul8tg1/hFxhNt4Og9aSzU4Im3ilLVjFwyJHHK9YoIthVq+Sr D/YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7FVXrHgpZxmxlmViQLhG22u5PfYGhQuRc5pw2JYRI7Y=; b=uIimDJ9Jf/E6YbqP68eFk/oB+8jhw0D9kW4fXzxfNc9W91p0NKinPw7cpKUoFUH0G7 fqNDan6dG3Of8+rU8qbplPOIu5NRUF/DoWYO1fdrxm5KP6Xf7JxhWlFYhJkJSV8EWuA2 qIaXEK76nyJBvkMuX1QSW3y8eh2Gs42uvJ5UE2M9fTgQvvmTgb20sTr6Vg6BsEXir3+E ebLs34PO5QcOMK/3lZNcw+oydjgfiEA06vt0tBamkAPEK9A1RE4N5QjqplYcGfMCYQ4J QOcj8TXrYraHJIovk6Pb39Gz0etTEVIcewvWR2r3aADW3b/EvWms2buWg1aaDo5ZknO3 J3bg== X-Gm-Message-State: AO0yUKVe1c0YGVO24P7+yC6qjXvTjjY7KrBc458UopBEdAq3lHJTO9Nj lyeTW0hNd+EV4A7qx1jzSU0= X-Google-Smtp-Source: AK7set8kQYcL18DA+kXEs0VgSXg/71QnEXGl04E7IoczkQK+wqCLrylliS4jr84dFT/NmfMUQuDhyg== X-Received: by 2002:a17:903:707:b0:19c:b7a9:d4a4 with SMTP id kk7-20020a170903070700b0019cb7a9d4a4mr13045832plb.37.1677458569690; Sun, 26 Feb 2023 16:42:49 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id a2-20020a170902ee8200b0019926c7757asm3170817pld.289.2023.02.26.16.42.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Feb 2023 16:42:49 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3731.400.51.1.1) 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:256841 Archived-At: > On Feb 24, 2023, at 11:27 PM, Evgeni Kolev wrote: >=20 > On Sat, Feb 25, 2023 at 7:08 AM Yuan Fu wrote: >=20 >> Huh, with or without comments, mark-defun always includes the empty >> lines before the defun for me. I get the same behavior in = rust-ts-mode. >> This seems intentional, because this is at the end of the definition = of >> mark-defun: >>=20 >> (skip-chars-backward "[:space:]\n") >> (unless (bobp) >> (forward-line 1)) >=20 > Did you check with my example or another example? With my example, the > issue I get is that only the empty lines are marked, without the > defun, without the comments. I'm attaching two screenshots - before > and after mark-defun. >=20 > Note: I get the correct behaviour when there is just one defun in the > file. But if there are more, or the defun at point is not at the top > of the file - mark-defun does not work as expected. Sorry, I used wrong go mode when testing your recipe. I used go-mode = thinking it is go-ts-mode :-( Using go-ts-mode, I can reproduce what you = see, yes. The problem you discovered revealed some shortcoming in our tree-sitter = navigation function, and requires quite a few non-trivial changes, I = working on fixing it. The direct cause is that (treesit-beginning-of-defun -1) is supposed to = go to the beginning of next defun, but instead goes to the beginning of = next next defun. That was a design decision I made but I can see it = causing old functions to misbehave.=20 Yuan=