Function: treesit-explore-mode
treesit-explore-mode is an interactive and byte-compiled function
defined in treesit.el.gz.
Signature
(treesit-explore-mode &optional ARG)
Documentation
Enable exploring the current buffer's syntax tree.
Pops up a window showing the syntax tree of the source in the current buffer in real time. The corresponding node enclosing the text in the active region is highlighted in the explorer window.
This is a minor mode. If called interactively, toggle the
Treesit-Explore mode mode. If the prefix argument is positive, enable
the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is toggle. Enable the
mode if ARG is nil, omitted, or is a positive number. Disable the mode
if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate the variable treesit-explore-mode(var)/treesit-explore-mode(fun).
The mode's hook is called both when the mode is enabled and when it is disabled.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(define-minor-mode treesit-explore-mode
"Enable exploring the current buffer's syntax tree.
Pops up a window showing the syntax tree of the source in the
current buffer in real time. The corresponding node enclosing
the text in the active region is highlighted in the explorer
window."
:lighter " TSexplore"
(if treesit-explore-mode
(let ((language
(intern (completing-read
"Language: "
(cl-remove-duplicates
(mapcar #'treesit-parser-language
(treesit-parser-list nil nil t)))))))
(if (not (treesit-language-available-p language))
(user-error "Cannot find tree-sitter grammar for %s: %s"
language (cdr (treesit-language-available-p
language t)))
;; Create explorer buffer.
(unless (buffer-live-p treesit--explorer-buffer)
(setq-local treesit--explorer-buffer
(get-buffer-create
(format "*tree-sitter explorer for %s*"
(buffer-name))))
(setq-local treesit--explorer-language language)
(with-current-buffer treesit--explorer-buffer
(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)
;; Tell `desktop-save' to not save explorer buffers.
(when (boundp 'desktop-modes-not-to-save)
(unless (memq 'treesit--explorer-tree-mode
desktop-modes-not-to-save)
(push 'treesit--explorer-tree-mode
desktop-modes-not-to-save)))))
;; Turn off explore mode.
(remove-hook 'post-command-hook
#'treesit--explorer-post-command t)
(remove-hook 'kill-buffer-hook
#'treesit--explorer-kill-explorer-buffer t)
(treesit--explorer-kill-explorer-buffer)))