WEBVTT captioned by sachac, verified by wouter NOTE Introduction 00:00:01.887 --> 00:00:04.610 Hi everyone, my name is Wouter and I want to 00:00:04.730 --> 00:00:08.795 share something silly I've made with Emacs. 00:00:08.855 --> 00:00:09.755 But as you can see, 00:00:09.756 --> 00:00:11.218 I'm not starting with Emacs. 00:00:11.238 --> 00:00:15.302 So my day job as a lecturer 00:00:15.303 --> 00:00:16.780 in applied computing science 00:00:16.781 --> 00:00:19.588 means unfortunately I have to work a lot 00:00:19.728 --> 00:00:23.332 in Java environments, hence IntelliJ. 00:00:23.873 --> 00:00:25.794 I know LSPs are also there in Emacs, 00:00:25.795 --> 00:00:28.491 but they're not there yet. 00:00:28.912 --> 00:00:33.780 And something in IntelliJ and the really awesome 00:00:33.820 --> 00:00:35.622 tools of the Jetbrains people, 00:00:38.006 --> 00:00:40.911 That's a functionality that's there I want to 00:00:40.991 --> 00:00:43.475 show you which is called Local History and that 00:00:43.535 --> 00:00:46.520 was something I was really missing in Emacs. 00:00:46.540 --> 00:00:47.942 So I made my own. 00:00:48.547 --> 00:00:50.630 I'm not really sure if it's the best version, but 00:00:50.690 --> 00:00:51.852 let's first see. NOTE The problem 00:00:51.892 --> 00:00:54.716 So I've been working all morning on some silly 00:00:54.756 --> 00:00:57.200 example projects, how to show students how to 00:00:57.240 --> 00:01:00.024 write unit tests for Spring Boot projects. 00:01:00.044 --> 00:01:02.407 And what if I made a silly mistake and I want to 00:01:02.588 --> 00:01:06.253 look back at something I've written and take that 00:01:06.313 --> 00:01:07.435 back out of the history? 00:01:07.915 --> 00:01:10.940 The problem is that this thing is not yet on a 00:01:11.000 --> 00:01:13.984 version control, so I can't do a git log, git 00:01:14.044 --> 00:01:15.246 history, blah, blah, blah. 00:01:15.985 --> 00:01:19.752 So I can't take this out of version control. 00:01:21.314 --> 00:01:23.217 Even if I would have committed something, 00:01:23.218 --> 00:01:27.065 suppose I did something like this: 00:01:27.085 --> 00:01:30.290 I added a single line, blah, blah, 00:01:30.952 --> 00:01:33.797 and then went on about my day, ran a unit test, 00:01:33.817 --> 00:01:36.081 and then was like, okay, now maybe I don't need 00:01:36.101 --> 00:01:37.002 that line after all, 00:01:37.343 --> 00:01:38.004 and then commit. 00:01:38.485 --> 00:01:40.288 So that line would 00:01:40.690 --> 00:01:43.433 never reach it inside version control, 00:01:43.434 --> 00:01:46.037 so I would not be able to get that back. 00:01:46.038 --> 00:01:48.420 Of course, in my case, because this is a Mac, 00:01:48.421 --> 00:01:53.207 `Cmd-z` for undoing will just get this thing back, 00:01:53.208 --> 00:01:56.392 but what if I need persistent undo history, 00:01:56.393 --> 00:01:59.617 and that will be gone forever. NOTE Local history in IntelliJ 00:01:59.618 --> 00:02:00.858 Unless you do something like this: 00:02:00.859 --> 00:02:03.844 local history, show history, and then you 00:02:03.884 --> 00:02:06.748 can see exactly what I did 00:02:08.145 --> 00:02:12.632 and which changes I made for this particular file. 00:02:12.652 --> 00:02:14.093 So I added `jsonPath` 00:02:14.094 --> 00:02:16.637 instead of using the `expectBody` here. 00:02:17.618 --> 00:02:20.502 The exact content does not matter for this talk at all. 00:02:20.522 --> 00:02:27.651 But the idea is that I want to preserve that local history. 00:02:27.671 --> 00:02:28.813 All right. 00:02:28.833 --> 00:02:32.938 So let me kill IntelliJ for now. NOTE Emacs 00:02:33.796 --> 00:02:36.520 How do I do this in Emacs? 00:02:36.540 --> 00:02:39.443 So this is a part of the Dutch course I've been 00:02:39.463 --> 00:02:42.127 writing related to the exercise that you just saw. 00:02:43.128 --> 00:02:46.993 I wrote a simple function in Emacs Lisp that 00:02:47.034 --> 00:02:47.995 does exactly that. 00:02:48.015 --> 00:02:55.365 If I get my file history, `h` for history, then 00:02:55.385 --> 00:02:58.409 you can see more or less the same thing. 00:02:58.449 --> 00:03:02.554 So now this is a diff for recent versions. 00:03:02.821 --> 00:03:09.478 For instance, if I select this one, this is a 00:03:09.538 --> 00:03:10.601 consult mini-buffer. 00:03:11.242 --> 00:03:14.170 If I select this one, then you can see I opened 00:03:14.210 --> 00:03:16.375 up another buffer and split the screen 00:03:17.080 --> 00:03:21.065 next to it, which is a simple diff using the 00:03:21.105 --> 00:03:24.710 built-in Emacs version . If I just press `n` for 00:03:24.750 --> 00:03:27.674 next, next, next, you can see the differences. 00:03:27.734 --> 00:03:30.638 Now, for each chunk, I can decide to revert 00:03:30.678 --> 00:03:34.524 something, or at least see whatever the hell it 00:03:34.584 --> 00:03:38.429 was that I did in the past few hours. If I'm 00:03:38.469 --> 00:03:40.652 not interested in this at all, then I just press `q` 00:03:41.433 --> 00:03:44.337 and this thing is completely gone. 00:03:44.873 --> 00:03:47.636 The same problem here applies as well, or problem, 00:03:48.037 --> 00:03:50.179 maybe it's a feature. This thing is not yet on 00:03:50.239 --> 00:03:50.920 version control. 00:03:50.960 --> 00:03:53.102 So this particular file, 00:03:53.103 --> 00:03:55.525 I have not yet committed this in Git. 00:03:55.545 --> 00:03:57.187 So it relies on something else. 00:03:57.327 --> 00:03:59.189 And that something, of course, 00:03:59.190 --> 00:04:04.816 is still Emacs's built-in functionality to backup files. 00:04:06.678 --> 00:04:09.081 The first thing you would probably say is why 00:04:09.141 --> 00:04:12.585 don't you just use the many 00:04:13.055 --> 00:04:17.360 built-in undo versions or 00:04:17.540 --> 00:04:21.604 functionality stuff or visual undo, vundo, 00:04:21.605 --> 00:04:22.707 which I do use. 00:04:23.287 --> 00:04:26.430 But if you work a lot in the same file, 00:04:26.431 --> 00:04:29.314 as you can see, 00:04:29.315 --> 00:04:34.500 this file is a Markdown file that's 5,400 words long, 00:04:34.501 --> 00:04:38.406 so it can be a bit cumbersome to work with. 00:04:38.866 --> 00:04:40.328 So let's see. NOTE Vundo 00:04:40.882 --> 00:04:45.227 What happens if I just call vundo or use my 00:04:45.287 --> 00:04:47.610 shortcut? That would make things a bit more 00:04:47.670 --> 00:04:49.993 difficult for you guys to follow. 00:04:50.013 --> 00:04:51.634 So I'll just press `RET` 00:04:51.635 --> 00:04:54.118 and start a vundo mini-buffer. 00:04:55.440 --> 00:04:59.084 Now I can try to make sense of all this. 00:04:59.104 --> 00:05:01.066 Somehow, maybe I need... 00:05:01.067 --> 00:05:03.970 let's see the version on the second row. 00:05:04.928 --> 00:05:07.392 Maybe this one, and then I can see the 00:05:07.452 --> 00:05:09.754 differences by pressing `d`, 00:05:09.755 --> 00:05:13.921 and then vundo opens another similar diff 00:05:13.922 --> 00:05:16.085 as the one that I made myself. 00:05:16.145 --> 00:05:17.466 You can see I was typing 00:05:17.467 --> 00:05:21.933 `als je controller een object`, 00:05:21.934 --> 00:05:27.082 which is Dutch, and I was starting a sentence. 00:05:27.102 --> 00:05:29.746 That's okay for small edits or for small files, 00:05:29.826 --> 00:05:32.370 but... Even if you increase the history, 00:05:32.603 --> 00:05:36.307 those bullets will only get more unwieldy, 00:05:36.308 --> 00:05:39.111 so it was not really interesting for me to just 00:05:39.191 --> 00:05:42.475 increase the kept version history 00:05:42.476 --> 00:05:44.617 and use vundo as an alternative 00:05:44.618 --> 00:05:47.242 to the IntelliJ local history thing. 00:05:49.685 --> 00:05:51.828 There are of course multiple existing 00:05:51.888 --> 00:05:53.630 packages that do more or less the same. 00:05:54.030 --> 00:05:55.813 The only thing that I did was write a single 00:05:55.853 --> 00:05:58.196 function, so it's not really a package at all. 00:05:58.596 --> 00:06:01.480 I'll show you in a bit what it's like. NOTE undo-fu-session 00:06:01.797 --> 00:06:06.306 You have stuff like undo sessions that are 00:06:06.366 --> 00:06:08.329 persistent, like this thing. 00:06:09.431 --> 00:06:11.816 This is an interesting plugin which saves and 00:06:11.836 --> 00:06:14.621 recovers undo steps between Emacs sessions. 00:06:14.822 --> 00:06:17.206 I initially thought it was interesting enough to 00:06:17.847 --> 00:06:23.518 take a look at, especially if combined with vundo. 00:06:24.477 --> 00:06:26.082 The problem only gets worse 00:06:26.083 --> 00:06:31.441 because the vundo bullets showing different edits 00:06:31.442 --> 00:06:33.610 will only increase in size. 00:06:34.568 --> 00:06:37.272 And combined with undo-fu-session, 00:06:37.273 --> 00:06:40.599 I just couldn't really find anything at all anymore 00:06:41.741 --> 00:06:43.463 compared to... NOTE Timestamps 00:06:43.464 --> 00:06:44.566 The thing in the local history 00:06:44.567 --> 00:06:47.251 in IntelliJ is there are timestamps. 00:06:47.272 --> 00:06:51.660 Normally I know, for example, around 10 00:06:51.700 --> 00:06:53.964 o'clock this morning, I made an interesting edit 00:06:54.545 --> 00:06:56.188 that was just before lunch break. 00:06:56.472 --> 00:06:58.294 Or just before I went to the bathroom, after 00:06:58.314 --> 00:07:00.297 that, I don't know any more what I did. 00:07:00.617 --> 00:07:03.120 So I want to focus on that specific part. 00:07:03.140 --> 00:07:07.606 So I timestamped my stuff instead. NOTE Configuration 00:07:07.626 --> 00:07:10.990 Digging a bit deeper into the Emacs 00:07:11.030 --> 00:07:13.854 configuration, the things that I did to alter is 00:07:14.695 --> 00:07:17.839 the first thing, of course, some basic settings, 00:07:18.123 --> 00:07:21.586 which is the backup and the autosave directory. 00:07:21.606 --> 00:07:23.848 These two I will be needing. 00:07:24.008 --> 00:07:27.592 As you can see, like I wrote here, I like backups. 00:07:28.092 --> 00:07:30.334 So I enabled as much stuff as possible. 00:07:31.395 --> 00:07:33.577 Version control, of course, that's the one that 00:07:33.897 --> 00:07:35.038 you will be needing. 00:07:35.319 --> 00:07:37.781 But also `vc-make-backup-files`. 00:07:37.821 --> 00:07:39.002 What does this thing do? 00:07:40.924 --> 00:07:46.729 If we take a look at the symbol beneath it. 00:07:47.131 --> 00:07:49.755 You can see: if non-nil, backups of registered 00:07:49.815 --> 00:07:51.757 files are made with other files. 00:07:52.058 --> 00:07:55.022 If nil, default, files covered by version control 00:07:55.082 --> 00:07:55.783 don't get backups. 00:07:55.803 --> 00:07:58.246 So if Emacs thinks this file is already covered 00:07:58.306 --> 00:08:01.451 by version control, most cases that would be git, 00:08:01.791 --> 00:08:04.154 it will not be locally backed up, and that was not 00:08:04.234 --> 00:08:06.217 something I was content with. 00:08:07.899 --> 00:08:10.443 Those few lines that I will never commit anyway, 00:08:10.683 --> 00:08:12.025 they're not backed up, 00:08:12.410 --> 00:08:14.973 and sometimes you need those lines. 00:08:15.093 --> 00:08:17.075 Most of the times you don't, but sometimes you do. 00:08:18.096 --> 00:08:19.818 So I also enabled that one. 00:08:21.180 --> 00:08:24.744 If you enable all that stuff, of course, too 00:08:24.784 --> 00:08:26.426 much backups files will be generated. 00:08:26.446 --> 00:08:28.829 So you will need to trim them a little bit. 00:08:28.849 --> 00:08:30.851 You can either do that yourself or use a 00:08:30.911 --> 00:08:33.173 callback function or a time function or whatever, 00:08:33.294 --> 00:08:39.340 or just configure these specific settings. 00:08:39.360 --> 00:08:41.623 Then let's see. 00:08:42.177 --> 00:08:43.719 Backup. 00:08:46.122 --> 00:08:46.603 What was it? 00:08:47.884 --> 00:08:51.909 Let's go to the last few pages here. 00:08:52.810 --> 00:08:54.072 The mini-buffer. 00:08:56.735 --> 00:08:57.196 Here it is. 00:08:58.077 --> 00:08:59.779 `consult-local-history`. 00:08:59.799 --> 00:09:03.324 This is the thing that I just called in my other file. 00:09:04.365 --> 00:09:06.468 What it actually does is really simple. 00:09:07.609 --> 00:09:09.091 It scans the backup directory. 00:09:10.072 --> 00:09:11.374 If I evaluate... 00:09:11.810 --> 00:09:19.458 If I were to evaluate that, let's see, we'll call 00:09:20.239 --> 00:09:21.200 the backup history. 00:09:21.921 --> 00:09:24.403 This thing is just a configuration of the one in 00:09:24.443 --> 00:09:26.425 the Emacs .el file that I just showed. 00:09:27.106 --> 00:09:30.289 And then it checks for this buffer file name. 00:09:30.670 --> 00:09:31.731 Are there any backups? 00:09:32.091 --> 00:09:35.194 If yes, we just format them using a time string 00:09:35.775 --> 00:09:37.817 and then show them inside the mini-buffer. 00:09:38.455 --> 00:09:44.743 So if I go back to my tdd.md file and then go to 00:09:44.763 --> 00:09:48.026 the file history, this diff history, 00:09:48.027 --> 00:09:49.748 this is just the formatted one 00:09:49.749 --> 00:09:50.990 and these are all the files 00:09:51.231 --> 00:09:54.234 found in my specific backup directory 00:09:54.235 --> 00:09:55.877 regarding tdd.md. 00:10:01.123 --> 00:10:04.486 So once we have all those sorted files, 00:10:04.487 --> 00:10:08.412 we format the candidates and then we just display them. 00:10:08.763 --> 00:10:15.750 Then you use `consult--read` to see exactly 00:10:15.950 --> 00:10:18.833 which candidate is the one that's being picked. 00:10:19.513 --> 00:10:21.875 The one that's being picked, we use `diff-buf` 00:10:22.836 --> 00:10:26.158 or `diff-no-select` with the selected backup, 00:10:26.159 --> 00:10:30.083 the file name, and a few other parameters I found useful. 00:10:30.524 --> 00:10:32.425 Then it gets opened in a new window. 00:10:32.445 --> 00:10:36.069 So it's just a built-in diff. 00:10:36.089 --> 00:10:38.331 Then you can decide for yourself what to do with it. NOTE Wrapping up 00:10:40.758 --> 00:10:43.100 If you somehow think this is all really stupid 00:10:43.101 --> 00:10:46.185 or the way this is written is silly 00:10:46.186 --> 00:10:48.188 or completely wrong, please do let me know 00:10:48.189 --> 00:10:50.952 because I've been using Emacs for only less than a year, 00:10:50.953 --> 00:10:54.819 so I'm actually a complete noob when it comes to this. 00:10:54.839 --> 00:10:59.506 So I'm sure there will be better or more robust alternatives. 00:10:59.586 --> 00:11:04.433 I'd be really interested in hearing from that as well. 00:11:04.974 --> 00:11:10.242 So yeah, thank you very much and see you soon.