summaryrefslogtreecommitdiffstats
path: root/2022/info/treesitter-after.md
blob: f34bdb3971bba507a33c03fe70f46123bf272ddb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!-- Automatically generated by emacsconf-publish-after-page -->


<a name="treesitter-mainVideo-transcript"></a>
# Transcript

[[!template new="1" text="""Hey everyone, my name is Abin Simon""" start="00:00:00.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and this talk is about &quot;Tree-sitter:""" start="00:00:03.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Beyond Syntax Highlighting.&quot;""" start="00:00:05.080" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""For those who are not aware of what Tree-sitter is,""" start="00:00:08.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""let me give you a quick intro.""" start="00:00:10.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Tree-sitter, at its core, is a parser generator tool""" start="00:00:11.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and an incremental parsing library.""" start="00:00:17.120" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""What it essentially means is that it gives you""" start="00:00:19.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""an always up-to-date""" start="00:00:22.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""AST [abstract syntax tree] of your code.""" start="00:00:23.155" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""In the current Emacs frame, what you see to the right""" start="00:00:24.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""is the AST tree produced by Tree-sitter""" start="00:00:27.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""of the code that is on the left.""" start="00:00:30.840" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""For example, if you go to this &quot;if&quot; statement,""" start="00:00:33.560" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""you can see it goes here.""" start="00:00:37.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It is also really good at handling errors.""" start="00:00:38.840" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""For example, if I were to delete this [if statement],""" start="00:00:41.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""it still parses out a tree as much as it can,""" start="00:00:44.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""but with an error node.""" start="00:00:47.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""Now let's see how we can query the tree""" start="00:00:50.280" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""to get the information that we need.""" start="00:00:51.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's first try to get all the identifiers in the buffer.""" start="00:00:54.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It highlights all the identifiers in the buffer,""" start="00:01:01.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""but let's say we want to get something""" start="00:01:04.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""a little more precise.""" start="00:01:05.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's say we wanted to get this &quot;i&quot; here.""" start="00:01:07.280" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This, in our case, would be this identifier""" start="00:01:10.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""inside this assignment expression""" start="00:01:13.280" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""inside this &quot;for&quot; statement.""" start="00:01:15.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""We can write it out like this.""" start="00:01:27.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I hope this gives you a basic idea""" start="00:01:29.920" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""of how Tree-sitter works and how you can query""" start="00:01:31.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""to get the information that you need.""" start="00:01:34.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""First of all, let's see how Tree-sitter can help us""" start="00:01:37.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""with syntax highlighting.""" start="00:01:39.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is the default syntax highlighting by Emacs for SQL.""" start="00:01:41.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Now let's see how Tree-sitter helps.""" start="00:01:46.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is the syntax highlighting in Emacs""" start="00:01:52.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""which Tree-sitter enabled.""" start="00:01:54.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""You'll see that we're able to target""" start="00:01:56.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""a lot more things and highlight them.""" start="00:01:58.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""That said, you don't always have to""" start="00:02:01.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""highlight everything.""" start="00:02:03.139" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I personally prefer a much simpler theme.""" start="00:02:04.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""Now let's see how Tree-sitter helps you simplify""" start="00:02:15.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""adding custom syntax highlighting to your code.""" start="00:02:17.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is a Python file which has""" start="00:02:20.920" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""a class and a few member functions.""" start="00:02:22.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Anyone who has used Python will know that""" start="00:02:25.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""the &quot;self&quot; keyword, while it is passed in as an argument,""" start="00:02:27.680" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""it has more meaning than that.""" start="00:02:32.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's see if you can use Tree-sitter""" start="00:02:34.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""to highlight just the &quot;self&quot; keyword.""" start="00:02:35.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""If you look at the Tree-sitter tree,""" start="00:02:38.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""you can see that this is the first identifier""" start="00:02:40.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""in the list of parameters for a function definition.""" start="00:02:43.120" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is how you would query for the first identifier""" start="00:02:45.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""inside parameters inside a function definition.""" start="00:02:55.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Now, if you see here, it also matches &quot;cls&quot;,""" start="00:02:59.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""but let's restrict it to match just &quot;self&quot;.""" start="00:03:02.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Now we have a Tree-sitter query that identifies""" start="00:03:11.360" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""the first argument to the function definition""" start="00:03:14.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and is also called &quot;self&quot;.""" start="00:03:16.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""We can use this to apply custom highlighting onto this.""" start="00:03:19.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is pretty much all the code""" start="00:03:22.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""that you'll need to do this.""" start="00:03:25.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""The first block here is essentially to say to""" start="00:03:26.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Tree-sitter to highlight anything with python.self""" start="00:03:29.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""with the face of custom-set.""" start="00:03:32.160" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Now the second block here essentially is""" start="00:03:35.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""how we match for that.""" start="00:03:37.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Now if you go back into a Python buffer""" start="00:03:39.800" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and re-enable python-mode, we'll see that &quot;self&quot;""" start="00:03:41.800" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""is highlighted differently.""" start="00:03:44.680" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""How about creating text objects?""" start="00:03:47.120" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Tree-sitter can help there too.""" start="00:03:48.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""For those who don't know, text objects""" start="00:03:50.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""is an idea that comes from Vim,""" start="00:03:53.080" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and you can do things like select word,""" start="00:03:54.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""delete word, things like that.""" start="00:03:57.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""There are other text objects like line and paragraph.""" start="00:04:00.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""For each text object, you can have operations""" start="00:04:06.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""that are defined on them.""" start="00:04:09.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""For example, delete, copy, select, comment,""" start="00:04:09.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""all of these are operations that you can do.""" start="00:04:13.600" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's try and use Tree-sitter to add more text objects.""" start="00:04:16.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is a plugin that I wrote""" start="00:04:19.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""which lets you add more text objects into Emacs.""" start="00:04:20.560" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It helps you code aware text objects""" start="00:04:25.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""like functions, conditionals, loops, and such.""" start="00:04:27.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's see an example scenario of how""" start="00:04:31.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""something like this could come in handy.""" start="00:04:34.360" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""For example, I can select inside this condition""" start="00:04:35.920" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""or inside this function and do things like that.""" start="00:04:39.280" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's say I want to take this conditional,""" start="00:04:42.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""move to the next function, and create it here.""" start="00:04:44.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""What I would do is something like""" start="00:04:47.160" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""delete the conditional, move to the next function,""" start="00:04:49.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""create a conditional there, and paste.""" start="00:04:52.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's try another example.""" start="00:04:56.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's say I want to take this and move it to the end.""" start="00:04:57.160" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""If I had to do it without text objects,""" start="00:05:01.360" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I'd probably have to go back to the previous comma,""" start="00:05:02.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""delete till next comma, find the closing bracket,""" start="00:05:06.800" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and paste before.""" start="00:05:10.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""That works, but let's see""" start="00:05:11.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""how Tree-sitter can simplify it.""" start="00:05:14.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""With Tree-sitter, I can say delete the argument,""" start="00:05:16.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""go to the end of the next argument, and then paste.""" start="00:05:19.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Tree-sitter essentially helps Emacs""" start="00:05:22.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""understand the code better semantically.""" start="00:05:25.280" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Here is yet another use case.""" start="00:05:27.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I work at a remote company,""" start="00:05:29.600" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and I often find myself being in a call""" start="00:05:31.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""with my teammates, explaining the code to them.""" start="00:05:33.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""And one thing that really comes in handy""" start="00:05:35.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""is the narrowing capability of Emacs.""" start="00:05:38.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Specifically, the fancy-narrow package.""" start="00:05:39.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I use it to narrow just the function,""" start="00:05:43.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""or I could narrow to the conditional.""" start="00:05:44.840" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""Next to the end, the list would be code folding.""" start="00:05:48.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is a package which uses Tree-sitter""" start="00:05:51.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""to improve the code folding functionalities of Emacs.""" start="00:05:54.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Code folding has always been this thing""" start="00:05:57.560" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""that I've had a love-hate relationship with.""" start="00:06:00.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It usually works most of the time,""" start="00:06:02.280" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""but then fails if the indentation is wrong""" start="00:06:04.280" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""or we do something weird with the arguments.""" start="00:06:06.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""But now with Tree-sitter in the mix,""" start="00:06:09.160" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""it's a lot more precise.""" start="00:06:11.680" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I can fold comments, I can fold functions,""" start="00:06:12.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I can fold conditionals. You get the idea.""" start="00:06:17.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""I work with Kubernetes, which means I end up""" start="00:06:20.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""having to write and read a lot of YAML files.""" start="00:06:23.840" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""And navigating big YAML files is a mess.""" start="00:06:28.080" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""The two main problems are figuring out where I am,""" start="00:06:31.840" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and two, navigating to where I want to be.""" start="00:06:35.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's see how Tree-sitter can help us with both of this.""" start="00:06:38.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is an example YAML file.""" start="00:06:41.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""To be precise, this is the values file""" start="00:06:43.840" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""of the Redis helm chart.""" start="00:06:47.080" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I'm somewhere in the file on tag under image,""" start="00:06:48.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""but I don't know what this tag is for.""" start="00:06:52.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""But with the help of Tree-sitter,""" start="00:06:54.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I've been able to add this information""" start="00:06:57.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""into my header line.""" start="00:06:59.160" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""If you see in the header line,""" start="00:07:00.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""you'll see that I'm under sentinel.image.""" start="00:07:02.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Now let's see how this helps with navigation.""" start="00:07:05.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's say I want to enable persistence on master node.""" start="00:07:08.800" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""So with the help of Tree-sitter,""" start="00:07:12.680" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I was able to enumerate every field""" start="00:07:18.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""that is available in this YAML file,""" start="00:07:20.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and I can pass that information onto imenu,""" start="00:07:22.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""which I can then use to go to exactly where I want to.""" start="00:07:24.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Also, since we're not dealing with""" start="00:07:28.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""any language specific constructs,""" start="00:07:30.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""this is very easy to extend to""" start="00:07:32.600" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""other similar languages""" start="00:07:34.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""or config files in this case.""" start="00:07:35.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""So for example, this is a JSON file,""" start="00:07:37.440" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and I can navigate to location or project.""" start="00:07:39.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""And just like in YAML, it shows me where I'm at.""" start="00:07:44.800" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I'm in projects.name,""" start="00:07:48.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""or I'm inside projects.highlights.""" start="00:07:49.920" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Or how about Nix?""" start="00:07:52.880" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is my home.nix file.""" start="00:07:55.600" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Again, I can search for services,""" start="00:07:57.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and this lists me all the services that I've enabled.""" start="00:08:01.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""How about just services.description?""" start="00:08:04.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""So this is all the services""" start="00:08:06.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""that I've enabled and have descriptions.""" start="00:08:08.160" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""Now that we have seen this for config files,""" start="00:08:10.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""let's see how similar things apply for code.""" start="00:08:12.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Just like in config files,""" start="00:08:15.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I can see which function I'm under,""" start="00:08:16.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and if I go to the next function, it changes.""" start="00:08:18.680" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""Okay, here is something really awesome.""" start="00:08:21.560" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This is probably one of my favorites,""" start="00:08:23.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and one of the things that actually made me understand""" start="00:08:26.600" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""how powerful Tree-sitter is, and got me into it.""" start="00:08:30.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I work with a lot of Go code,""" start="00:08:34.080" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and anyone who has worked with Go will tell you""" start="00:08:35.680" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""how repetitive it is handling errors.""" start="00:08:38.840" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""For those who don't write Go,""" start="00:08:41.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""let me give you a rough idea of what I'm talking about.""" start="00:08:42.800" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""If you want to bubble up the error,""" start="00:08:45.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""the way you would do it is just to return the error""" start="00:08:47.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""to the function that called it.""" start="00:08:49.920" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Over here, you can either return nil or an empty value,""" start="00:08:51.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and at the end, you return error.""" start="00:08:55.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Let's try and use Tree-sitter to do this.""" start="00:08:57.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Using the help of Tree-sitter, let's make Emacs""" start="00:09:00.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""go back, figure out what the return arguments are,""" start="00:09:03.120" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""figure out what their default values are,""" start="00:09:06.422" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and automatically fill in the return statement.""" start="00:09:08.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It would look something like this.""" start="00:09:11.480" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""In my case, it filled in the complete form,""" start="00:09:13.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""it figured out what the return arguments are,""" start="00:09:16.120" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""what their types are,""" start="00:09:18.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and what their default values are,""" start="00:09:19.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and filled out the entire return.""" start="00:09:20.960" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""And since this is a template,""" start="00:09:22.800" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I can go to the next function, do the same thing,""" start="00:09:24.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""next function, do the same thing,""" start="00:09:27.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""next function, do the same thing.""" start="00:09:29.560" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""Here is a really fascinating use case of Tree-sitter,""" start="00:09:31.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""structural editing.""" start="00:09:34.360" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""You might be aware of plugins like paredit,""" start="00:09:36.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""which seems to &quot;know&quot; your code.""" start="00:09:38.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""This sort of takes it onto another level.""" start="00:09:40.280" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It is in its early stages, but what this lets you do""" start="00:09:42.520" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""is completely treat your code as an AST,""" start="00:09:46.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and edit as if it's a tree instead of characters.""" start="00:09:48.920" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""I am not going to go much in depth into it,""" start="00:09:52.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""but if you're interested, there is a talk""" start="00:09:54.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""from last year's EmacsConf around it.""" start="00:09:57.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""I'm just going to end this with one last tiny thing""" start="00:09:59.080" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""that I found in the tree-sitter-extras package.""" start="00:10:02.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It's this tiny macro called tree-sitter-save-excursion.""" start="00:10:04.920" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It works pretty much like save-excursion, but better.""" start="00:10:07.600" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It uses the Tree-sitter syntax tree""" start="00:10:11.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""instead of just the code""" start="00:10:13.400" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""to figure out where to restore the position.""" start="00:10:14.800" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""My main use case for this was with code formatters.""" start="00:10:16.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""Since the code moves around a lot""" start="00:10:20.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""when it gets formatted,""" start="00:10:22.080" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""save-excursion was completely useless,""" start="00:10:23.160" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""but this came in handy.""" start="00:10:25.000" video="mainVideo-treesitter" id="subtitle"]]
[[!template new="1" text="""I'll just leave you off with""" start="00:10:26.240" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""what the future of Tree-sitter looks like for Emacs.""" start="00:10:28.120" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""So far, every Tree-sitter related feature""" start="00:10:31.120" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""that I've talked about is powered by this library.""" start="00:10:33.760" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""But there is talk about Tree-sitter coming into the core.""" start="00:10:36.040" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""It will most probably be landing in Emacs 29,""" start="00:10:42.320" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""and if you want to check out the work on Tree-sitter""" start="00:10:45.840" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""in core Emacs, you can check out""" start="00:10:48.720" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""the features/tree-sitter branch.""" start="00:10:51.200" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""You'll probably see more and more features and packages""" start="00:10:52.920" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""relying upon Tree-sitter, and even major modes""" start="00:10:56.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""being powered by Tree-sitter.""" start="00:10:59.640" video="mainVideo-treesitter" id="subtitle"]]
[[!template text="""And that's a wrap from me. Thank you.""" start="00:11:01.560" video="mainVideo-treesitter" id="subtitle"]]



Captioner: sachac

Questions or comments? Please e-mail [mail@meain.io](mailto:mail@meain.io?subject=Comment%20for%20EmacsConf%202022%20treesitter%3A%20Tree-sitter%20beyond%20syntax%20highlighting)


<!-- End of emacsconf-publish-after-page -->