Skip to content

Commit 85773ab

Browse files
committed
Minor copyedits in tree-sitter starting guide
* admin/notes/tree-sitter/starter-guide: Minor copyedits. Reflow some paragraphs.
1 parent 2dacec1 commit 85773ab

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

admin/notes/tree-sitter/starter-guide

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ merged) and rebuild Emacs.
3434

3535
* Install language definitions
3636

37-
Tree-sitter by itself doesn’t know how to parse any particular
38-
language. We need to install language definitions (or “grammars”) for
39-
a language to be able to parse it. There are a couple of ways to get
40-
them.
37+
Tree-sitter by itself doesn’t know how to parse any particular language.
38+
We need to install language definitions (or “grammars”) for a language
39+
to be able to parse it. There are a couple of ways to get them.
4140

4241
You can use this script that I put together here:
4342

@@ -50,7 +49,7 @@ GNU/Linux and macOS, they can be downloaded here:
5049

5150
https://github.com/casouri/tree-sitter-module/releases/tag/v2.4
5251

53-
To build them yourself, run
52+
To build them yourself, run:
5453

5554
git clone git@github.com:casouri/tree-sitter-module.git
5655
cd tree-sitter-module
@@ -73,26 +72,25 @@ automatically download and compile the language grammar for you.
7372

7473
* Setting up for adding major mode features
7574

76-
Start Emacs and load tree-sitter with
75+
Start Emacs and load tree-sitter with:
7776

7877
(require 'treesit)
7978

80-
Now check if Emacs is built with tree-sitter library
79+
Now check if Emacs is built with tree-sitter library:
8180

8281
(treesit-available-p)
8382

84-
Make sure Emacs can find the language grammar you want to use
83+
Make sure Emacs can find the language grammar you want to use:
8584

8685
(treesit-language-available-p 'lang)
8786

8887
* Tree-sitter major modes
8988

9089
Tree-sitter modes should be separate major modes, so other modes
91-
inheriting from the original mode don't break if tree-sitter is
92-
enabled. For example js2-mode inherits js-mode, we can't enable
93-
tree-sitter in js-mode, lest js-mode would not setup things that
94-
js2-mode expects to inherit from. So it's best to use separate major
95-
modes.
90+
inheriting from the original mode don't break if tree-sitter is enabled.
91+
For example js2-mode inherits js-mode, we can't enable tree-sitter in
92+
js-mode, lest js-mode would not setup things that js2-mode expects to
93+
inherit from. So it's best to use separate major modes.
9694

9795
If the tree-sitter variant and the "native" variant could share some
9896
setup, you can create a "base mode", which only contains the common
@@ -119,19 +117,18 @@ you. The query function returns a list of (capture-name . node). For
119117
font-lock, we use face names as capture names. And the captured node
120118
will be fontified in their capture name.
121119

122-
The capture name could also be a function, in which case (NODE
123-
OVERRIDE START END) is passed to the function for fontification. START
124-
and END are the start and end of the region to be fontified. The
125-
function should only fontify within that region. The function should
126-
also allow more optional arguments with (&rest _), for future
127-
extensibility. For OVERRIDE check out the docstring of
128-
treesit-font-lock-rules.
120+
The capture name could also be a function, in which case (NODE OVERRIDE
121+
START END) is passed to the function for fontification. START and END
122+
are the start and end of the region to be fontified. The function
123+
should only fontify within that region. The function should also allow
124+
more optional arguments with (&rest _), for future extensibility. For
125+
OVERRIDE check out the docstring of treesit-font-lock-rules.
129126

130127
** Query syntax
131128

132129
There are two types of nodes, named, like (identifier),
133130
(function_definition), and anonymous, like "return", "def", "(",
134-
"}". Parent-child relationship is expressed as
131+
"}". Parent-child relationship is expressed as:
135132

136133
(parent (child) (child) (child (grand_child)))
137134

@@ -155,8 +152,7 @@ The query above captures both parent and child.
155152

156153
["return" "continue" "break"] @keyword
157154

158-
The query above captures all the keywords with capture name
159-
"keyword".
155+
The query above captures all the keywords with capture name "keyword".
160156

161157
These are the common syntax, see all of them in the manual
162158
("Parsing Program Source" section).
@@ -168,7 +164,7 @@ open any python source file, type M-x treesit-explore-mode RET. Now
168164
you should see the parse-tree in a separate window, automatically
169165
updated as you select text or edit the buffer. Besides this, you can
170166
consult the grammar of the language definition. For example, Python’s
171-
grammar file is at
167+
grammar file is at:
172168

173169
https://github.com/tree-sitter/tree-sitter-python/blob/master/grammar.js
174170

@@ -262,7 +258,7 @@ Concretely, something like this:
262258

263259
* Indent
264260

265-
Indent works like this: We have a bunch of rules that look like
261+
Indent works like this: We have a bunch of rules that look like:
266262

267263
(MATCHER ANCHOR OFFSET)
268264

@@ -354,9 +350,8 @@ Set ‘treesit-simple-imenu-settings’ and call
354350

355351
* Navigation
356352

357-
Set ‘treesit-defun-type-regexp’ and call
358-
‘treesit-major-mode-setup’. You can additionally set
359-
‘treesit-defun-name-function’.
353+
Set ‘treesit-defun-type-regexp’ and call ‘treesit-major-mode-setup’.
354+
You can additionally set ‘treesit-defun-name-function’.
360355

361356
* Which-func
362357

@@ -404,13 +399,12 @@ BTW ‘treesit-node-string’ does different things.
404399
* Manual
405400

406401
I suggest you read the manual section for tree-sitter in Info. The
407-
section is Parsing Program Source. Typing
402+
section is Parsing Program Source. Typing:
408403

409404
C-h i d m elisp RET g Parsing Program Source RET
410405

411406
will bring you to that section. You don’t need to read through every
412-
sentence, just read the text paragraphs and glance over function
413-
names.
407+
sentence, just read the text paragraphs and glance over function names.
414408

415409
* Appendix 1
416410

0 commit comments

Comments
 (0)