Function: treesit-node-field-name-for-child
treesit-node-field-name-for-child is a function defined in treesit.c.
Signature
(treesit-node-field-name-for-child NODE N)
Documentation
Return the field name of the Nth child of NODE.
Return nil if there's no Nth child, or if it has no field. If NODE is nil, return nil.
N counts all children, i.e., named ones and anonymous ones.
N could be negative, e.g., -1 represents the last child.
Other relevant functions are documented in the treesit group.
Shortdoc
;; treesit
(treesit-node-field-name-for-child node)
e.g. => "body"
Source Code
// Defined in /usr/src/emacs/src/treesit.c
{
if (NILP (node))
return Qnil;
treesit_check_node (node);
CHECK_INTEGER (n);
EMACS_INT idx = XFIXNUM (n);
treesit_initialize ();
TSNode treesit_node = XTS_NODE (node)->node;
/* Process negative index. */
if (idx < 0)
idx = ts_node_child_count (treesit_node) + idx;
if (idx < 0)
return Qnil;
if (idx > UINT32_MAX)
xsignal1 (Qargs_out_of_range, n);
const char *name
= ts_node_field_name_for_child (treesit_node, (uint32_t) idx);
if (name == NULL)
return Qnil;
return build_string (name);
}