From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: nvp Newsgroups: gmane.emacs.bugs Subject: bug#66431: [PATCH] Fix reset treesit--explorer-last-node when explorer buffer was killed Date: Fri, 20 Oct 2023 14:22:37 -0700 Message-ID: References: <83a5slsjmh.fsf@gnu.org> <76FD5982-60CC-48D2-9823-C235CCEC2EEC@gmail.com> <029D1797-AE78-4E45-BE25-0BEC8AF47321@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000006344f006082c7941" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21541"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 66431@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 20 23:23:53 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 1qtwyH-0005QA-2t for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Oct 2023 23:23:53 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtwy0-0003Eh-J1; Fri, 20 Oct 2023 17:23: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 1qtwxz-0003Ds-1J for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 17:23:35 -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 1qtwxy-0001MX-PJ for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 17:23:34 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qtwyP-0006gS-Q9 for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 17:24:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: nvp Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Oct 2023 21:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66431 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66431-submit@debbugs.gnu.org id=B66431.169783700625623 (code B ref 66431); Fri, 20 Oct 2023 21:24:01 +0000 Original-Received: (at 66431) by debbugs.gnu.org; 20 Oct 2023 21:23:26 +0000 Original-Received: from localhost ([127.0.0.1]:41766 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtwxp-0006fC-IX for submit@debbugs.gnu.org; Fri, 20 Oct 2023 17:23:26 -0400 Original-Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]:55609) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtwxl-0006ew-KR for 66431@debbugs.gnu.org; Fri, 20 Oct 2023 17:23:24 -0400 Original-Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6ce2fc858feso832536a34.3 for <66431@debbugs.gnu.org>; Fri, 20 Oct 2023 14:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697836968; x=1698441768; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=cFt6EgQsSVwo2T6r/dkqNpBd6ftXzAgbV2qOPv5Rais=; b=crszRBGY1UQtm/Nh0Op7Xkmgti+e2CsUxDRHZHvhOiZ9P6vWiasLfHRN0hRCEyKq/L myNog3BgAZpIXHqvp5XrdzDwtjXqO0Vt0C1QB9DVxbDxTzXxVu3KlGv/7C2b5krUAC5p FxISL/L8bU23juMjW7uH7pCzyOJKx6R/hnXbnmPT7041Se0acayaLnjMq3bHq3f7KLYe 7D5Pl1ik79d7blbs9j/t/3mML3zxc+JlSB0wkgCUmC7cx/OCoCA7jQfpTDivdNkqLrTe 274P4ChU3nL8D6vxklvemMz5gR/0JTp0rlB74umQoHaz53CZno1AfmyVD3X/oDRPs/xt Nsig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697836968; x=1698441768; h=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=cFt6EgQsSVwo2T6r/dkqNpBd6ftXzAgbV2qOPv5Rais=; b=gexpsAwteiw7TVkaVv5MLp7hQgS1hrqRZjdeu0FTfB8wIWkir0H7fQLgL/1AQbfC4d 4h4n+jjsFfw8mWgLUjxH65mCo7i8Jq6COb/T6ODaBHI1XdT/Nk8k8bsnJVa4xw7uk8dB h56SzJAw1/Lpp6Ou/yqbY4GnVrK05v20BAplEzblnWUu42uRojVFYKW2vPfhLwdAn0wi flgbPPFnbVH7OKluaLDhWJD+9eWSilIhiVZ8R3X0wnJfKQU3/xEUORICfGuQbz9LRHsx wnvE+0zUWIktiwFS9je7PgckHeM3I9eD+d/YALuMwreNzNNgVtv++la8/bdQNpmeOnBd yZ4g== X-Gm-Message-State: AOJu0YyRufWrYFTVRSqHNU4SPCOrBxcAhEOQFCocOwxbKJeLMR3963qE pnRpvbAcry6ogwBRv04i3+VIxx8hjMEUrAHDqN4= X-Google-Smtp-Source: AGHT+IEancAPK0uIQURCg7OVWp9uP6NPSp/vMmfjbr09zRWujUZm3KycTYw6Z40Tf60MLhRmmpTgg57MJu4xukWaTTM= X-Received: by 2002:a05:6870:8a27:b0:1e9:8a35:8635 with SMTP id p39-20020a0568708a2700b001e98a358635mr3645729oaq.21.1697836968394; Fri, 20 Oct 2023 14:22:48 -0700 (PDT) In-Reply-To: <029D1797-AE78-4E45-BE25-0BEC8AF47321@gmail.com> 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:272820 Archived-At: --0000000000006344f006082c7941 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable That fixes the problem! However, the reason I initially put the reset inside the `(unless (buffer-live-p treesit--explorer-buffer) ...)` in `treesit-explore-mode` was b/c it looked like there was an optimization happening in `treesit--explorer-refresh` where it does this check ;; If we didn't edit the buffer nor change the top-level ;; node, don't redraw the whole syntax tree. (highlight-only (treesit-node-eq top-level treesit--explorer-last-node)) I don't know if that is something you'd want to keep, but just pointing it out in case. I think the initial patch works as well, but still allows that check to work when the explorer buffer hasn't been killed. Thankyou! On Wed, Oct 18, 2023 at 9:36=E2=80=AFPM Yuan Fu wrote: > > > > On Oct 14, 2023, at 9:20 PM, nvp wrote: > > > > Hi, > > The patch is supposed to reset `treesit--explorer-last-node` in the > source buffer, just before the `(with-current-buffer > treesit--explorer-buffer ...)`. > > Upon trying to reproduce it now, I realized it's harder to reproduce > than I had thought -- sorry about that. > > I noticed the bug (if it is a bug) initially when I was adding a > function to jump b/w source and explorer buffers, like the following: > > > > (defun my-treesit-explorer-jump () > > "Pop b/w source and explorer buffers." > > (interactive) > > (let ((buf > > (cond > > ((eq major-mode 'treesit--explorer-tree-mode) > > (when (buffer-live-p treesit--explorer-source-buffer) > > treesit--explorer-source-buffer)) > > (t > > (unless (and treesit-explore-mode > > (buffer-live-p treesit--explorer-buffer)) > > ;; *** Without the reset here, the explorer buffer doesn't > > ;; get redrawn the first time, when > treesit--explorer-last-node > > ;; is non-nil in the source buffer *** > > ;; (setq-local treesit--explorer-last-node nil) > > (cl-letf (((symbol-function (function completing-read)) > > (lambda (&rest _) (symbol-name > (treesit-language-at (point)))))) > > (treesit-explore-mode 1))) > > treesit--explorer-buffer)))) > > (pop-to-buffer buf))) > > > > Let me give a more precise recipe to reproduce: > > 1. From a c++-ts-mode buffer, call `treesit-explorer-mode`, select > `cpp`. Now there should be an explorer buffer. > > 2. Kill the associated explorer buffer. > > 3. Now, back in the c++-ts-mode buffer, `treesit--explorer-last-node` > should still have a value. > > 4. From that c++-ts-mode buffer, call `my-treesit-explorer-jump`, and > the explorer buffer should be empty, until > > switching back to the source buffer. > > > > This seems to me to be caused by `treesit--explorer-post-command` not > running until the source > > buffer is active again. > > Thank you, I think I see the problem now. Could you try the below patch > and see it fixes your problem? Also, sorry for the late reply, I meant to > reply sooner but couldn=E2=80=99t find the time to figure out what exact = was the > cause :-) I was initially a bit confused since we already do set last-nod= e > to nil. > > Yuan > > > > --0000000000006344f006082c7941 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
That fixes the problem!

However, the re= ason I initially put the reset inside the `(unless (buffer-live-p treesit--= explorer-buffer) ...)`
in `treesit-explore-mode` was b/c it looke= d like there was an optimization happening in=C2=A0
`treesit--exp= lorer-refresh` where it does this check=C2=A0

=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; If we didn't edit the buffer n= or change the top-level
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; node= , don't redraw the whole syntax tree.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(highlight-only (treesit-node-eq
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t= op-level treesit--explorer-last-node))

I don&#= 39;t know if that is something you'd want to keep, but just pointing it= out in case.=C2=A0 I think
the initial patch works as well, but = still allows that check to work when the explorer buffer=C2=A0hasn't=C2= =A0
been killed.

Thankyou!
On Wed, = Oct 18, 2023 at 9:36=E2=80=AFPM Yuan Fu <casouri@gmail.com> wrote:


> On Oct 14, 2023, at 9:20 PM, nvp <noah.v.peart@gmail.com> wrote:
>
> Hi,
> The patch is supposed to reset `treesit--explorer-last-node` in the so= urce buffer, just before the `(with-current-buffer treesit--explorer-buffer= ...)`.
> Upon trying to reproduce it now, I realized it's harder to reprodu= ce than I had thought -- sorry about that.=C2=A0
> I noticed the bug (if it is a bug) initially when I was adding a funct= ion to jump b/w source and explorer buffers, like the following:
>
> (defun my-treesit-explorer-jump ()
>=C2=A0 =C2=A0"Pop b/w source and explorer buffers."
>=C2=A0 =C2=A0(interactive)
>=C2=A0 =C2=A0(let ((buf
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cond
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0((eq major-mode 'treesit--= explorer-tree-mode)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (buffer-live-p treesit-= -explorer-source-buffer)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 treesit--explorer-sour= ce-buffer))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(t
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (unless (and treesit-explore-= mode
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(buffer-live-p treesit--explorer-buffer))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; *** Without the res= et here, the explorer buffer doesn't
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; get redrawn the fir= st time, when treesit--explorer-last-node
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; is non-nil in the s= ource buffer ***
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; (setq-local treesit= --explorer-last-node nil)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cl-letf (((symbol-fun= ction (function completing-read))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(lambda (&rest _) (symbol-name (treesit-language-at= (point))))))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (treesit-explor= e-mode 1)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 treesit--explorer-buffer))))<= br> >=C2=A0 =C2=A0 =C2=A0(pop-to-buffer buf)))
>
> Let me give a more precise recipe to reproduce:
> 1. From a c++-ts-mode buffer, call `treesit-explorer-mode`, select `cp= p`.=C2=A0 Now there should be an explorer buffer.
> 2. Kill the associated explorer buffer.
> 3. Now, back in the c++-ts-mode buffer, `treesit--explorer-last-node` = should still have a value.
> 4. From that c++-ts-mode buffer, call `my-treesit-explorer-jump`, and = the explorer buffer should be empty, until
> switching back to the source buffer.
>
> This seems to me to be caused by `treesit--explorer-post-command` not = running until the source
> buffer is active again.

Thank you, I think I see the problem now. Could you try the below patch and= see it fixes your problem? Also, sorry for the late reply, I meant to repl= y sooner but couldn=E2=80=99t find the time to figure out what exact was th= e cause :-) I was initially a bit confused since we already do set last-nod= e to nil.

Yuan



--0000000000006344f006082c7941--