docs(tree-sitter): improve README formatting

This commit is contained in:
Colin Woodbury 2022-06-21 12:38:57 -07:00 committed by Henrik Lissner
parent 40ca1a799f
commit a5cc803ad4

View file

@ -21,78 +21,94 @@
- [[#error-bad-bounding-indices-0-1][=(error "Bad bounding indices: 0, 1")=]] - [[#error-bad-bounding-indices-0-1][=(error "Bad bounding indices: 0, 1")=]]
* Description * Description
This module adds [[https://tree-sitter.github.io/tree-sitter/][tree-sitter]] support to doom:
This module adds [[https://tree-sitter.github.io/tree-sitter/][tree-sitter]] support to Doom:
#+begin_quote #+begin_quote
Tree sitter is a parser generator tool and an incremental parsing library. It 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 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 syntax tree as the source file is edited. This allows for features of the editor
to become syntax aware. to become syntax aware.
#+end_quote #+end_quote
It includes: It includes:
+ Better syntax highlighting of supported languages
+ Better syntax highlighting of supported languages.
+ Structural text objects to manipulate functions statements and other code + Structural text objects to manipulate functions statements and other code
structures like any other text object structures like any other text object.
** Maintainers ** Maintainers
- @jeetelongname
+ @jeetelongname
** Module Flags ** Module Flags
This module provides no flags. This module provides no flags.
** Plugins ** Plugins
+ [[https://github.com/emacs-tree-sitter/elisp-tree-sitter][tree-sitter]] + [[https://github.com/emacs-tree-sitter/elisp-tree-sitter][tree-sitter]]
+ [[https://github.com/emacs-tree-sitter/tree-sitter-langs][tree-sitter-langs]] + [[https://github.com/emacs-tree-sitter/tree-sitter-langs][tree-sitter-langs]]
+ [[https://github.com/meain/evil-textobj-tree-sitter][evil-textobj-tree-sitter]]* (=:editor evil +everywhere=) + [[https://github.com/meain/evil-textobj-tree-sitter][evil-textobj-tree-sitter]]* (=:editor evil +everywhere=)
* Prerequisites * Prerequisites
This module has no prerequisites. This module has no prerequisites.
* Features * Features
** Language support ** Language support
Currently Emacs tree sitter has got [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/repos][parsers for these languages]] with syntax
highlighting support for [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/queries][these languages]] as well as ~typescript-tsx-mode~ Currently Emacs tree sitter has [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/repos][parsers for these languages]], and syntax
To enable tree sitter for individual languages add the =+tree-sitter= flag. highlighting support for [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/queries][these languages]] as well as ~typescript-tsx-mode~.
Check the module readme of your language for support.
To enable tree sitter for individual languages, add the =+tree-sitter= flag. Check
the module readme of your language for support.
** Text Objects ** Text Objects
Not all language support all text objects (yet). [[https://github.com/nvim-treesitter/nvim-treesitter-textobjects#built-in-textobjects][Here is a table of the text
objects languages support]] Not all languages support all text objects (yet). [[https://github.com/nvim-treesitter/nvim-treesitter-textobjects#built-in-textobjects][Here is a table of the text
Note: only languages with parsers in emacs have text object support currently. object languages support]].
Note: Only languages with parsers in Emacs have text object support currently.
Currently text objects are bound to: Currently text objects are bound to:
| key | text object | | key | text object |
|-----+---------------------| |-----+---------------------|
| =A= | parameter list | | =A= | parameter list |
| =f= | function definition | | =f= | function definition |
| =F= | function call | | =F= | function call |
| =C= | class | | =C= | class |
| =c= | comment | | =c= | comment |
| =v= | conditional | | =v= | conditional |
| =l= | loop | | =l= | loop |
They are used in a container context (not =vf= but =vaf= or =vif=) They are used in a container context (not =vf= but =vaf= or =vif=)
** Goto certain nodes ** Goto certain nodes
you can also 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 You can also jump to the next / previous node type in a buffer by using =[g= or =]g=
want to jump to respectfully, the following key will correspond to the text object you want to
jump to.
Currently keys are bound to: Currently keys are bound to:
| key | text object | | key | text object |
|-----+----------------| |-----+----------------|
| =a= | parameter list | | =a= | parameter list |
| =f= | function | | =f= | function |
| =F= | function call | | =F= | function call |
| =c= | comment | | =c= | comment |
| =C= | class | | =C= | class |
| =v= | conditional | | =v= | conditional |
| =l= | loop | | =l= | loop |
* Configuration * Configuration
** Rebinding text objects ** Rebinding text objects
Rebinding keys is the same as any other key but do notes they need to be bound
to the keymaps ~+tree-sitter-inner-text-object-map~ or Rebinding keys is the same as any other key, but do note that they need to be
~+tree-sitter-outer-text-object-map~ bound to the keymaps ~+tree-sitter-inner-text-object-map~ or
~+tree-sitter-outer-text-object-map~.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(map! (:map +tree-sitter-outer-text-objects-map (map! (:map +tree-sitter-outer-text-objects-map
"f" nil "f" nil
@ -108,8 +124,8 @@ to the keymaps ~+tree-sitter-inner-text-object-map~ or
** Adding your own text objects ** Adding your own text objects
If you wish to [[https://github.com/meain/evil-textobj-tree-sitter#custom-textobjects][add your own custom text objects]] then you need to bind them to If you wish to [[https://github.com/meain/evil-textobj-tree-sitter#custom-textobjects][add your own custom text objects]] then you need to bind them to
~+tree-sitter-{inner, outer}-text-objects-map~ ~+tree-sitter-{inner, outer}-text-objects-map~. For example:
for example:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(map! (:map +tree-sitter-outer-text-objects-map (map! (:map +tree-sitter-outer-text-objects-map
"m" (evil-textobj-tree-sitter-get-textobj "import" "m" (evil-textobj-tree-sitter-get-textobj "import"
@ -118,13 +134,16 @@ for example:
#+end_src #+end_src
** Disabling highlighting for certain modes ** Disabling highlighting for certain modes
If you want to disable highlighting by default you can add a
If you want to disable highlighting by default you can do:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(after! MODE-PACKAGE (after! MODE-PACKAGE
(tree-sitter-hl-mode -1)) (tree-sitter-hl-mode -1))
#+end_src #+end_src
If you only want it for certain modes then If you only want it for certain modes, then:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(remove-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode) (remove-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
@ -133,6 +152,7 @@ If you only want it for certain modes then
* Troubleshooting * Troubleshooting
** =(error "Bad bounding indices: 0, 1")= ** =(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 This means that the text object does not have the underlying query needed. This
bound.) or [[https://github.com/nvim-treesitter/nvim-treesitter-textobjects/][contributing upstream!]] can be fixed by either adding in a custom query (which would override the
current key bound) or [[https://github.com/nvim-treesitter/nvim-treesitter-textobjects/][contributing upstream!]]