doomemacs/modules/tools/tree-sitter
Henrik Lissner 1a05e2fa64
bump: :tools
NicolasPetton/pass@c721604b3b -> NicolasPetton/pass@ed7031c5c3
Silex/docker.el@6997c86a24 -> Silex/docker.el@d5255a65b7
alphapapa/magit-todos@cadf29d1cc -> alphapapa/magit-todos@debb77b358
andras-simonyi/citeproc-el@290320fc57 -> andras-simonyi/citeproc-el@c61c98b9d2
doomelpa/code-review@26f426e992 -> doomelpa/code-review@c34ff1ee64
editorconfig/editorconfig-emacs@2fed9599bc -> editorconfig/editorconfig-emacs@4b81a59928
emacs-citar/citar-org-roam@761eed6678 -> emacs-citar/citar-org-roam@7d67dccf80
emacs-citar/citar@2c0547db57 -> emacs-citar/citar@885b86f673
emacs-lsp/lsp-mode@02c5ba59ce -> emacs-lsp/lsp-mode@fb88cc6b8b
emacs-straight/eglot@f73594f589 -> emacs-straight/eglot@cd4e45b700
emacs-straight/rainbow-mode@24437ec2c6 -> emacs-straight/rainbow-mode@70ed10d410
emacs-tree-sitter/tree-sitter-langs@5eb24557f5 -> emacs-tree-sitter/tree-sitter-langs@20fbbb8573
emacsorphanage/quickrun@6f96318930 -> emacsorphanage/quickrun@248149b026
hcl-emacs/terraform-mode@39d2fd5bfc -> hcl-emacs/terraform-mode@e8b57df8c2
jacktasia/dumb-jump@d9503c157a -> jacktasia/dumb-jump@ede6a04187
magit/forge@ba35ffc9ba -> magit/forge@b16b6ec4f7
magit/magit@4881835572 -> magit/magit@54d37dc14c
meain/evil-textobj-tree-sitter@9a9edd42a2 -> meain/evil-textobj-tree-sitter@220ceae065
purcell/envrc@33d01388ce -> purcell/envrc@1385e72a73
rejeep/prodigy.el@a3be00d3b9 -> rejeep/prodigy.el@cc68fa9d60
tmalsburg/helm-bibtex@ef07adfeda -> tmalsburg/helm-bibtex@bf184cc311
xuchunyang/osx-dictionary.el@0715e5a3ac -> xuchunyang/osx-dictionary.el@1f5a74f3e5
yoshiki/yaml-mode@3fcb36d603 -> yoshiki/yaml-mode@5b58248ab2
zx2c4/password-store@28cec11f1d -> zx2c4/password-store@b5e965a838
2024-02-04 19:07:25 -05:00
..
autoload.el feat(tree-sitter): add set-tree-sitter-lang! autodef 2022-09-10 18:36:24 +02:00
config.el refactor: deprecate featurep! for modulep! 2022-08-14 20:43:35 +02:00
doctor.el docs(tree-sitter): add doctor check for modules 2022-05-22 21:25:58 +01:00
packages.el bump: :tools 2024-02-04 19:07:25 -05:00
README.org docs(*): replace all-the-icons with nerd-icons 2023-09-16 20:19:11 +02:00

:tools tree-sitter

Description   unfold

This module adds tree-sitter support to Doom Emacs.

󰟶 Tree sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited. This allows for features of the editor to become syntax aware.

It includes:

  • Better syntax highlighting of supported languages.
  • Structural text objects to manipulate functions statements and other code structures like any other text object.

Module flags

This module has no flags.

Hacks

No hacks documented for this module.

TODO Changelog

This module does not have a changelog yet.

Installation

Enable this module in your doom! block.

This module has no direct requirements, but some languages may have their own to fulfill before tree-sitter support works for them. Run $ doom doctor to find out what you're missing.

TODO Usage

󱌣 This module's usage documentation is incomplete. Complete it?

Language support

Currently Emacs tree sitter has parsers for these languages, and syntax highlighting support for these languages as well as typescript-tsx-mode.

To enable tree-sitter support for specific languages, add the +tree-sitter flag to their respective Doom modules. Check the module readme of your language for support.

Text Objects

Not all languages support all text objects (yet). Here is a table of the text object languages support.

 Only languages with parsers in Emacs have text object support at the moment.

Currently text objects are bound to:

key text object
A parameter list
f function definition
F function call
C class
c comment
v conditional
l loop

They are used in a container context (not vf, but vaf or vif).

Goto certain nodes

To jump to the next/previous node, type in a buffer by using [g or ]g respectfully, the following key will correspond to the text object you want to jump to.

Currently keys are bound to:

key text object
a parameter list
f function
F function call
c comment
C class
v conditional
l loop

TODO Configuration

󱌣 This module's configuration documentation is incomplete. Complete it?

Rebind text objects

Rebinding keys works the same as rebinding any other key, but text-object keys must be bound on one or both of the +tree-sitter-inner-text-object-map or +tree-sitter-outer-text-object-map keymaps:

(map! (:map +tree-sitter-outer-text-objects-map
       "f" (evil-textobj-tree-sitter-get-textobj "call.inner")
       "F" (evil-textobj-tree-sitter-get-textobj "function.inner"))
      (:map +tree-sitter-inner-text-objects-map
       "f" (evil-textobj-tree-sitter-get-textobj "call.inner")
       "F" (evil-textobj-tree-sitter-get-textobj "function.inner")))

Add your own text objects

To add your own custom text objects, bind them to +tree-sitter-{inner, outer}-text-objects-map:

(map! :map +tree-sitter-outer-text-objects-map
      "m" (evil-textobj-tree-sitter-get-textobj "import"
            '((python-mode . [(import_statement) @import])
              (rust-mode . [(use_declaration) @import]))))

Configuring Tree sitter highlighting

Highlighting is controlled by the variable +tree-sitter-hl-enabled-modes This list allows you to whitelist, blacklist, fully enable or fully disable tree-sitter highlighting for all major modes

To use highlighting in select modes add major-modes to +tree-sitter-hl-enabled-modes. This disables highlighting in all other modes. The symbol that should be used is the major mode symbol, not the package symbol.

(setq +tree-sitter-hl-enabled-modes '(python-mode go-mode))

If you want to disallow highlighting in certain modes then the car of +tree-sitter-hl-enabled-modes should be not. This enables highlighting in all modes except the ones disallowed.

(setq +tree-sitter-hl-enabled-modes '(not web-mode typescript-tsx-mode))

If +tree-sitter-hl-enabled-modes is set to nil or t it will fully disable or fully enable highlighting in every tree sitter enabled language respectively.

Troubleshooting

Report an issue?

(error "Bad bounding indices: 0, 1")

This means that the text object does not have the underlying query needed. This can be fixed by either adding in a custom query (which would override the current key bound) or contributing upstream!

Frequently asked questions

This module has no FAQs yet. Ask one?

TODO Appendix

󱌣 This module has no appendix yet. Write one?