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#66431: [PATCH] Fix reset treesit--explorer-last-node when explorer buffer was killed Date: Wed, 18 Oct 2023 21:35:48 -0700 Message-ID: <029D1797-AE78-4E45-BE25-0BEC8AF47321@gmail.com> References: <83a5slsjmh.fsf@gnu.org> <76FD5982-60CC-48D2-9823-C235CCEC2EEC@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_A2C4F754-EF7D-4669-BF1B-A2B65D6F47F0" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31323"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 66431@debbugs.gnu.org To: nvp Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 19 06:36: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 1qtKmG-0007zI-Py for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 19 Oct 2023 06:36:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtKlx-0005Ex-Vg; Thu, 19 Oct 2023 00:36:37 -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 1qtKlw-0005Eh-H6 for bug-gnu-emacs@gnu.org; Thu, 19 Oct 2023 00:36:36 -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 1qtKlv-0005l9-SF for bug-gnu-emacs@gnu.org; Thu, 19 Oct 2023 00:36:36 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qtKmM-00069z-6d for bug-gnu-emacs@gnu.org; Thu, 19 Oct 2023 00:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Oct 2023 04:37: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.169769019523634 (code B ref 66431); Thu, 19 Oct 2023 04:37:02 +0000 Original-Received: (at 66431) by debbugs.gnu.org; 19 Oct 2023 04:36:35 +0000 Original-Received: from localhost ([127.0.0.1]:35400 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtKlu-000697-Oj for submit@debbugs.gnu.org; Thu, 19 Oct 2023 00:36:35 -0400 Original-Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:56464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtKls-00068u-HW for 66431@debbugs.gnu.org; Thu, 19 Oct 2023 00:36:33 -0400 Original-Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1cab2c24ecdso4156285ad.0 for <66431@debbugs.gnu.org>; Wed, 18 Oct 2023 21:36:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697690160; x=1698294960; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=JapYjnlPeH0faFz1wN4jS7xRlXLmqPHdbYdeFlqSakw=; b=To30cdWrTUIvd7eg06TvMiUkCPxPBRmHsPfyhFItq2jkUdj3Fmj1yBZA/2ega9Ackx SWw6NSVbYLGhpsgoVqIhGYzHcklJH4hOy6ZP/+jh5N3lmyhbLslzSgTfsWyOYfwPbeWG RsFkxKH4MZx/Bn/u1t3tAbdoEZK5xpTPu5IvbKbKaTLeinCHXwoe9kjjDBgVNOirA+pM Upjf2aEzKi0Xe2cLO1zp3ITFxXTfdA2QmlfVN/7RwE42c29eqmaqis3rqjRUbKmbe1Ek UuwbE83FJ8Jxdk3hkuANl/ZyobgX8ZzW5zBEDwAxwZDdrK5ip42fdzngsiRXgn7agV/5 w9UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697690160; x=1698294960; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JapYjnlPeH0faFz1wN4jS7xRlXLmqPHdbYdeFlqSakw=; b=L0l7yE3Bzb0AKuN4BzMCIa1TSqIzgWwQIi971BvhcUr2WTtrYAg2oml4vx7BEhiBGa UiKY6q2ZN1JAClr76QxlGCICFuQ6GzuCBBOoR/0hszosYFIbJ/w7JaqJYw2R6fB5xcXf 2a8A9n8f21+jgzoaC3tglfeKqb89WshsjwQ/2OEmLFe8G6DU3gLjQZKd8IlCitmLf94o dJxlqplqqaLeLhcZ5yYlgH3Q48fI0LnOLyYoGqBU/DeBnaxqhUKFA6hjYGI1qRyFZmmc QWrdHaXYY97NidjaxvIe0/NAS1Trs3LLdjG77OXrHNAPmA1Csgkef8mm1zQHHcrAhNCk RfXA== X-Gm-Message-State: AOJu0YxCmKy9UQqxtzxxqHJJ6Lggt5rAUd3T3WxfaljezvnqlpPXZTUB 774zcOQR0mSbfZ24EcgaLMU= X-Google-Smtp-Source: AGHT+IEs+LJ5NKnVwKp71CZZKicIuETK7zDX76eIe8/VGl1Sl5RLKZxf+IYxrh5cBLwtuUz/8NJwSQ== X-Received: by 2002:a17:902:c614:b0:1c3:1f0c:fb82 with SMTP id r20-20020a170902c61400b001c31f0cfb82mr965002plr.41.1697690160029; Wed, 18 Oct 2023 21:36:00 -0700 (PDT) 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 iy2-20020a170903130200b001c731b62403sm774107plb.218.2023.10.18.21.35.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2023 21:35:59 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3731.700.6) 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:272693 Archived-At: --Apple-Mail=_A2C4F754-EF7D-4669-BF1B-A2B65D6F47F0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 14, 2023, at 9:20 PM, nvp wrote: >=20 > 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. =20 > 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: >=20 > (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))) >=20 > Let me give a more precise recipe to reproduce: > 1. =46rom 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. =46rom that c++-ts-mode buffer, call `my-treesit-explorer-jump`, = and the explorer buffer should be empty, until > switching back to the source buffer. >=20 > This seems to me to be caused by `treesit--explorer-post-command` not = running until the source=20 > 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-node to nil. Yuan --Apple-Mail=_A2C4F754-EF7D-4669-BF1B-A2B65D6F47F0 Content-Disposition: attachment; filename=fix-last-node.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="fix-last-node.diff" Content-Transfer-Encoding: 7bit diff --git a/lisp/treesit.el b/lisp/treesit.el index c73ac9912d6..9f7e8bacd35 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -3198,13 +3198,13 @@ treesit-explore-mode (treesit--explorer-tree-mode))) (display-buffer treesit--explorer-buffer (cons nil '((inhibit-same-window . t)))) + (setq-local treesit--explorer-last-node nil) (treesit--explorer-refresh) ;; Set up variables and hooks. (add-hook 'post-command-hook #'treesit--explorer-post-command 0 t) (add-hook 'kill-buffer-hook #'treesit--explorer-kill-explorer-buffer 0 t) - (setq-local treesit--explorer-last-node nil) ;; Tell `desktop-save' to not save explorer buffers. (when (boundp 'desktop-modes-not-to-save) (unless (memq 'treesit--explorer-tree-mode --Apple-Mail=_A2C4F754-EF7D-4669-BF1B-A2B65D6F47F0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_A2C4F754-EF7D-4669-BF1B-A2B65D6F47F0--