File: treesit.el.html

This file is the Lisp counterpart of treesit.c. Together they provide tree-sitter integration for Emacs. This file contains convenient functions that are more idiomatic and flexible than the exposed C API of tree-sitter. It also contains frameworks for integrating tree-sitter with font-lock, indentation, activating and deactivating tree-sitter, debugging tree-sitter, etc.

Some conventions:

1. Whenever it makes sense, a function that takes a tree-sitter node
as an argument should also accept nil (and return nil in that case). This is to help with function chaining.

2. In most cases, a function shouldn't implicitly create a parser.
All parsers should be created explicitly by user. Use

    (car (treesit-parser-list nil LANG))

to get a parser for a certain language.

Initially in Emacs 29, the world is simple and each language has one parser in the buffer. So if we need a parser for a language, we can just create it if it doesn't exist. But now we have local parsers, so there will be more than one parser for each language in a buffer. We can also have local parser of the same language as the host parser. All of which means we can't equalize language and parser, and create parser for a language willy-nilly anymore. Major mode will manage their parsers.

Defined variables (55)

treesit--explorer-bufferBuffer used to display the syntax tree.
treesit--explorer-highlight-overlayOverlay used to highlight in syntax tree and source buffer.
treesit--explorer-last-nodeLast top-level node used to generate syntax tree.
treesit--explorer-parserThe language used in the playground.
treesit--explorer-refresh-timerTimer for refreshing the syntax tree buffer.
treesit--explorer-source-bufferSource buffer corresponding to the playground buffer.
treesit--explorer-tree-mode-abbrev-tableAbbrev table for ‘treesit--explorer-tree-mode’.
treesit--explorer-tree-mode-hookHook run after entering ‘treesit--explorer-tree-mode’.
treesit--explorer-tree-mode-mapKeymap for the treesit tree explorer.
treesit--explorer-tree-mode-syntax-tableSyntax table for ‘treesit--explorer-tree-mode’.
treesit--font-lock-fast-modeIf this variable is t, change the way we query so it’s faster.
treesit--font-lock-query-expand-rangeThe amount to expand the start and end of the region when fontifying.
treesit--font-lock-verboseIf non-nil, print debug messages when fontifying.
treesit--indent-region-batch-sizeHow many lines of indent value do we precompute.
treesit--indent-verboseIf non-nil, log progress when indenting.
treesit--inspect-nameUsed by ‘treesit-inspect-mode’ to show node name in mode-line.
treesit--install-language-grammar-bloblessIf non-nil, create a blobless clone when cloning git repos.
treesit--install-language-grammar-full-cloneIf non-nil, do a full clone when cloning git repos.
treesit--install-language-grammar-out-dir-historyHistory for OUT-DIR for ‘treesit-install-language-grammar’.
treesit--parser-overlay-offsetDefines at which position to get the parser overlay.
treesit--pre-redisplay-tickThe last ‘buffer-chars-modified-tick’ that we’ve processed.
treesit--query-cacheCache of compiled queries for font-lock/indentation.
treesit--syntax-propertize-startIf non-nil, next ‘syntax-propertize’ should start at this position.
treesit-add-log-defun-delimiterThe delimiter used to connect several defun names.
treesit-aggregated-outline-predicateSettings that configure ‘treesit-outline-search’ for multi-language modes.
treesit-aggregated-simple-imenu-settingsSettings that configure ‘treesit-simple-imenu’ for multi-language modes.
treesit-auto-install-grammarWhether to install tree-sitter language grammar libraries when needed.
treesit-defun-name-functionA function that is called with a node and returns its defun name or nil.
treesit-defun-skipperA function called after tree-sitter navigation moved a step.
treesit-defun-tacticDetermines how Emacs treats nested defuns.
treesit-defun-type-regexpA regexp that matches the node type of defun nodes.
treesit-enabled-modesSpecify which tree-sitter based major modes to enable by default.
treesit-explore-modeNon-nil if Treesit-Explore mode is enabled.
treesit-explore-mode-hookHook run after entering or leaving ‘treesit-explore-mode’.
treesit-font-lock-feature-listA list of lists of feature symbols.
treesit-font-lock-levelDecoration level to be used by tree-sitter fontifications.
treesit-font-lock-settingsA list of SETTINGs for treesit-based fontification.
treesit-indent-functionFunction used by ‘treesit-indent’ to do some of the work.
treesit-inspect-modeNon-nil if Treesit-Inspect mode is enabled.
treesit-inspect-mode-hookHook run after entering or leaving ‘treesit-inspect-mode’.
treesit-language-at-point-functionA function that returns the language at point.
treesit-language-display-name-alistAn alist mapping language symbols to their display names.
treesit-language-source-alistConfiguration for downloading and installing tree-sitter language grammars.
treesit-max-buffer-sizeMaximum buffer size (in bytes) for enabling tree-sitter parsing.
treesit-outline-predicatePredicate used to find outline headings in the syntax tree.
treesit-primary-parserThe primary parser for this buffer.
treesit-range-settingsA list of range settings.
treesit-sexp-thingA thing that matches the sexp nodes for ‘forward-sexp’.
treesit-sexp-thing-down-listA thing that matches the sexp nodes for ‘down-list’.
treesit-sexp-thing-up-listA thing that matches the sexp nodes for ‘up-list’.
treesit-simple-imenu-settingsSettings that configure ‘treesit-simple-imenu’.
treesit-simple-indent-override-rulesExtra simple indent rules for customizing indentation.
treesit-simple-indent-presetsA list of indent rule presets.
treesit-simple-indent-rulesA list of indent rule settings.
treesit-simple-indent-standalone-predicateFunction used to determine if a node is "standalone".

Defined functions (153)

treesit--build-grammar(WORKDIR OUT-DIR LANG SOURCE-DIR CC C++)
treesit--call-process-signal(&rest ARGS)
treesit--check-repo-url(URL)
treesit--children-covering-range(NODE START END)
treesit--children-covering-range-recurse(NODE START END THRESHOLD &optional LIMIT)
treesit--cleanup-local-range-overlays(MODIFIED-TICK BEG END)
treesit--clip-ranges(RANGES START END)
treesit--compile-query-with-cache(LANG QUERY)
treesit--compute-font-lock-level(LEVEL)
treesit--copy-queries(WORKDIR OUT-DIR LANG SOURCE-DIR)
treesit--explorer--nodes-to-highlight(PARSER)
treesit--explorer-draw-node(NODE)
treesit--explorer-generate-parser-alist()
treesit--explorer-highlight-node(NODES)
treesit--explorer-jump(BUTTON)
treesit--explorer-kill-explorer-buffer()
treesit--explorer-post-command(&rest _)
treesit--explorer-refresh()
treesit--explorer-refresh-1()
treesit--explorer-tree-mode()
treesit--font-lock-fontify-region-1(NODE QUERY START END OVERRIDE LOUDLY)
treesit--font-lock-level-setter(SYM VAL)
treesit--font-lock-mark-ranges-to-fontify(RANGES)
treesit--font-lock-setting-clone-enable(SETTING)
treesit--forward-list-with-default(ARG DEFAULT-FUNCTION)
treesit--generate-shortdoc-examples()
treesit--generate-simple-imenu(NODE SETTINGS)
treesit--git-checkout-branch(REPO-DIR REVISION)
treesit--git-clone-repo(URL REVISION WORKDIR)
treesit--guess-primary-parser()
treesit--imenu-merge-entries(ENTRIES)
treesit--indent-1()
treesit--indent-largest-node-at(POS)
treesit--indent-prev-line-node(POS)
treesit--indent-rules-optimize(RULES)
treesit--install-language-grammar-1(OUT-DIR LANG URL &rest ARGS)
treesit--install-language-grammar-build-recipe(LANG)
treesit--language-git-revision(REPO-DIR)
treesit--language-git-timestamp(REPO-DIR)
treesit--language-git-version-tags(REPO-DIR)
treesit--merge-ranges(OLD-RANGES NEW-RANGES START END)
treesit--node-length(NODE)
treesit--parser-at-level(PARSERS LEVEL &optional INCLUDE-NULL)
treesit--pre-redisplay(&rest _)
treesit--pre-syntax-ppss(START END)
treesit--read-major-mode()
treesit--scan-error(PRED ARG)
treesit--set-nonsticky(START END SYM &optional REMOVE)
treesit--simple-imenu-1(NODE PRED NAME-FN)
treesit--simple-indent-eval(EXP)
treesit--thing-sibling(POS THING PREV)
treesit--update-range-1(BEG END HOST-PARSER SETTINGS EMBED-LEVEL)
treesit--update-ranges-local(HOST-PARSER QUERY EMBEDDED-LANG MODIFIED-TICK EMBED-LEVEL &optional BEG END OFFSET RANGE-FN)
treesit--update-ranges-non-local(HOST-PARSER QUERY EMBED-LANG MODIFIED-TICK EMBED-LEVEL &optional BEG END OFFSET RANGE-FN)
treesit-add-font-lock-rules(RULES &optional HOW FEATURE)
treesit-add-log-current-defun()
treesit-beginning-of-defun(&optional ARG)
treesit-beginning-of-thing(THING &optional ARG TACTIC)
treesit-buffer-root-node(&optional LANGUAGE TAG)
treesit-check-indent(MODE)
treesit-cycle-sexp-thing(&optional INTERACTIVE)
treesit-declare-unavailable-functions()
treesit-default-defun-skipper()
treesit-defun-at-point()
treesit-defun-name(NODE)
treesit-down-list(&optional ARG)
treesit-end-of-defun(&optional ARG _)
treesit-end-of-thing(THING &optional ARG TACTIC)
treesit-ensure-installed(LANG)
treesit-explore()
treesit-explore-mode(&optional ARG)
treesit-explorer-switch-parser(PARSER)
treesit-fill-reindent-defun(&optional JUSTIFY)
treesit-filter-child(NODE PRED &optional NAMED)
treesit-font-lock-fontify-region(START END &optional LOUDLY)
treesit-font-lock-recompute-features(&optional ADD-LIST REMOVE-LIST LANGUAGE)
treesit-font-lock-rules(&rest QUERY-SPECS)
treesit-font-lock-setting-enable(SETTING)
treesit-font-lock-setting-feature(SETTING)
treesit-font-lock-setting-language(SETTING)
treesit-font-lock-setting-override(SETTING)
treesit-font-lock-setting-query(SETTING)
treesit-font-lock-setting-reversed(SETTING)
treesit-fontify-with-override(START END FACE OVERRIDE &optional BOUND-START BOUND-END)
treesit-forward-comment(&optional COUNT)
treesit-forward-list(&optional ARG)
treesit-forward-sentence(&optional ARG)
treesit-forward-sexp(&optional ARG)
treesit-forward-sexp-list(&optional ARG)
treesit-hs-block-end()
treesit-hs-find-block-beginning()
treesit-hs-find-next-block(REGEXP MAXP COMMENTS)
treesit-hs-inside-comment-p()
treesit-hs-looking-at-block-start-p()
treesit-indent()
treesit-indent-region(BEG END)
treesit-inspect-mode(&optional ARG)
treesit-inspect-node-at-point(&optional ARG)
treesit-install-language-grammar(LANG &optional OUT-DIR)
treesit-language-at(POSITION)
treesit-language-at-point-default(POSITION)
treesit-language-display-name(LANGUAGE)
treesit-local-parsers-at(&optional POS LANGUAGE WITH-HOST)
treesit-local-parsers-on(&optional BEG END LANGUAGE WITH-HOST)
treesit-major-mode-setup()
treesit-merge-font-lock-feature-list(FEATURES-LIST-1 FEATURES-LIST-2)
treesit-navigate-thing(POS ARG SIDE THING &optional TACTIC RECURSING)
treesit-node-at(POS &optional PARSER-OR-LANG NAMED)
treesit-node-buffer(NODE)
treesit-node-children(NODE &optional NAMED)
treesit-node-enclosed-p(SMALLER LARGER &optional STRICT)
treesit-node-field-name(NODE)
treesit-node-get(NODE INSTRUCTIONS)
treesit-node-index(NODE &optional NAMED)
treesit-node-language(NODE)
treesit-node-named(NODE)
treesit-node-on(BEG END &optional PARSER-OR-LANG NAMED)
treesit-node-text(NODE &optional NO-PROPERTY)
treesit-node-top-level(NODE &optional PRED INCLUDE-NODE)
treesit-outline--at-point()
treesit-outline-level()
treesit-outline-predicate--from-imenu(NODE)
treesit-outline-search(&optional BOUND MOVE BACKWARD LOOKING-AT)
treesit-parent-until(NODE PRED &optional INCLUDE-NODE)
treesit-parent-while(NODE PRED)
treesit-parser-range-on(PARSER BEG &optional END)
treesit-parsers-at(&optional POS LANGUAGE WITH-HOST ONLY)
treesit-query-range(NODE QUERY &optional BEG END OFFSET RANGE-FN)
treesit-query-range-by-language(NODE QUERY LANGUAGE-FN &optional BEG END OFFSET RANGE-FN)
treesit-query-string(STRING QUERY LANGUAGE)
treesit-query-validate(LANGUAGE QUERY)
treesit-query-with-optional(LANGUAGE MANDATORY &rest QUERIES)
treesit-range-fn-exclude-children(NODE OFFSET)
treesit-range-rules(&rest QUERY-SPECS)
treesit-ready-p(LANGUAGE &optional QUIET)
treesit-replace-font-lock-feature-settings(NEW-SETTINGS SETTINGS)
treesit-search-forward-goto(NODE PREDICATE &optional START BACKWARD ALL)
treesit-show-paren-data()
treesit-show-paren-data--categorize(POS &optional END-P)
treesit-simple-imenu()
treesit-simple-indent(NODE PARENT BOL)
treesit-simple-indent-add-rules(LANGUAGE RULES &optional WHERE ANCHOR)
treesit-simple-indent-modify-rules(LANG NEW-RULES RULES &optional HOW)
treesit-thing-at(POS THING &optional STRICT)
treesit-thing-at-point(THING TACTIC)
treesit-thing-defined-p(THING LANGUAGE)
treesit-thing-definition(THING LANGUAGE)
treesit-thing-next(POS THING)
treesit-thing-prev(POS THING)
treesit-transpose-sexps(&optional ARG)
treesit-up-list(&optional ARG ESCAPE-STRINGS NO-SYNTAX-CROSSING)
treesit-update-ranges(&optional BEG END)
treesit-validate-and-compile-font-lock-rules(SETTINGS)

Defined faces (2)

treesit-explorer-anonymous-nodeFace for anonymous nodes in tree-sitter explorer.
treesit-explorer-field-nameFace for field names in tree-sitter explorer.