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: Sat, 14 Oct 2023 21:20:34 -0700 Message-ID: References: <83a5slsjmh.fsf@gnu.org> <76FD5982-60CC-48D2-9823-C235CCEC2EEC@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000000718ea0607b99dc4" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12475"; 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 Sun Oct 15 06:21:57 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 1qrsdZ-00031A-3p for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Oct 2023 06:21:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrsdI-00071p-FP; Sun, 15 Oct 2023 00:21:40 -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 1qrsdG-00071h-V8 for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 00:21:38 -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 1qrsdG-0003rh-Kx for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 00:21:38 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qrsde-0002OG-Gs for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 00:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: nvp Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Oct 2023 04:22:02 +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.16973436789118 (code B ref 66431); Sun, 15 Oct 2023 04:22:02 +0000 Original-Received: (at 66431) by debbugs.gnu.org; 15 Oct 2023 04:21:18 +0000 Original-Received: from localhost ([127.0.0.1]:51063 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrscv-0002Mz-IB for submit@debbugs.gnu.org; Sun, 15 Oct 2023 00:21:18 -0400 Original-Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]:46212) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrsct-0002Mj-7G for 66431@debbugs.gnu.org; Sun, 15 Oct 2023 00:21:16 -0400 Original-Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-57f02eeabcaso2131095eaf.0 for <66431@debbugs.gnu.org>; Sat, 14 Oct 2023 21:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697343645; x=1697948445; 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=WMRHIxH0U6Hod3RQadnN4A/vcEgfdZ+o5NdSCEKHT2E=; b=HuOU0T8xr+TjI5s2hG6mjLNzdl42wm9PyiDWuOj5DuSMzTE8J2Py9TpAvNV7pg+Dqp TmDPX6OM+Bfzowvk0e7jOOXihUuc+H9ttp5v6nL5vz8exctYnTcPDLE6Dmm67fuOcAsL zNGloRfFVngGg3kDcSUrEcV5OkY3P5PeVbwZkz7VQ75w1mP3yN7VlA/lshoJ7Q2g+nyJ BlXsHkejjdZkE/+tQCabISiGJiCNbvEJRPNvr/O59HCPJ9nic7g5YiAb7JVBlgKipPjH i9G2FkBTLjwkgowrx/JUmljSFXCSscmiORs7r8q+iyfCFHu6effjZUaFvYvCNL7QtIyq xqkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697343645; x=1697948445; 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=WMRHIxH0U6Hod3RQadnN4A/vcEgfdZ+o5NdSCEKHT2E=; b=tQk6KWNImsGqnq5DZxosx3QhtWRHSIIHS1w64iQcDQOLqg3QyD2J+IR7n8rmjkm0uH jraLcwbs0urD+dgc3hvsUNn21I+2TbDFecqTCJlg95Q/jPogObPHWGNq9N84j7meNoHT qyHJwbz0+C16naNFJyCjsZ2KTWMz8ujeVU+phur8D57VLHsc0egWCFDfkJDtwjCfxNfk eYHNHPRoxdtkQrl8wNc16kF3XgNC31rl59CS3sGN55EPPVfRrdv918Tee+MfxxVFDrvr 03ziyLdzM5xBiwP+VWYqZmB3+BGPXkQjYpTWUkzZlphYDkGzRtz5+F89HZhVa+zDkblJ rZIw== X-Gm-Message-State: AOJu0Yzw5pzmixdcazGMrTEfdshorcrqpFcnU8Gv+BvHgkq7OXwz5zJk CzDEE9cjixnWonbp0d/5sY/jyWRN04foWsxkV0aqNnuo7S8= X-Google-Smtp-Source: AGHT+IHHrDEKyqnOZ6McVpU4aaR/85bD/k4G9VkQNlts2FVqUKk3LrvX3vp0gFO5/0m0ezi3M/hJnyc0g0crnjhbWu4= X-Received: by 2002:a05:6870:11cb:b0:1e9:c10e:401f with SMTP id 11-20020a05687011cb00b001e9c10e401fmr7374566oav.12.1697343645094; Sat, 14 Oct 2023 21:20:45 -0700 (PDT) In-Reply-To: <76FD5982-60CC-48D2-9823-C235CCEC2EEC@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:272481 Archived-At: --0000000000000718ea0607b99dc4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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-nod= e ;; 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. On Sat, Oct 14, 2023 at 10:08=E2=80=AFAM Yuan Fu wrote: > > > > On Oct 14, 2023, at 1:17 AM, Eli Zaretskii wrote: > > > >> From: nvp > >> Date: Mon, 9 Oct 2023 23:02:48 -0700 > >> > >> Tags: patch > >> > >> Bug: After `treesit-explorer-mode` is enabled in a buffer and its > >> associated `treesit--explorer-buffer` is killed, a subsequent call > >> to `treesit-explorer-mode` initially displays an empty explorer > >> buffer b/c `treesit--explorer-refresh` sees old value for > >> `treesit--explorer-last-node`. > >> > >> * lisp/treesit.el (treesit-explorer-mode): reset > >> `treesit--explorer-last-node` when `treesit--explorer-buffer` was kill= ed > >> > >> In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version > >> 3.24.33, cairo version 1.16.0) of 2023-10-05 built on noah-X580VD > >> Repository revision: 505c80623049d9e181918acdac8229c9a2041b1e > >> Repository branch: master > >> Windowing system distributor 'The X.Org Foundation', version > 11.0.12101004 > >> System Description: Ubuntu 22.04.3 LTS > > > > Yuan, could you please look into this? Is the patch OK to go in, and > > if so, should it be installed on emacs-29? > > I=E2=80=99ll look at it, thanks for the reminder. > > Yuan > > --0000000000000718ea0607b99dc4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,
The patch is supposed to reset `treesit--explorer-= last-node` in the source buffer, just before the `(with-current-buffer tree= sit--explorer-buffer ...)`.
Upon trying to reproduce it now, I re= alized it's harder to reproduce=C2=A0than I=C2=A0had thought -- sorry a= bout that.=C2=A0=C2=A0
I noticed the bug (if it is a bug) initial= ly when I was adding a function to jump b/w source and explorer buffers, li= ke the following:

(defun my-treesit-explorer-jump = ()
=C2=A0 "Pop b/w source and explorer buffers."
=C2=A0 (in= teractive)
=C2=A0 (let ((buf
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cond<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((eq major-mode 'treesit--explore= r-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=A0treesit--explorer-source-buffer))
=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 tree= sit-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 (buffer-live-p treesit--explorer-buffer))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; *** Without the reset he= re, the explorer buffer doesn't
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0;; get redrawn the first time, when treesit--explorer-last-nod= e
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; is non-nil i= n the source 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-function (function completing-re= ad))
=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(tree= sit-explore-mode 1)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0treesit--= explorer-buffer))))
=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 `cpp`.=C2=A0 Now= there should be an explorer buffer.
2. Kill the associated explo= rer buffer.
3. Now, back in the c++-ts-mode buffer, `treesit--exp= lorer-last-node` should still have a value.
4. From that c++-ts-m= ode buffer, call `my-treesit-explorer-jump`, and the explorer buffer should= be empty, until
switching back to the source buffer.
<= br>
This seems to me to be caused by `treesit--explorer-post-comm= and` not running until the source=C2=A0
buffer is active again.


On Sat, Oct 14, 2023 at 10:08=E2=80=AFAM Yuan Fu <casouri@gmail.com> wrote:


> On Oct 14, 2023, at 1:17 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: nvp <noah.v.peart@gmail.com>
>> Date: Mon, 9 Oct 2023 23:02:48 -0700
>>
>> Tags: patch
>>
>> Bug: After `treesit-explorer-mode` is enabled in a buffer and its<= br> >> associated `treesit--explorer-buffer` is killed, a subsequent call=
>> to `treesit-explorer-mode` initially displays an empty explorer >> buffer b/c `treesit--explorer-refresh` sees old value for
>> `treesit--explorer-last-node`.
>>
>> * lisp/treesit.el (treesit-explorer-mode): reset
>> `treesit--explorer-last-node` when `treesit--explorer-buffer` was = killed
>>
>> In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version >> 3.24.33, cairo version 1.16.0) of 2023-10-05 built on noah-X580VD<= br> >> Repository revision: 505c80623049d9e181918acdac8229c9a2041b1e
>> Repository branch: master
>> Windowing system distributor 'The X.Org Foundation', versi= on 11.0.12101004
>> System Description: Ubuntu 22.04.3 LTS
>
> Yuan, could you please look into this?=C2=A0 Is the patch OK to go in,= and
> if so, should it be installed on emacs-29?

I=E2=80=99ll look at it, thanks for the reminder.

Yuan

--0000000000000718ea0607b99dc4--