summaryrefslogtreecommitdiffstats
path: root/2021/captions/emacsconf-2021-test--test-blocks--eduardo-ochs--main.vtt
diff options
context:
space:
mode:
Diffstat (limited to '2021/captions/emacsconf-2021-test--test-blocks--eduardo-ochs--main.vtt')
-rw-r--r--2021/captions/emacsconf-2021-test--test-blocks--eduardo-ochs--main.vtt493
1 files changed, 493 insertions, 0 deletions
diff --git a/2021/captions/emacsconf-2021-test--test-blocks--eduardo-ochs--main.vtt b/2021/captions/emacsconf-2021-test--test-blocks--eduardo-ochs--main.vtt
new file mode 100644
index 00000000..f41f699b
--- /dev/null
+++ b/2021/captions/emacsconf-2021-test--test-blocks--eduardo-ochs--main.vtt
@@ -0,0 +1,493 @@
+WEBVTT
+
+00:00.240 --> 00:00:01.839
+Hi! My name is Eduardo Ochs.
+
+00:00:01.839 --> 00:00:02.639
+I'm the author of
+
+00:00:02.639 --> 00:00:04.319
+an Emacs package called eev,
+
+00:00:04.319 --> 00:00:05.279
+and this talk is about
+
+00:00:05.279 --> 00:00:06.480
+a new feature of eev
+
+00:00:06.480 --> 00:00:08.400
+called "test blocks".
+
+00:08.400 --> 00:00:10.320
+Let's start by a demo.
+
+00:10.320 --> 00:00:12.320
+This is a file in Lua that defines
+
+00:00:12.320 --> 00:00:14.160
+these two functions here,
+
+00:14.160 --> 00:00:18.000
+and if we type <f8> several times here,
+
+00:18.000 --> 00:00:20.720
+the <f8>s create a Lua REPL here
+
+00:00:20.720 --> 00:00:22.240
+and then they send these lines
+
+00:00:22.240 --> 00:00:25.840
+to the REPL, where this line here
+
+00:00:25.840 --> 00:00:27.840
+loads this file into the REPL,
+
+00:00:27.840 --> 00:00:29.679
+and these other lines here
+
+00:29.679 --> 00:00:33.200
+are tests for these lines.
+
+00:33.200 --> 00:00:34.719
+There's a lot of information here,
+
+00:00:34.719 --> 00:00:36.160
+so let me organize them
+
+00:00:36.160 --> 00:00:40.480
+in a more visual way.
+
+00:40.480 --> 00:00:42.960
+This is our file in Lua.
+
+00:42.960 --> 00:00:44.559
+Lua sees this thing
+
+00:00:44.559 --> 00:00:46.160
+as a multi-line comment,
+
+00:00:46.160 --> 00:00:47.520
+but we are going to see it
+
+00:00:47.520 --> 00:00:48.879
+as a test block.
+
+00:00:48.879 --> 00:00:50.879
+And eev mode is active,
+
+00:00:50.879 --> 00:00:54.480
+so <f8> does the right thing.
+
+00:54.480 --> 00:00:56.800
+These three lines here
+
+00:00:56.800 --> 00:00:58.320
+set up the target buffer
+
+00:00:58.320 --> 00:01:00.000
+running a Lua REPL.
+
+00:01:00.000 --> 00:01:02.079
+You can see the the prompt
+
+00:01:02.079 --> 00:01:03.520
+of the REPL here,
+
+01:03.520 --> 00:01:04.640
+and these lines here
+
+00:01:04.640 --> 00:01:07.200
+are sent to the REPL.
+
+01:07.200 --> 00:01:08.960
+When we type <f8>
+
+00:01:08.960 --> 00:01:10.720
+on a line that starts
+
+01:10.720 --> 00:01:11.680
+with a red star,
+
+00:01:11.680 --> 00:01:13.600
+like these lines here,
+
+01:13.600 --> 00:01:15.119
+what <f8> does is that
+
+00:01:15.119 --> 00:01:17.537
+it sends the rest of the line--
+
+00:01:17.537 --> 00:01:18.880
+sorry, it executes
+
+00:01:18.880 --> 00:01:21.119
+the rest of the line as Lisp.
+
+01:21.119 --> 00:01:23.920
+So the three <f8>s here
+
+01:23.920 --> 00:01:26.000
+executes these lines as Lisp,
+
+00:01:26.000 --> 00:01:29.520
+and they set up the target buffer here.
+
+01:29.520 --> 00:01:31.119
+When we type <f8>
+
+00:01:31.119 --> 00:01:32.720
+on a line that does not start
+
+00:01:32.720 --> 00:01:34.159
+with a red star,
+
+00:01:34.159 --> 00:01:35.680
+the <f8> sends the line
+
+00:01:35.680 --> 00:01:38.799
+to the target buffer and moves down.
+
+01:38.799 --> 00:01:40.619
+This line loads this file
+
+00:01:40.619 --> 00:01:45.200
+in the REPL, and these lines are tests.
+
+01:45.200 --> 00:01:46.799
+So we just saw how to use
+
+00:01:46.799 --> 00:01:48.240
+an existing test block;
+
+00:01:48.240 --> 00:01:49.840
+let's now see how to create
+
+00:01:49.840 --> 00:01:51.280
+a new test block.
+
+00:01:51.280 --> 00:01:52.640
+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:09.920
+and this function is just
+
+00:02:09.920 --> 00:02:12.800
+five lines of code plus a docstring...
+
+02:12.800 --> 00:02:14.160
+and the docstring explains
+
+00:02:14.160 --> 00:02:15.920
+that if the major mode is foo-mode,
+
+00:02:15.920 --> 00:02:18.800
+then this 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:31.120
+And here's an example
+
+00:02:31.120 --> 00:02:32.560
+of one such function.
+
+00:02:32.560 --> 00:02:34.800
+That's a function that inserts
+
+00:02:34.800 --> 00:02:37.280
+a test block in haskell-mode.
+
+02:37.280 --> 00:02:40.959
+Here we can see two functions like this:
+
+00:02:40.959 --> 00:02:46.080
+one for haskell-mode and one for js-mode.
+
+02:46.080 --> 00:02:48.560
+These functions look quite similar,
+
+00:02:48.560 --> 00:02:52.720
+but their effects look quite different.
+
+02:52.720 --> 00:02:54.800
+To make this comparison here,
+
+00:02:54.800 --> 00:02:57.280
+I started by writing--
+
+02:57.280 --> 00:02:59.040
+by creating seven files,
+
+00:02:59.040 --> 00:03:01.120
+each one in a different language.
+
+03:01.120 --> 00:03:03.040
+Initially, each one of these files
+
+03:03.040 --> 00:03:04.159
+only had a comment
+
+00:03:04.159 --> 00:03:06.403
+with the name of the language...
+
+00:03:06.403 --> 00:03:10.560
+so: C, Haskell, Javascript, Org Mode, etc.
+
+03:10.560 --> 00:03:12.560
+In each one of these files,
+
+00:03:12.560 --> 00:03:16.959
+I typed M-x eeit to insert a test block.
+
+03:16.959 --> 00:03:18.319
+So here we can see that
+
+00:03:18.319 --> 00:03:20.319
+these test blocks are different.
+
+03:20.319 --> 00:03:21.440
+For example, the syntax
+
+00:03:21.440 --> 00:03:22.560
+for multi-line comments
+
+00:03:22.560 --> 00:03:25.200
+is different depending on the language.
+
+03:25.200 --> 00:03:27.440
+This block here that selects
+
+00:03:27.440 --> 00:03:30.100
+which REPL to run is also different,
+
+00:03:30.100 --> 00:03:34.080
+and this line here that tells the REPL
+
+00:03:34.080 --> 00:03:36.000
+to load the current file
+
+00:03:36.000 --> 00:03:37.680
+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:45.360
+For example, to implement test blocks
+
+00:03:45.360 --> 00:03:48.560
+in shell mode, I had to use
+
+03:48.560 --> 00:03:52.560
+this weird syntax using a here-document.
+
+03:52.560 --> 00:03:55.040
+In Tcl, I also had to improvise a bit,
+
+00:03:55.040 --> 00:03:55.920
+and in some cases,
+
+00:03:55.920 --> 00:03:57.840
+I had to improvise a lot.
+
+03:57.840 --> 00:04:00.159
+For example, in Org Mode,
+
+00:04:00.159 --> 00:04:02.400
+there isn't an obvious REPL to run,
+
+00:04:02.400 --> 00:04:03.840
+and there isn't an obvious way
+
+00:04:03.840 --> 00:04:06.480
+to load the the current Org file
+
+00:04:06.480 --> 00:04:09.360
+into the REPL, so the default action
+
+00:04:09.360 --> 00:04:12.560
+of M-x eeit in Org Mode
+
+00:04:12.560 --> 00:04:15.439
+is just to insert this thing here,
+
+04:15.439 --> 00:04:22.320
+that we can use to run a shell in a REPL.
+
+04:22.320 --> 00:04:25.280
+So these functions are quite similar.
+
+00:04:25.280 --> 00:04:26.240
+In the beginning,
+
+00:04:26.240 --> 00:04:27.919
+I was writing all of them by hand...
+
+00:04:27.919 --> 00:04:29.120
+but then I got bored
+
+00:04:29.120 --> 00:04:30.160
+and I wrote a function
+
+00:04:30.160 --> 00:04:33.840
+to help me write functions like that.
+
+04:33.840 --> 00:04:37.280
+This function is called find-eeit-links,
+
+00:04:37.280 --> 00:04:39.919
+and it creates a temporary buffer,
+
+04:39.919 --> 00:04:42.080
+and the contents of this temporary buffer
+
+00:04:42.080 --> 00:04:44.320
+depends on the major mode. For example,
+
+00:04:44.320 --> 00:04:45.680
+if the current mode is python-mode,
+
+04:45.680 --> 00:04:48.880
+then running this function here
+
+04:48.880 --> 00:04:50.160
+creates a temporary buffer
+
+00:04:50.160 --> 00:04:53.120
+that lets me write the support
+
+00:04:53.120 --> 00:04:55.440
+for test blocks in python-mode,
+
+00:04:55.440 --> 00:04:57.440
+or rewrite the function
+
+00:04:57.440 --> 00:04:59.040
+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.639
+in which this thing is my template
+
+00:05:08.639 --> 00:05:11.039
+for the function. Usually, this string
+
+00:05:11.039 --> 00:05:11.919
+is totally wrong,
+
+00:05:11.919 --> 00:05:13.919
+I have to rewrite this string,
+
+05:13.919 --> 00:05:14.960
+but the rest is right.
+
+00:05:14.960 --> 00:05:16.960
+You can see python-mode here
+
+00:05:16.960 --> 00:05:18.479
+in the name of the function.
+
+00:05:18.479 --> 00:05:20.080
+So we have to edit this
+
+00:05:20.080 --> 00:05:22.840
+and save that to our ~/.emacs.
+
+05:22.840 --> 00:05:26.080
+By the way, these things here
+
+00:05:26.080 --> 00:05:28.880
+hyperlinks to many different things...
+
+05:28.880 --> 00:05:31.600
+This Elisp hyperlink here
+
+05:31.600 --> 00:05:32.880
+points to the source code,
+
+00:05:32.880 --> 00:05:36.880
+to the section in which these functions
+
+00:05:36.880 --> 00:05:39.919
+are defined. So you can see this here,
+
+00:05:39.919 --> 00:05:41.759
+the function that supports C,
+
+05:41.759 --> 00:05:42.800
+the function for Haskell,
+
+00:05:42.800 --> 00:05:46.400
+the function for Javascript, etc...
+
+05:46.400 --> 00:05:47.520
+and that's it!
+
+00:05:47.520 --> 00:05:49.440
+This is a five-minute talk,
+
+00:05:49.440 --> 00:05:50.960
+so I can't say much...
+
+05:50.960 --> 00:05:52.320
+If you want more information,
+
+00:05:52.320 --> 00:05:54.800
+or if you want to see real-world examples,
+
+00:05:54.800 --> 00:05:57.280
+how I use test blocks, etc. etc.,
+
+00:05:57.280 --> 00:05:58.639
+see this page here...
+
+00:05:58.639 --> 00:06:01.253
+and I do not have time to explain this
+
+00:06:01.253 --> 00:06:02.560
+"By the way" here.
+
+06:02.560 --> 06:03.333
+So that's it! Thanks! =)
+
+06:03.333 --> 06:04.333
+[captions by Eduardo Ochs]