summaryrefslogtreecommitdiffstats
path: root/2020/subtitles/emacsconf-2020--30-a-tour-of-vterm--gabriele-bozzola-sbozzolo.vtt
blob: 183ea9f6e76dffa3b0c191f48f5e11425e0b11cb (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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
WEBVTT

00:00:00.880 --> 00:00:03.760
Hello and welcome to this talk.

00:00:03.760 --> 00:00:06.080
The title of this talk is a tour of vterm,

00:00:06.080 --> 00:00:08.559
a fast and fully featured terminal emulator

00:00:08.559 --> 00:00:10.800
inside GNU Emacs.

00:00:10.801 --> 00:00:12.719
So let's try to understand what we mean

00:00:12.720 --> 00:00:14.559
with "fast and fully featured."

00:00:14.559 --> 00:00:16.800
To do that we'll compare vterm

00:00:16.801 --> 00:00:20.400
with the packages which are built in Emacs,

00:00:20.401 --> 00:00:22.400
mainly, term.

00:00:22.400 --> 00:00:25.039
So let's jump into the vterm.

00:00:25.040 --> 00:00:26.720
So this is a vterm buffer

00:00:26.720 --> 00:00:29.439
and this is a ansi-term buffer.

00:00:29.440 --> 00:00:30.720
What I'm going to do now is

00:00:30.721 --> 00:00:32.160
first I'm going to prove to you

00:00:32.160 --> 00:00:34.160
what we mean by fast.

00:00:34.161 --> 00:00:37.440
To do that, let me open a large file display on screen--

00:00:37.441 --> 00:00:40.239
a large file, this is about one megabyte of data--

00:00:40.239 --> 00:00:41.840
and let me time that.

00:00:41.841 --> 00:00:45.200
It takes about 0.6 seconds with vterm.

00:00:45.201 --> 00:00:48.320
Let's do the same with with ansi-term.

00:00:48.321 --> 00:00:51.520
Well, we already see the difference.

00:00:51.520 --> 00:00:53.039
So I will use this time to tell you

00:00:53.039 --> 00:00:56.320
what's different, and what is vterm exactly.

00:00:56.321 --> 00:00:58.399
vterm is a terminal emulator

00:00:58.400 --> 00:01:00.800
built on top of an external library.

00:01:00.801 --> 00:01:02.719
The library is called libvterm,

00:01:02.719 --> 00:01:05.519
and is the same library used by Newton

00:01:05.519 --> 00:01:07.200
for their own terminal emulator.

00:01:07.200 --> 00:01:10.799
It's a C library, and this is what gives us

00:01:10.799 --> 00:01:15.119
a lot of good features. First, the speed.

00:01:15.119 --> 00:01:17.119
Time spent here, 0.6, is essentially

00:01:17.120 --> 00:01:18.479
the time that it takes to:

00:01:18.479 --> 00:01:22.240
1. convert the Emacs representation of text

00:01:22.241 --> 00:01:25.040
into the vterm representation of what is a string,

00:01:25.041 --> 00:01:27.360
and 2., into actually displaying that,

00:01:27.361 --> 00:01:29.520
and that can take time

00:01:29.520 --> 00:01:32.240
if there's fontification involved.

00:01:32.241 --> 00:01:34.240
So these are the 0.6 seconds there.

00:01:34.240 --> 00:01:38.479
As we say, in ansi-term, that's much more time.

00:01:38.480 --> 00:01:40.720
It's much slower. So the terminal will feel

00:01:40.721 --> 00:01:42.880
much snappier, much faster.

00:01:42.880 --> 00:01:46.720
But that's not the main benefit or the only benefit

00:01:46.721 --> 00:01:49.759
of using this external library vterm.

00:01:49.760 --> 00:01:53.040
The second big benefit is that

00:01:53.041 --> 00:01:56.560
vterm has support for all the escape codes

00:01:56.560 --> 00:01:58.320
that xterm has support for,

00:01:58.321 --> 00:02:01.119
so vterm is essentially as running xterm

00:02:01.119 --> 00:02:03.600
inside an Emacs buffer. So let's see that.

00:02:03.600 --> 00:02:05.759
For example, let's start by looking

00:02:05.760 --> 00:02:08.239
at the support for colors.

00:02:08.239 --> 00:02:10.319
We have support for all the colors out of the box.

00:02:10.320 --> 00:02:11.840
We don't have to do anything.

00:02:11.840 --> 00:02:14.720
And if we did the same here, well,

00:02:14.721 --> 00:02:16.800
we have only 20 colors.

00:02:16.801 --> 00:02:18.239
There's a way to get all the colors,

00:02:18.240 --> 00:02:19.680
but it's much more involved.

00:02:19.680 --> 00:02:23.040
But this is not where vterm shines.

00:02:23.040 --> 00:02:27.200
We can run all the commands that we want.

00:02:27.200 --> 00:02:31.440
htop, ncdu, everything runs here.

00:02:31.441 --> 00:02:35.519
Also this title, it's a fairly complicated

00:02:35.520 --> 00:02:37.920
manipulation of the window

00:02:37.921 --> 00:02:40.879
and it will not work here.

00:02:40.879 --> 00:02:42.000
It just doesn't work actually.

00:02:42.001 --> 00:02:46.160
Now the terminal is probably messed up. Yes.

00:02:46.161 --> 00:02:48.400
So using this external library

00:02:48.400 --> 00:02:50.959
removes the burden from the developers

00:02:50.959 --> 00:02:52.319
of having to implement support

00:02:52.320 --> 00:02:53.280
for all the escape codes.

00:02:53.281 --> 00:02:55.360
We just use those.

00:02:55.360 --> 00:02:58.480
So in many ways, running vterm

00:02:58.480 --> 00:03:01.760
is running xterm inside Emacs,

00:03:01.760 --> 00:03:04.159
but it's better than that because,

00:03:04.160 --> 00:03:05.840
since this is an Emacs buffer,

00:03:05.840 --> 00:03:09.760
we can enjoy a lot of features from Emacs

00:03:09.760 --> 00:03:11.360
as well as a tighter integration

00:03:11.361 --> 00:03:13.200
with Emacs itself.

00:03:13.200 --> 00:03:15.840
For example, as you see here,

00:03:15.841 --> 00:03:20.239
the title of my buffer is from the directory I'm in.

00:03:20.240 --> 00:03:21.760
So let's go to my tmp.

00:03:21.760 --> 00:03:23.440
The title will change.

00:03:23.441 --> 00:03:25.920
So there's information being exchanged

00:03:25.921 --> 00:03:28.000
between vterm and Emacs.

00:03:28.000 --> 00:03:30.000
And of course, the title is not the only place

00:03:30.001 --> 00:03:32.000
where information is exchanged.

00:03:32.000 --> 00:03:35.920
I can find a file and I will be in the directory

00:03:35.920 --> 00:03:37.680
where my terminal is.

00:03:37.681 --> 00:03:40.000
This feature is also available in ansi-term,

00:03:40.000 --> 00:03:41.360
and it works also on vterm,

00:03:41.361 --> 00:03:43.440
and it follows me. So if I go to tmp,

00:03:43.441 --> 00:03:44.720
I'll get the tmp.

00:03:44.720 --> 00:03:47.120
If I ssh to a remote server,

00:03:47.121 --> 00:03:50.239
it will work also on remote servers as well,

00:03:50.240 --> 00:03:53.920
which is a very nice way to edit files remotely

00:03:53.920 --> 00:03:55.599
while we're working on a shell.

00:03:55.600 --> 00:03:59.280
And second, while vterm is not an Elisp interpreter

00:03:59.281 --> 00:04:01.200
like eshell, what we can do is

00:04:01.201 --> 00:04:04.720
we can still run Emacs functions.

00:04:04.721 --> 00:04:06.080
So for example...

00:04:06.081 --> 00:04:08.000
that requires some configuration.

00:04:08.001 --> 00:04:11.599
vterm command (message "hi")

00:04:11.600 --> 00:04:13.120
as you see there's a "hi" here.

00:04:13.121 --> 00:04:14.959
So what I'm doing is I'm executing

00:04:14.960 --> 00:04:16.239
the Elisp function hi.

00:04:16.239 --> 00:04:18.959
I can drop that and turn it around,

00:04:18.960 --> 00:04:21.600
hash function to run Elisp functions.

00:04:21.601 --> 00:04:24.880
Or another one, find-file, same.

00:04:24.880 --> 00:04:27.360
We call this feature "message passing,"

00:04:27.361 --> 00:04:30.000
and it requires some configuration

00:04:30.001 --> 00:04:32.000
on the Emacs side as well as in the shell side.

00:04:32.000 --> 00:04:33.440
It's important to stress

00:04:33.441 --> 00:04:35.360
what's the nature of vterm.

00:04:35.360 --> 00:04:37.919
For instance, every time I'm sending a key binding,

00:04:37.920 --> 00:04:40.000
it's not immediately clear if my intention is

00:04:40.001 --> 00:04:41.840
to send it to the shell or to Emacs.

00:04:41.841 --> 00:04:44.320
So vterm implements some reasonable defaults,

00:04:44.320 --> 00:04:46.800
but at the moment it's mainly packaged

00:04:46.800 --> 00:04:49.120
to display characters on a screen.

00:04:49.120 --> 00:04:50.720
So for example, if you're using evil,

00:04:50.721 --> 00:04:52.639
the editing commands in evil

00:04:52.640 --> 00:04:54.080
will not work immediately.

00:04:54.081 --> 00:04:55.759
There's some work to be done

00:04:55.759 --> 00:04:58.160
and integration can be improved on that side,

00:04:58.161 --> 00:05:00.240
but sometimes we really want this to behave

00:05:00.240 --> 00:05:02.240
exactly like a Emacs buffer.

00:05:02.240 --> 00:05:03.680
We want to be able to search.

00:05:03.681 --> 00:05:06.639
If I try to get it to search,

00:05:06.640 --> 00:05:07.280
it will not work.

00:05:07.281 --> 00:05:08.400
I will send it to the shell.

00:05:08.401 --> 00:05:11.919
So to do that, we enabled vterm copy mode.

00:05:11.920 --> 00:05:14.720
As you see, copy mode, and now this buffer

00:05:14.721 --> 00:05:17.039
is essentially a fundamental buffer.

00:05:17.039 --> 00:05:21.120
I can move around. I can search.

00:05:21.120 --> 00:05:25.520
So it must have... I can do everything I want.

00:05:25.521 --> 00:05:26.479
And there are additional features.

00:05:26.480 --> 00:05:30.560
For example, I can jump around all the prompts.

00:05:30.561 --> 00:05:32.639
I find this extremely useful,

00:05:32.639 --> 00:05:35.039
because I can copy updates from my programs.

00:05:35.040 --> 00:05:38.320
What I always have to do is

00:05:38.321 --> 00:05:41.520
I have to Google some errors.

00:05:41.521 --> 00:05:43.120
So what I do is I select that

00:05:43.120 --> 00:05:45.120
and I have my keybinding in Emacs conf,

00:05:45.121 --> 00:05:48.479
and I'm Googling what I have to Google.

00:05:48.480 --> 00:05:51.120
So this is very nice and if I...

00:05:51.121 --> 00:05:52.639
now that I have selected something,

00:05:52.640 --> 00:05:53.840
if I just press return,

00:05:53.841 --> 00:05:56.400
I will go back to my normal editing mode

00:05:56.401 --> 00:06:00.160
with the text copied, so I can paste it back.

00:06:00.161 --> 00:06:02.720
So it's a quick way to interact with copy

00:06:02.721 --> 00:06:05.840
and interact with the output of a buffer.

00:06:05.841 --> 00:06:09.120
So finally, let's discuss how to actually use vterm.

00:06:09.121 --> 00:06:10.560
Let's circle back, let's go,

00:06:10.560 --> 00:06:12.400
and let's look at the GitHub repo

00:06:12.400 --> 00:06:14.000
where development is happening.

00:06:14.001 --> 00:06:15.520
vterm is available in MELPA,

00:06:15.520 --> 00:06:17.759
but since it's leveraging the power

00:06:17.760 --> 00:06:18.960
of an external module,

00:06:18.960 --> 00:06:20.479
you must have Emacs compiled

00:06:20.480 --> 00:06:22.000
with support for modules,

00:06:22.000 --> 00:06:25.600
and many distros like Ubuntu, Debian,

00:06:25.600 --> 00:06:26.880
that's not there. So you have to

00:06:26.881 --> 00:06:29.199
get Emacs with support for modules:

00:06:29.200 --> 00:06:31.360
compiling or getting images somewhere else.

00:06:31.361 --> 00:06:33.840
And also, the first time you are going to use this,

00:06:33.840 --> 00:06:38.960
which works only on Mac or GNU Linux systems,

00:06:38.961 --> 00:06:41.759
Emacs will try to find and compile this module,

00:06:41.759 --> 00:06:44.240
so it's important. This requirement is important.

00:06:44.241 --> 00:06:46.400
If you're using Windows, well,

00:06:46.401 --> 00:06:49.199
it's not available and will not work.

00:06:49.199 --> 00:06:53.440
So to conclude, I want to just advertise this page.

00:06:53.440 --> 00:06:56.240
If you have problems, look at the issues

00:06:56.240 --> 00:06:58.240
and open an issue in case.

00:06:58.241 --> 00:06:59.199
We'll try to help you.

00:06:59.200 --> 00:07:00.800
We are very excited about vterm,

00:07:00.800 --> 00:07:02.639
and I think it's a transformative

00:07:02.639 --> 00:07:10.319
terminal experience inside GNU Emacs.