Hi! My name is Eduardo Ochs.
I'm the author of
an Emacs package called eev,
and this talk is about
a new feature of eev
called "test blocks".
Let's start by a demo.
This is a file in Lua that defines
these two functions here,
and if we type <f8> several times here,
the <f8>s create a Lua REPL here
and then they send these lines
to the REPL, where this line here
loads this file into the REPL,
and these other lines here
are tests for these lines.
There's a lot of information here,
so let me organize them
in a more visual way.
This is our file in Lua.
Lua sees this thing
as a multi-line comment,
but we are going to see it
as a test block.
And eev mode is active,
so <f8> does the right thing.
These three lines here
set up the target buffer
running a Lua REPL.
You can see the the prompt
of the REPL here,
and these lines here
are sent to the REPL.
When we type <f8>
on a line that starts
with a red star,
like these lines here,
what <f8> does is that
it sends the rest of the line--
sorry, it executes
the rest of the line as Lisp.
So the three <f8>s here
executes these lines as Lisp,
and they set up the target buffer here.
When we type <f8>
on a line that does not start
with a red star,
the <f8> sends the line
to the target buffer and moves down.
This line loads this file
in the REPL, and these lines are tests.
So we just saw how to use
an existing test block;
let's now see how to create
a new test block.
We just have to run this:
M-x ee-insert-test-block -
or M-x eeit.
The result depends on the major mode.
Let's understand that
by looking at the source code.
eeit is an alias to this function here,
and this function is just
five lines of code plus a docstring...
and the docstring explains
that if the major mode is foo-mode,
then this function tries to call
a function called ee-insert-test-foo-mode
if that function exists,
and that, if that function does not exist,
then it yields an error.
And here's an example
of one such function.
That's a function that inserts
a test block in haskell-mode.
Here we can see two functions like this:
one for haskell-mode and one for js-mode.
These functions look quite similar,
but their effects look quite different.
To make this comparison here,
I started by writing--
by creating seven files,
each one in a different language.
Initially, each one of these files
only had a comment
with the name of the language...
so: C, Haskell, Javascript, Org Mode, etc.
In each one of these files,
I typed M-x eeit to insert a test block.
So here we can see that
these test blocks are different.
For example, the syntax
for multi-line comments
is different depending on the language.
This block here that selects
which REPL to run is also different,
and this line here that tells the REPL
to load the current file
is also different,
depending on the language.
In some cases, I had to improvise a bit.
For example, to implement test blocks
in shell mode, I had to use
this weird syntax using a here-document.
In Tcl, I also had to improvise a bit,
and in some cases,
I had to improvise a lot.
For example, in Org Mode,
there isn't an obvious REPL to run,
and there isn't an obvious way
to load the the current Org file
into the REPL, so the default action
of M-x eeit in Org Mode
is just to insert this thing here,
that we can use to run a shell in a REPL.
So these functions are quite similar.
In the beginning,
I was writing all of them by hand...
but then I got bored
and I wrote a function
to help me write functions like that.
This function is called find-eeit-links,
and it creates a temporary buffer,
and the contents of this temporary buffer
depends on the major mode. For example,
if the current mode is python-mode,
then running this function here
creates a temporary buffer
that lets me write the support
for test blocks in python-mode,
or rewrite the function
that supports test blocks
in python-mode.
So if I'm in python-mode and I run this,
I get a temporary buffer like this,
in which this thing is my template
for the function. Usually, this string
is totally wrong,
I have to rewrite this string,
but the rest is right.
You can see python-mode here
in the name of the function.
So we have to edit this
and save that to our ~/.emacs.
By the way, these things here
hyperlinks to many different things...
This Elisp hyperlink here
points to the source code,
to the section in which these functions
are defined. So you can see this here,
the function that supports C,
the function for Haskell,
the function for Javascript, etc...
and that's it!
This is a five-minute talk,
so I can't say much...
If you want more information,
or if you want to see real-world examples,
how I use test blocks, etc. etc.,
see this page here...
and I do not have time to explain this
"By the way" here.
So that's it! Thanks! =)
[captions by Eduardo Ochs]