From f2b757c5b0b26b0924f046b6ee3719fd7dd2ec3f Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Fri, 29 Nov 2024 20:38:24 -0800 Subject: [PATCH] Add treesit-explore command * lisp/treesit.el (treesit-explore): New function. * doc/lispref/parsing.texi (Language Grammar): Advertize this command instead of the minor mode. (cherry picked from commit d0b918d8f3cc0779fa73b395b6384c8a04b0c0ba) --- doc/lispref/parsing.texi | 4 ++-- lisp/treesit.el | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 9fe828d8512..5ef29f558ef 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -240,8 +240,8 @@ which displays the syntax tree of the source in the current buffer in real time. Emacs also comes with an ``inspect mode'', which displays information of the nodes at point in the mode-line. -@deffn Command treesit-explore-mode -This mode pops up a window displaying the syntax tree of the source in +@deffn Command treesit-explore +This command pops up a window displaying the syntax tree of the source in the current buffer. Selecting text in the source buffer highlights the corresponding nodes in the syntax tree display. Clicking on nodes in the syntax tree highlights the corresponding text in the diff --git a/lisp/treesit.el b/lisp/treesit.el index be6df5a576b..1c57191fe53 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -3624,6 +3624,14 @@ window." #'treesit--explorer-kill-explorer-buffer t) (treesit--explorer-kill-explorer-buffer))) +(defun treesit-explore () + "Show the explorer." + (interactive) + (if (and treesit-explore-mode + (buffer-live-p treesit--explorer-buffer)) + (display-buffer treesit--explorer-buffer '(nil (inhibit-same-window . t))) + (treesit-explore-mode))) + ;;; Install & build language grammar (defvar treesit-language-source-alist nil -- 2.39.5