summaryrefslogblamecommitdiffstats
path: root/2022/captions/emacsconf-2022-justl--justl-driving-recipes-within-emacs--sibi-prabakaran--main.vtt
blob: cd239aa89d757d28fe76cfee582c233d679f4327 (plain) (tree)
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826

























































































































































































































































































































































































































































































































































































































































































































































































































































                                                
WEBVTT captioned by sachac

00:00:00.000 --> 00:00:04.240
Hi everyone, I am Sibi Prabakaran

00:00:04.240 --> 00:00:09.560
and welcome to my session on Justl Emacs Mode.

00:00:09.560 --> 00:00:11.640
A bit about me, I have been working

00:00:11.640 --> 00:00:12.880
as a Haskell Engineer

00:00:12.880 --> 00:00:15.600
at FPComplete for the last 4 years.

00:00:15.600 --> 00:00:17.400
I am based out of India.

00:00:17.400 --> 00:00:20.680
I occasionally blog at my website psibi.in

00:00:20.680 --> 00:00:23.560
where you can find more information about me.

00:00:23.560 --> 00:00:25.000
I have been using Emacs

00:00:25.000 --> 00:00:26.920
for more than a decade now.

00:00:26.920 --> 00:00:28.160
I help in the maintenance

00:00:28.160 --> 00:00:31.080
of the Terraform client for LSP mode.

00:00:31.080 --> 00:00:33.960
I have also authored dhall-mode and rego-mode

00:00:33.960 --> 00:00:35.000
which are the major modes

00:00:35.000 --> 00:00:39.320
for the respective languages.

00:00:39.320 --> 00:00:40.680
Before jumping into the demo

00:00:40.680 --> 00:00:42.040
of the Emacs package,

00:00:42.040 --> 00:00:44.160
I would like to give a brief introduction

00:00:44.160 --> 00:00:46.280
about justfiles and what it is.

00:00:46.280 --> 00:00:49.000
I will also try to compare it with Makefiles

00:00:49.000 --> 00:00:53.640
as it takes a lot of inspiration from it.

00:00:53.640 --> 00:00:55.640
What you see currently in the buffer

00:00:55.640 --> 00:00:57.320
is a sample justfile.

00:00:57.320 --> 00:00:59.480
If you have previously used Makefiles,

00:00:59.480 --> 00:01:00.480
you would be able to see

00:01:00.480 --> 00:01:02.280
that there is quite a bit of similarity

00:01:02.280 --> 00:01:03.560
between them.

00:01:03.560 --> 00:01:05.080
Anything that starts with hash

00:01:05.080 --> 00:01:07.120
is a documentation comment.

00:01:07.120 --> 00:01:09.160
You can see that I have the first recipe

00:01:09.160 --> 00:01:10.920
which is named as default.

00:01:10.920 --> 00:01:12.520
So if you run the just executable

00:01:12.520 --> 00:01:14.120
without any arguments,

00:01:14.120 --> 00:01:15.400
by default it is going to run

00:01:15.400 --> 00:01:17.200
the first recipe.

00:01:17.200 --> 00:01:18.440
This recipe's definition

00:01:18.440 --> 00:01:20.080
calls the just command

00:01:20.080 --> 00:01:21.920
in turn, with the two arguments,

00:01:21.920 --> 00:01:24.080
namely --list and --unsorted,

00:01:24.080 --> 00:01:25.680
which basically asks just

00:01:25.680 --> 00:01:27.800
to list down all the recipes

00:01:27.800 --> 00:01:29.680
in an unsorted order.

00:01:29.680 --> 00:01:32.400
Each line of each recipe is executed

00:01:32.400 --> 00:01:33.920
by a fresh shell.

00:01:33.920 --> 00:01:35.120
That pretty much

00:01:35.120 --> 00:01:36.360
is the high level overview

00:01:36.360 --> 00:01:38.520
of getting started to use this tool.

00:01:38.520 --> 00:01:40.760
This tool assumes the presence of a shell

00:01:40.760 --> 00:01:43.480
which is bash in most GNU/Linux systems,

00:01:43.480 --> 00:01:44.840
but you can configure it

00:01:44.840 --> 00:01:47.160
to explicitly use any specific shell

00:01:47.160 --> 00:01:48.520
you have in mind.

00:01:48.520 --> 00:01:50.480
Let me in fact go and try executing

00:01:50.480 --> 00:01:52.600
the first recipe.

00:01:52.600 --> 00:01:53.760
I will first execute it

00:01:53.760 --> 00:01:55.160
without any arguments,

00:01:55.160 --> 00:01:59.000
which will force it to run the first recipe.

00:01:59.000 --> 00:02:01.800
As you can see, it listed all the recipes.

00:02:01.800 --> 00:02:03.200
Now I can actually execute

00:02:03.200 --> 00:02:04.200
a particular recipe

00:02:04.200 --> 00:02:06.640
by passing an explicit recipe name.

00:02:06.640 --> 00:02:08.400
Let me execute the hello recipe now

00:02:08.400 --> 00:02:11.920
which will basically print "hello world".

00:02:11.920 --> 00:02:15.320
It works as expected.

00:02:15.320 --> 00:02:17.040
As you can see, that's all that's required

00:02:17.040 --> 00:02:18.600
to get started with this tool.

00:02:18.600 --> 00:02:20.348
You create a file named justfile

00:02:20.349 --> 00:02:22.800
in a directory, define some recipes

00:02:22.800 --> 00:02:23.640
and then run them

00:02:23.640 --> 00:02:27.680
via the just executable.

00:02:27.680 --> 00:02:28.440
Note that there are

00:02:28.440 --> 00:02:30.680
various other features in justfile.

00:02:30.680 --> 00:02:32.240
You can define variables,

00:02:32.240 --> 00:02:33.280
mark some variables

00:02:33.280 --> 00:02:35.520
to be exported as environment variables,

00:02:35.520 --> 00:02:37.280
have optional parameters

00:02:37.280 --> 00:02:38.800
that can be passed to a recipe.

00:02:38.800 --> 00:02:40.960
You can also set up dependency

00:02:40.960 --> 00:02:42.480
between recipes

00:02:42.480 --> 00:02:44.920
and also write scripts within a recipe

00:02:44.920 --> 00:02:46.800
in a language of your choice.

00:02:46.800 --> 00:02:48.560
I won't be going into the details,

00:02:48.560 --> 00:02:50.120
but I encourage you to go through

00:02:50.120 --> 00:02:51.640
the very helpful manual page

00:02:51.640 --> 00:02:56.440
to learn more about it.

00:02:56.440 --> 00:02:59.200
Also, let me compare it with Makefiles.

00:02:59.200 --> 00:03:00.800
I do think it's kind of unfair

00:03:00.800 --> 00:03:02.160
to compare both the tools

00:03:02.160 --> 00:03:04.760
since make is a build automation tool

00:03:04.760 --> 00:03:07.520
whereas just's goal is a task runner,

00:03:07.520 --> 00:03:09.320
and since just doesn't try to be

00:03:09.320 --> 00:03:10.440
a build system,

00:03:10.440 --> 00:03:12.480
it can avoid the associated complexity

00:03:12.480 --> 00:03:15.080
that comes with the tool like make.

00:03:15.080 --> 00:03:17.040
There is one nice historical fact

00:03:17.040 --> 00:03:18.200
about just.

00:03:18.200 --> 00:03:19.560
The initial version of just

00:03:19.560 --> 00:03:21.640
relied on make command being available,

00:03:21.640 --> 00:03:23.360
so it was basically

00:03:23.360 --> 00:03:25.440
a glorified wrapper around it.

00:03:25.440 --> 00:03:26.440
But it was removed,

00:03:26.440 --> 00:03:27.760
and justfile doesn't have

00:03:27.760 --> 00:03:29.680
that dependency anymore.

00:03:29.680 --> 00:03:31.680
If you are using make as a task runner

00:03:31.680 --> 00:03:33.400
then you would have to use

00:03:33.400 --> 00:03:35.400
something called phony targets.

00:03:35.400 --> 00:03:37.240
I don't want to go into the details,

00:03:37.240 --> 00:03:39.240
but makefiles have good reason

00:03:39.240 --> 00:03:41.040
for why they need something like that.

00:03:41.040 --> 00:03:44.080
Since justfile is not a build system,

00:03:44.080 --> 00:03:45.200
it doesn't have to deal with them.

00:03:45.200 --> 00:03:47.400
The error message

00:03:47.400 --> 00:03:48.680
and user experience of this tool,

00:03:48.680 --> 00:03:50.480
in my opinion, is better.

00:03:50.480 --> 00:03:52.760
To show you a concrete example,

00:03:52.760 --> 00:03:54.920
justfile errors out by default

00:03:54.920 --> 00:03:56.400
if you have duplicate recipes.

00:03:56.400 --> 00:03:58.840
This is in contrast with make

00:03:58.840 --> 00:04:00.720
where I believe it prints out

00:04:00.720 --> 00:04:01.760
a warning about it,

00:04:01.760 --> 00:04:03.840
but still executes the target action.

00:04:03.840 --> 00:04:06.600
Justfile also gives you the ability

00:04:06.600 --> 00:04:08.200
to easily create scripts

00:04:08.200 --> 00:04:10.680
written in any language within a recipe.

00:04:10.680 --> 00:04:12.680
My personal opinion is that

00:04:12.680 --> 00:04:14.200
if you are using makefile

00:04:14.200 --> 00:04:15.200
as a task runner,

00:04:15.200 --> 00:04:17.440
you might want to check out justfile

00:04:17.440 --> 00:04:19.280
to see if it will suit your workflow.

00:04:19.280 --> 00:04:25.000
With that, I'll move on to justl.el,

00:04:25.000 --> 00:04:26.800
which is basically an Emacs package

00:04:26.800 --> 00:04:28.120
for driving justfiles.

00:04:28.120 --> 00:04:29.920
I started writing this tool

00:04:29.920 --> 00:04:31.200
around a year ago

00:04:31.200 --> 00:04:33.720
when my usage of justfile increased.

00:04:33.720 --> 00:04:35.440
The objective of the tool

00:04:35.440 --> 00:04:37.480
is to reduce the usage of the CLI

00:04:37.480 --> 00:04:40.040
and drive the execution of the recipes

00:04:40.040 --> 00:04:41.480
natively within the editor.

00:04:41.480 --> 00:04:44.000
Let me take you back to the justfile

00:04:44.000 --> 00:04:45.240
which we saw previously.

00:04:45.240 --> 00:04:47.320
This time we will drive it

00:04:47.320 --> 00:04:48.840
within the editor itself,

00:04:48.840 --> 00:04:51.400
instead of executing commands via vterm

00:04:51.400 --> 00:04:52.400
as done previously.

00:04:52.400 --> 00:04:54.640
So the idea is you either

00:04:54.640 --> 00:04:56.000
open the justfile,

00:04:56.000 --> 00:04:57.840
or any other file in the directory.

00:04:57.840 --> 00:04:59.160
That doesn't matter, actually.

00:04:59.160 --> 00:05:00.720
Once you do that,

00:05:00.720 --> 00:05:02.360
you call the justl command.

00:05:02.360 --> 00:05:06.640
Now as you can see, it lists down

00:05:06.640 --> 00:05:07.520
all the recipes,

00:05:07.520 --> 00:05:09.280
along with the description if present.

00:05:09.280 --> 00:05:11.520
You can move on to different recipes

00:05:11.520 --> 00:05:13.080
by your usual keybinding.

00:05:13.080 --> 00:05:15.680
And for executing a specific recipe,

00:05:15.680 --> 00:05:18.240
you have to press the e keybinding,

00:05:18.240 --> 00:05:19.720
and that will run the recipe

00:05:19.720 --> 00:05:21.600
and show its output

00:05:21.600 --> 00:05:23.400
on a special buffer named *just*

00:05:23.400 --> 00:05:25.000
which is built on top of

00:05:25.000 --> 00:05:27.040
the compilation mode available in Emacs.

00:05:27.040 --> 00:05:28.760
Let me actually try

00:05:28.760 --> 00:05:30.240
executing the hello recipe

00:05:30.240 --> 00:05:32.440
which we previously executed in vterm.

00:05:32.440 --> 00:05:38.160
As you can see,

00:05:38.160 --> 00:05:39.680
it executed the recipe

00:05:39.680 --> 00:05:41.120
and the "hello world" output

00:05:41.120 --> 00:05:42.400
is visible in the just buffer.

00:05:42.400 --> 00:05:44.400
You can also see that there is

00:05:44.400 --> 00:05:45.880
other metadata like

00:05:45.880 --> 00:05:47.480
when it started executing

00:05:47.480 --> 00:05:49.520
and when did it finish executing.

00:05:49.520 --> 00:05:51.520
If a recipe execution fails,

00:05:51.520 --> 00:05:53.160
it will also change the color

00:05:53.160 --> 00:05:55.760
and print the corresponding exit code.

00:05:55.760 --> 00:05:57.320
Let me actually show you

00:05:57.320 --> 00:05:59.080
by modifying the hello recipe

00:05:59.080 --> 00:06:03.600
and making it exit.

00:06:03.600 --> 00:06:08.400
As you can see,

00:06:08.400 --> 00:06:10.480
it clearly indicates the error message now.

00:06:10.480 --> 00:06:12.720
That is a pretty much

00:06:12.720 --> 00:06:14.240
a good high level overview

00:06:14.240 --> 00:06:15.680
of how to execute recipes

00:06:15.680 --> 00:06:17.280
using this Emacs extension.

00:06:17.280 --> 00:06:21.720
If I press the h or the ? key,

00:06:21.720 --> 00:06:23.520
it will display the various ways

00:06:23.520 --> 00:06:24.160
to drive it.

00:06:24.160 --> 00:06:27.480
Now as you can see,

00:06:27.480 --> 00:06:29.320
you can pass various options to it.

00:06:29.320 --> 00:06:31.600
I find the dry run option effective

00:06:31.600 --> 00:06:34.560
whenever I have to print the recipe contents

00:06:34.560 --> 00:06:36.600
without actually executing the recipe.

00:06:36.600 --> 00:06:39.720
There are also various ways to execute it.

00:06:39.720 --> 00:06:42.960
You can use Emacs's eshell to execute it

00:06:42.960 --> 00:06:45.040
by pressing the E keybinding.

00:06:45.040 --> 00:06:48.400
Let me try executing the hello recipe again,

00:06:48.400 --> 00:06:50.760
but this time via Emacs's eshell.

00:06:50.760 --> 00:06:54.840
As you can see now I have an eshell instance

00:06:54.840 --> 00:06:57.320
where it executed the just hello recipe.

00:06:57.320 --> 00:07:02.440
You can also directly

00:07:02.440 --> 00:07:03.680
go to the recipe line

00:07:03.680 --> 00:07:05.000
by pressing the return key.

00:07:05.000 --> 00:07:08.040
So let's say if I want to

00:07:08.040 --> 00:07:09.360
go to the recipe build app

00:07:09.360 --> 00:07:12.160
all I have to do is press the return key

00:07:12.160 --> 00:07:14.400
and it will go to the just file

00:07:14.400 --> 00:07:15.520
with the proper line.

00:07:15.520 --> 00:07:19.800
You can also re-execute the same recipe

00:07:19.800 --> 00:07:21.320
from the output just buffer.

00:07:21.320 --> 00:07:23.320
I find this very helpful

00:07:23.320 --> 00:07:25.080
when iterating on certain things.

00:07:25.080 --> 00:07:26.720
In my day job,

00:07:26.720 --> 00:07:29.240
I often have to work with a Kubernetes cluster,

00:07:29.240 --> 00:07:30.480
and I would have to write

00:07:30.480 --> 00:07:33.360
resource manifest files for applications.

00:07:33.360 --> 00:07:36.376
Having the ability to run the recipes

00:07:36.377 --> 00:07:37.942
while iterating on the project

00:07:37.943 --> 00:07:39.560
is very useful, in my opinion.

00:07:39.560 --> 00:07:42.000
Let me actually show you

00:07:42.000 --> 00:07:43.680
an example of what I am talking about.

00:07:43.680 --> 00:07:46.680
Let me run the build app recipe now,

00:07:46.680 --> 00:07:48.400
which will basically build the manifest

00:07:48.400 --> 00:07:49.600
and print it out.

00:07:49.600 --> 00:07:58.160
Now let me open one of the application files.

00:07:58.160 --> 00:07:59.960
I will open the ingress.yaml file.

00:07:59.960 --> 00:08:06.120
So I have this YAML file which I am working on,

00:08:06.120 --> 00:08:08.600
and I also have this output buffer

00:08:08.600 --> 00:08:10.160
which is basically the output

00:08:10.160 --> 00:08:11.840
of the build app recipe.

00:08:11.840 --> 00:08:14.200
Now I can basically go through this buffer

00:08:14.200 --> 00:08:18.320
and see if everything is alright,

00:08:18.320 --> 00:08:21.760
but I find out that I didn't want

00:08:21.760 --> 00:08:23.920
the hostname to be emacs2022.

00:08:23.920 --> 00:08:25.840
I wanted it to be just emacs.

00:08:25.840 --> 00:08:29.000
I can go and fix it in my YAML file,

00:08:29.000 --> 00:08:34.160
and then I can go on

00:08:34.160 --> 00:08:36.160
to the output buffer

00:08:36.160 --> 00:08:38.520
and basically just re-run the command

00:08:38.520 --> 00:08:40.080
by pressing the g key binding.

00:08:40.080 --> 00:08:42.800
As you can see,

00:08:42.800 --> 00:08:48.160
it executed the same recipe again,

00:08:48.160 --> 00:08:49.440
and I can see that

00:08:49.440 --> 00:08:51.280
the hostname is indeed emacs.

00:08:51.280 --> 00:08:55.000
I find this kind of workflow very convenient

00:08:55.000 --> 00:08:56.600
while I am working on a project.

00:08:56.600 --> 00:08:59.320
Another way of interacting

00:08:59.320 --> 00:09:00.440
with the justl extension

00:09:00.440 --> 00:09:02.400
is by using the interactive function

00:09:02.400 --> 00:09:04.280
justl-exec-recipe-in-dir.

00:09:04.280 --> 00:09:06.040
The use case of this function

00:09:06.040 --> 00:09:07.840
is executing a one-off recipe

00:09:07.840 --> 00:09:09.920
while you are working on something else.

00:09:09.920 --> 00:09:11.960
Let me show you an example of it.

00:09:11.960 --> 00:09:19.800
As you can see, it shows me

00:09:19.800 --> 00:09:21.320
a drop down of various recipes

00:09:21.320 --> 00:09:22.640
available in the justfile.

00:09:22.640 --> 00:09:24.880
You can choose any particular one

00:09:24.880 --> 00:09:26.800
and execute the corresponding recipe.

00:09:26.800 --> 00:09:28.360
In this case, I will choose

00:09:28.360 --> 00:09:29.640
the build-app recipe,

00:09:29.640 --> 00:09:31.320
and we will get the output

00:09:31.320 --> 00:09:32.280
in the *just* buffer

00:09:32.280 --> 00:09:33.200
which should be similar

00:09:33.200 --> 00:09:34.680
to what we saw previously.

00:09:34.680 --> 00:09:43.920
So this was a quick introduction

00:09:43.920 --> 00:09:45.120
to what justfile is

00:09:45.120 --> 00:09:46.800
and how to drive them within Emacs.

00:09:46.800 --> 00:09:48.600
Hopefully it was helpful

00:09:48.600 --> 00:09:50.160
and it would encourage you

00:09:50.160 --> 00:09:51.480
to use justfiles in your workflow.

00:09:51.480 --> 00:09:53.800
Thank you for allowing me to present.

00:09:53.800 --> 00:09:55.480
I am available in IRC

00:09:55.480 --> 00:10:02.040
if you have any questions.