doomemacs/modules/tools/tree-sitter
Henrik Lissner 1abcf913aa
revert: fix(docs): set mode in file-local vars
emacs-straight/org-mode@e22b4eb7aa introduced a breaking change that
made it impossible to rely on .dir-locals.el to change org-mode buffers
in $EMACSDIR to doom-docs-org-mode (without infinite recursion), so we
used file-local variables in 7e400ab.

emacs-straight/org-mode@215de6176b reverted that change, so we can use
.dir-locals.el again, and this is my preference, since it requires less
boilerplate across our hundreds of org files.

Ref: emacs-straight/org-mode@215de6176b
Ref: emacs-straight/org-mode@e22b4eb7aa
Revert: 7e400abdc0
2022-08-07 19:08:07 +02:00
..
autoload.el fix(lsp,tree-sitter): void-function lsp!/tree-sitter! errors 2022-06-22 20:35:52 +02:00
config.el fix(tree-sitter): ensure load order 2022-06-18 15:01:13 +02:00
doctor.el docs(tree-sitter): add doctor check for modules 2022-05-22 21:25:58 +01:00
packages.el bump: :tools tree-sitter 2022-07-23 16:26:06 +02:00
README.org revert: fix(docs): set mode in file-local vars 2022-08-07 19:08:07 +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]))))

Disable syntax highlighting for certain modes

To disable syntax highlighting across the board you can do:

(remove-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)

Then it can be enabled for specific major modes:

(add-hook 'MAJOR-MODE-hook #'tree-sitter-hl-mode)

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?