From: Yuan Fu <casouri@gmail.com>
To: nvp <noah.v.peart@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, 66431@debbugs.gnu.org
Subject: bug#66431: [PATCH] Fix reset treesit--explorer-last-node when explorer buffer was killed
Date: Wed, 18 Oct 2023 21:35:48 -0700 [thread overview]
Message-ID: <029D1797-AE78-4E45-BE25-0BEC8AF47321@gmail.com> (raw)
In-Reply-To: <CAPVBTSdF=ajb_p64=0tnKCo1LL8QGUEXQcroeWY2BKs8aJyHRA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2414 bytes --]
> 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 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’t 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
[-- Attachment #2: fix-last-node.diff --]
[-- Type: application/octet-stream, Size: 912 bytes --]
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
[-- Attachment #3: Type: text/plain, Size: 2 bytes --]
next prev parent reply other threads:[~2023-10-19 4:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 6:02 bug#66431: [PATCH] Fix reset treesit--explorer-last-node when explorer buffer was killed nvp
2023-10-14 8:17 ` Eli Zaretskii
2023-10-14 17:08 ` Yuan Fu
2023-10-15 4:20 ` nvp
2023-10-19 4:35 ` Yuan Fu [this message]
2023-10-20 21:22 ` nvp
2023-10-21 18:33 ` Yuan Fu
2023-10-22 0:40 ` nvp
2023-10-22 3:35 ` Yuan Fu
2023-10-14 17:08 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=029D1797-AE78-4E45-BE25-0BEC8AF47321@gmail.com \
--to=casouri@gmail.com \
--cc=66431@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=noah.v.peart@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).