Variable: treesit-explore-mode

treesit-explore-mode is a buffer-local variable defined in treesit.el.gz.

Documentation

Non-nil if Treesit-Explore mode is enabled.

Use the command treesit-explore-mode(var)/treesit-explore-mode(fun) to change this variable.

Probably introduced at or before Emacs version 31.1.

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
      (progn
        ;; 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))))
          (with-current-buffer treesit--explorer-buffer
            (treesit--explorer-tree-mode)))
        ;; Select parser.  `treesit-explorer-switch-parser' will return
        ;; t if its `completing-read' did not quit.
        (if (not (condition-case _
                     (call-interactively #'treesit-explorer-switch-parser)
                   (quit)))
            (setq treesit-explore-mode nil)
          ;; Track the `treesit--explorer-source-buffer' active region.
          (add-hook 'post-command-hook
                    #'treesit--explorer-post-command 0 t)
          ;; Clean up when the `treesit-explore-mode' buffer is killed.
          (add-hook 'kill-buffer-hook
                    #'treesit--explorer-tree-mode-cleanup 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)))
          ;; Tell `desktop-save' to not save this minor mode
          ;; that might disrupt loading the desktop
          ;; with the prompt to select a parser.
          (when (boundp 'desktop-minor-mode-table)
            (unless (member '(treesit-explore-mode nil)
                            desktop-minor-mode-table)
              (push '(treesit-explore-mode nil)
                    desktop-minor-mode-table)))))
    ;; Turn off explore mode.
    (remove-hook 'post-command-hook
                 #'treesit--explorer-post-command t)
    (remove-hook 'kill-buffer-hook
                 #'treesit--explorer-tree-mode-cleanup t)
    ;; Clean up if the user disables `treesit-explore-mode' interactively; e.g.,
    ;; via M-x while leaving the source buffer alive.
    (when (called-interactively-p 'any)
      (treesit--explorer-tree-mode-cleanup))))