Function: treesit-inspect-node-at-point
treesit-inspect-node-at-point is an interactive and byte-compiled
function defined in treesit.el.gz.
Signature
(treesit-inspect-node-at-point &optional ARG)
Documentation
Show information of the node at point.
If called interactively, show in echo area, otherwise set
treesit--inspect-name (which will appear in the mode-line
if treesit-inspect-mode(var)/treesit-inspect-mode(fun) is enabled). Uses the first parser
in treesit-parser-list.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-inspect-node-at-point (&optional arg)
"Show information of the node at point.
If called interactively, show in echo area, otherwise set
`treesit--inspect-name' (which will appear in the mode-line
if `treesit-inspect-mode' is enabled). Uses the first parser
in `treesit-parser-list'."
(interactive "p")
;; NODE-LIST contains all the node that starts at point.
(let* ((node-list
(cl-loop for node = (treesit-node-at (point))
then (treesit-node-parent node)
while node
if (eq (treesit-node-start node)
(point))
collect node))
(largest-node (car (last node-list)))
(parent (treesit-node-parent largest-node))
;; node-list-ascending contains all the node bottom-up, then
;; the parent.
(node-list-ascending
(if (null largest-node)
;; If there are no nodes that start at point, just show
;; the node at point and its parent.
(list (treesit-node-at (point))
(treesit-node-parent
(treesit-node-at (point))))
(append node-list (list parent))))
(name ""))
;; We draw nodes like (parent field-name: (node)) recursively,
;; so it could be (node1 field-name: (node2 field-name: (node3))).
(dolist (node node-list-ascending)
(setq
name
(concat
(if (treesit-node-field-name node)
(format " %s: " (treesit-node-field-name node))
" ")
(if (treesit-node-check node 'named) "(" "\"")
(propertize (or (treesit-node-type node) "N/A")
'face
(if (treesit-node-eq node largest-node)
'bold nil))
name
(if (treesit-node-check node 'named) ")" "\""))))
;; Escape the percent character for mode-line. (Bug#65540)
(setq treesit--inspect-name (string-replace "%" "%%" name))
(force-mode-line-update)
(when arg
(if node-list
(message "%s" treesit--inspect-name)
(message "No node at point")))))