WEBVTT

00:00.240 --> 00:00:02.639
Hi! My name is Eduardo Ochs. I'm the author of

00:02.639 --> 00:00:05.040
an Emacs package called eev, and this talk is

00:05.040 --> 00:00:07.200
about a new feature of eev called "test

00:07.200 --> 00:00:08.400
blocks".

00:08.400 --> 00:00:10.320
Let's start by a demo.

00:10.320 --> 00:00:12.559
This is a file in Lua that defines these

00:12.559 --> 00:00:14.160
two functions here,

00:14.160 --> 00:00:16.720
and if we type &lt;f8&gt; several times

00:16.720 --> 00:00:18.000
here

00:18.000 --> 00:00:20.880
the &lt;f8&gt;s create a Lua REPL - here - and

00:20.880 --> 00:00:24.400
then they send these lines to the REPL,

00:24.400 --> 00:00:27.039
where this line here loads this file

00:27.039 --> 00:00:29.679
into the REPL, and these other lines - here -

00:29.679 --> 00:00:33.200
are tests for these lines.

00:33.200 --> 00:00:35.120
There's a lot of information here, so let

00:35.120 --> 00:00:40.480
me organize them in a more visual way.

00:40.480 --> 00:00:42.960
This is our file in Lua.

00:42.960 --> 00:00:45.760
Lua sees this thing as a multi-line

00:45.760 --> 00:00:47.760
comment, but we are going to see it as a

00:47.760 --> 00:00:51.920
test block. And eev mode is active - so

00:51.920 --> 00:00:54.480
&lt;f8&gt; does the right thing.

00:54.480 --> 00:00:57.360
These three lines here set up the

00:57.360 --> 00:01:00.079
target buffer running a Lua REPL - you

01:00.079 --> 00:01:03.520
can see the the prompt of the REPL here -

01:03.520 --> 00:01:05.360
and these lines here are sent to the

01:05.360 --> 00:01:07.200
REPL.

01:07.200 --> 00:01:09.680
When we type &lt;f8&gt; on a line that

01:09.680 --> 00:01:10.720
starts

01:10.720 --> 00:01:13.600
with a red star, like these lines here,

01:13.600 --> 00:01:15.759
what &lt;f8&gt; does is that it sends the

01:15.759 --> 00:01:18.240
rest of the line - sorry, it

01:18.240 --> 00:01:21.119
executes the rest of the line as Lisp.

01:21.119 --> 00:01:23.920
So the three &lt;f8&gt;s here

01:23.920 --> 00:01:26.240
executes these lines as Lisp, and they

01:26.240 --> 00:01:29.520
set up the target buffer - here -

01:29.520 --> 00:01:31.759
and when we type &lt;f8&gt; on a line that

01:31.759 --> 00:01:34.159
does not start with a red star

01:34.159 --> 00:01:36.640
the &lt;f8&gt; sends the line to the target

01:36.640 --> 00:01:38.799
buffer and moves down.

01:38.799 --> 00:01:41.040
This line loads this file in the

01:41.040 --> 00:01:45.200
REPL, and these lines are tests.

01:45.200 --> 00:01:47.520
So we just saw how to use an existing

01:47.520 --> 00:01:50.000
test block; let's now see how to create a

01:50.000 --> 00:01:52.640
new test block. We just have to run this:

01:52.640 --> 00:01:55.680
M-x ee-insert-test-block -

01:55.680 --> 00:01:58.079
or M-x eeit.

01:58.079 --> 00:02:01.439
The result depends on the major mode.

02:01.439 --> 00:02:03.920
Let's understand that

02:03.920 --> 00:02:06.079
by looking at the source code.

02:06.079 --> 00:02:08.720
eeit is an alias to this function here,

02:08.720 --> 00:02:10.640
and this function is just five lines of

02:10.640 --> 00:02:12.800
code plus a docstring...

02:12.800 --> 00:02:14.560
and the docstring explains that if the

02:14.560 --> 00:02:16.480
major mode is foo-mode then this

02:16.480 --> 00:02:18.800
function tries to call

02:18.800 --> 00:02:21.360
a function called ee-insert-test-foo-mode

02:21.360 --> 00:02:24.800
if that function exists,

02:24.800 --> 00:02:27.280
and that if that function does not exist

02:27.280 --> 00:02:29.680
then it yields an error.

02:29.680 --> 00:02:32.080
And here's an example of one such

02:32.080 --> 00:02:34.239
function - that's a function that

02:34.239 --> 00:02:37.280
inserts a test block in haskell-mode -

02:37.280 --> 00:02:40.319
and here we can see two functions like

02:40.319 --> 00:02:42.480
this: one for haskell-mode and one for

02:42.480 --> 00:02:46.080
js-mode.

02:46.080 --> 00:02:48.560
These functions look quite similar

02:48.560 --> 00:02:49.440
but

02:49.440 --> 00:02:52.720
their effects look quite different.

02:52.720 --> 00:02:55.760
To make this comparison here i started

02:55.760 --> 00:02:57.280
by writing -

02:57.280 --> 00:02:59.680
by creating seven files, each one in a

02:59.680 --> 00:03:01.120
different language,

03:01.120 --> 00:03:03.040
and initially each one of these files

03:03.040 --> 00:03:04.959
only had a comment with the name of the

03:04.959 --> 00:03:08.239
language... so: C, Haskell, Javascript,

03:08.239 --> 00:03:10.560
Org Mode, etc -

03:10.560 --> 00:03:13.040
and in each one of these files I typed

03:13.040 --> 00:03:16.959
M-x eeit to insert a test block.

03:16.959 --> 00:03:18.800
So here we can see that these test

03:18.800 --> 00:03:20.319
blocks are different -

03:20.319 --> 00:03:22.080
for example, the syntax for multi-line

03:22.080 --> 00:03:24.000
comments is different depending on the

03:24.000 --> 00:03:25.200
language -

03:25.200 --> 00:03:27.760
this block here that selects which

03:27.760 --> 00:03:30.319
REPL to run is also different, and

03:30.319 --> 00:03:33.200
this line here that

03:33.200 --> 00:03:34.879
tells the REPL to

03:34.879 --> 00:03:37.680
load the current file is also different

03:37.680 --> 00:03:39.680
depending on the language.

03:39.680 --> 00:03:41.840
In some cases I had to improvise a bit -

03:41.840 --> 00:03:43.360
for example,

03:43.360 --> 00:03:46.400
to implement test blocks in shell mode

03:46.400 --> 00:03:48.560
I had to use this -

03:48.560 --> 00:03:52.560
this weird syntax using a here-document -

03:52.560 --> 00:03:55.280
in Tcl I also had to improvise a bit, and

03:55.280 --> 00:03:57.840
in some cases I had to improvise a lot.

03:57.840 --> 00:04:01.120
For example in Org Mode there isn't an

04:01.120 --> 00:04:03.360
obvious REPL to run, and there isn't an

04:03.360 --> 00:04:05.280
obvious way to load the

04:05.280 --> 00:04:08.080
the current Org file into the REPL, so

04:08.080 --> 00:04:11.680
the default action of M-x eeit

04:11.680 --> 00:04:14.400
in Org Mode is just to insert this thing

04:14.400 --> 00:04:15.439
here,

04:15.439 --> 00:04:17.519
that we can use to run a

04:17.519 --> 00:04:22.320
shell in a REPL.

04:22.320 --> 00:04:23.199
So

04:23.199 --> 00:04:25.680
these functions are quite similar, and in

04:25.680 --> 00:04:27.440
the beginning I was writing all of them

04:27.440 --> 00:04:29.680
by hand... but then I got bored and I wrote

04:29.680 --> 00:04:32.320
a function to help me write functions

04:32.320 --> 00:04:33.840
like that.

04:33.840 --> 00:04:35.759
This function is called

04:35.759 --> 00:04:38.080
find-eeit-links and it creates a

04:38.080 --> 00:04:39.919
temporary buffer...

04:39.919 --> 00:04:41.680
and the contents of this temporary

04:41.680 --> 00:04:43.440
buffer depends on the major mode - for

04:43.440 --> 00:04:45.680
example if the current mode is python-mode

04:45.680 --> 00:04:48.880
then running this function here

04:48.880 --> 00:04:51.840
creates a temporary buffer that lets me

04:51.840 --> 00:04:53.840
write the support for

04:53.840 --> 00:04:56.880
test blocks in python-mode, or rewrite

04:56.880 --> 00:04:59.040
the function that supports test blocks

04:59.040 --> 00:05:00.880
in python-mode.

05:00.880 --> 00:05:03.600
So if I'm in python-mode and i run this

05:03.600 --> 00:05:06.639
i get a temporary buffer like this...

05:06.639 --> 00:05:08.800
in which this thing is my template for

05:08.800 --> 00:05:11.120
the function - usually this string is

05:11.120 --> 00:05:13.039
totally wrong, I have to rewrite this

05:13.039 --> 00:05:13.919
string,

05:13.919 --> 00:05:16.400
but the rest is right - you can see python-mode

05:16.400 --> 00:05:18.720
here in the name of the function. So

05:18.720 --> 00:05:21.360
we have to edit this and save that to

05:21.360 --> 00:05:22.840
our ~/.emacs -

05:22.840 --> 00:05:25.520
and by the way these things

05:25.520 --> 00:05:28.880
here hyperlinks to many different things...

05:28.880 --> 00:05:31.600
this elisp hyperlink here

05:31.600 --> 00:05:34.160
points to the source code - to the section

05:34.160 --> 00:05:35.280
in which

05:35.280 --> 00:05:36.400
these

05:36.400 --> 00:05:38.400
functions are defined -

05:38.400 --> 00:05:40.320
so you can see this here the function

05:40.320 --> 00:05:41.759
that supports C,

05:41.759 --> 00:05:43.440
the function for Haskell, the function

05:43.440 --> 00:05:46.400
for Javascript, etc...

05:46.400 --> 00:05:49.440
and that's it! This is a five-minute talk

05:49.440 --> 00:05:50.960
so I can't say much...

05:50.960 --> 00:05:52.639
If you want more information, or if you

05:52.639 --> 00:05:55.120
want to see real-world examples, how I

05:55.120 --> 00:05:58.000
use test blocks, etc, etc, see this page

05:58.000 --> 00:06:00.479
here... and I do not have time to explain

06:00.479 --> 00:06:02.560
this "By the way" here.

06:02.560 --> 06:06.080
So that's it! Thanks! =)
