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: Mon, 27 Feb 2023 18:03:37 +0200 Message-ID: References: <842751FC-8D98-4DC9-9632-43F67BCC94AD@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2604"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Theodor Thornhill , 61617@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 27 17:05:24 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 1pWg0C-0000Rp-Qi for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 Feb 2023 17:05:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWfzu-0000Jt-4P; Mon, 27 Feb 2023 11:05:06 -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 1pWfzr-0000EZ-ET for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2023 11:05: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 1pWfzq-0007lw-Fd for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2023 11:05:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pWfzp-0004Dq-U5 for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2023 11:05:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Evgeni Kolev Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 27 Feb 2023 16:05:01 +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.167751385216157 (code B ref 61617); Mon, 27 Feb 2023 16:05:01 +0000 Original-Received: (at 61617) by debbugs.gnu.org; 27 Feb 2023 16:04:12 +0000 Original-Received: from localhost ([127.0.0.1]:48622 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWfz1-0004CX-LK for submit@debbugs.gnu.org; Mon, 27 Feb 2023 11:04:11 -0500 Original-Received: from mail-qt1-f172.google.com ([209.85.160.172]:37469) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWfyz-0004CE-KI for 61617@debbugs.gnu.org; Mon, 27 Feb 2023 11:04:10 -0500 Original-Received: by mail-qt1-f172.google.com with SMTP id r5so7182495qtp.4 for <61617@debbugs.gnu.org>; Mon, 27 Feb 2023 08:04:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=e3+EXwAhWFDE8HbL6urk8McnhjKmcX8IN3ytSESuQNE=; b=h/gDratS7PiCHWTgWkJXoN/lWBm7vf2tukwuhyf7F0VMD8dbXgi4FY8BHU2GsH7eOD 0BALiArvC0rwkNKxEi2nUEuKDFcScXKfHIR0PNy1IfoQQLHhez0haPfI1wAjQ9+pJYVj 5eSIw3gf+x+0KSpn0sbc4tXsii4ranj7Al9luZQ04sOKuhMBxhWOogwYAVoGbOZaJ4ZE qy1zKTPJF/Fnm88WkvwpG+jquuTWWzojjxTLNI5DC/Z/IjNM1idFl2D79qQZfZkppUEs x0tYZ4NV/2hyvRf6jkR2QBpeV1V9gPs+kD9us0YQizvVCWDIIKz9BIBH0BofTH+KR1Dv fL7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e3+EXwAhWFDE8HbL6urk8McnhjKmcX8IN3ytSESuQNE=; b=khFvcgwjZabuKSFY3iMEBIlsMXomNa+c2ribfxDTJ+dOeBYxQq7jf2gVRJRjWG3vK+ lT04gORaIxPi/WrP+PIZiEad2+6iVVfaGR6Ze44J4n2TWEhQIwzpOE7h/ufZUn8RCmr0 1GlN+EXIfWswlNp7FxTPMu+uPO//8YEtLzaxgqwsj6MvtdmiMs0abV8/YZG9wqtFKEfx QUMpVCQZ4CAMj3CDRCEZqhXFue81QBW8M3U/fwW2KzCkZxJpHLVodD6hWlBGzSS0/VUC 7kXOJxFoBe34tikmRw8Esy4Y0pAN+POBc/ipb6XNWh8lWgTC/QTtr6RRdP5KbKB9v27n UelA== X-Gm-Message-State: AO0yUKUGkiB7vvc0vVQl+Pb+W917lo+BB/viAzLY+Pv3MFqUVhjRB13u oRRtU/SPM0xWxTzAUccskh85AL2QAAX5Lu01tK0= X-Google-Smtp-Source: AK7set8tbzGfkJ3Ponq/pjBGv6/DZwEvUmnFMN7DMudokySY4WnSVD2a5n5q1KsLJ4TikqOOo7N8VzyinVCjagCsxUY= X-Received: by 2002:ac8:3e1a:0:b0:3bf:b826:a5e3 with SMTP id z26-20020ac83e1a000000b003bfb826a5e3mr2838940qtf.1.1677513843800; Mon, 27 Feb 2023 08:04:03 -0800 (PST) In-Reply-To: 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:256888 Archived-At: Great, thanks for the fix! I tested a few common (for me) scenarios and mark-defun works as expected! On Mon, Feb 27, 2023 at 11:24=E2=80=AFAM Yuan Fu wrote: > > > > > On Feb 26, 2023, at 4:42 PM, Yuan Fu wrote: > > > > > > > >> On Feb 24, 2023, at 11:27 PM, Evgeni Kolev wrote: > >> > >> On Sat, Feb 25, 2023 at 7:08 AM Yuan Fu wrote: > >> > >>> 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-mod= e. > >>> This seems intentional, because this is at the end of the definition = of > >>> mark-defun: > >>> > >>> (skip-chars-backward "[:space:]\n") > >>> (unless (bobp) > >>> (forward-line 1)) > >> > >> 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. > >> > >> 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 th= inking 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 worki= ng 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 ne= xt next defun. That was a design decision I made but I can see it causing o= ld functions to misbehave. > > > > Yuan > > The fix is brain-twisting but don=E2=80=99t embody a lot of code, yay! Th= is now should be fixed. > > Yuan