 This will be video number six in a series of videos I have entitled configuring emacs for those of you that have followed along with the first five videos I will warn you today's video. I'm not gonna really add a whole lot of new functionality We're not gonna install a lot of new programs or anything like that today we're just gonna take the existing config as it existed at the end of the fifth video and Refactor some of the code we're gonna fix some minor bugs some minor Annuances because our configuration at the end of video five that configuration file was nearly a thousand lines long at that point It was over 800 lines of code and I really just I wanted to clean things up a little bit Now for those of you that haven't been following along since video one if you want Obviously go back and watch the previous five videos But I've also created a repository over on my get lab at get lab comm slash DWT one That's my get lab look for the configuring emacs repository if you click on it I've got right now five Subdirectories there'll be a sixth one after I publish today's video But if you click on for example number five here directory number five here These are the configuration files as they existed at the end of the fifth video So one of the big things I wanted to do From that last configuration that we had after the video number five is we have a lot of Really large blocks of code in our configuration file that we're never going to edit I mean they're like this alpaca block of code here that sits up the alpaca package manager, right? We're never actually going to need to edit this for any reason at least I seriously doubt I'm ever gonna edit this for any reason because I don't know what any of this code means right It's rather complicated block of code And it's probably something that unless you really know what you're doing you shouldn't play around with this code anyway So I would just like to get it out of this configuration file because a configuration file is something that a user should play with right? It's basic settings you know changing fonts and things like that and theming right? This is kind of like a core part of what is essentially our emacs distribution here So what I've decided to do is let me Go to a different workspace and let me open This configuration file So what I have done is I have removed that alpaca block of code that used to be here And what I've done is I have created this scripts directory So in dot config slash emacs I have a directory called scripts that I created and What I did is I moved that entire alpaca block of code to this file that I titled alpaca dash setup Why did I choose that name? Why not? I didn't want a conflicting alpaca Name already there was no command for alpaca setup So I just titled the file that and it was just a straight cut and paste job I cut it out of the config.org and put it into this script here And the only other thing at the very end when you're sourcing a script you do need this line here provide What we're providing is this function here alpaca dash setup So really that one bit of code is all I needed to add And then in the config.org what I needed is I needed to add the scripts directory to the path So we're going to probably have a lot of scripts eventually in this scripts directory And we need to load it to the path here inside emacs So emacs knows that these scripts are available for us that it will source them So you can say I have add to list and then quote load dash path That's the load path command and what path are we loading? We're loading dot config slash emacs slash scripts And then all we need to do is simply add this require and then single quote alpaca dash setup So it requires alpaca dash setup, which is the alpaca dash setup Screw up here because that provides alpaca dash setup. I hope that makes sense So what this does it allows us to take essentially About 68 lines of code that would have been in the config.org We can strip it out because we're never going to need to play with this right It just needs to be out of sight out of mind And then the other one that I wanted to do something similar with was we had a very large block of code for buffer move Which is these custom functions that allow us to move buffers around for example Let me open a new split here And let me just navigate to some random file here on my system by default emacs Really doesn't have any functions built into it that allow you to move the window splits around kind of like You know kind of like a tiling window manager would for example with these custom buffer move Functions that we've created we can actually do something like I could do I could do space w capital h To move the window to the left where I could do space w capital l to move it back to the right Or you know space w capital j to move it down if there was a frame that it could move down to or space w capital k To move to the frame above it again if there happened to be a frame above it So this buffer move block of code here again very lengthy block of code here All right, probably a good 50 lines of code that we really are never going to play with this So once again, I just wanted to get that out of the way So I no longer have that buffer move section in the config.org what I've done now if I go back into the scripts directory You can see I now have buffer dash move dot el where I took all the buffer move stuff and just Put it in its own little script in the scripts directory And the only once again the only thing I had to do at the end To make sure I add the provide line here provide buffer dash move And then of course in the config where I'm sourcing stuff require quote buffer dash move And one last thing I wanted to rip out of the config.org because it's something I doubt anybody's going to play with I had a custom section of uh, like emacs app launchers I go to the old config I had this app launchers section where I was experimenting with using emacs as a run launcher similar to dmenu or rophy and it kind of works But most people are never going to use it 99.9 of the people that ever use this config Including me are probably never really going to use these app launchers, but I didn't want to Delete the code. I wanted to keep it around So what I decided to do in the new config is instead of having the app launchers section that was somewhere here You know, I ripped all of that out and once again if I go back to the scripts directory I now have app dash launchers dot el and I've made this this Emacs lists script here So the code I just moved it from the config.org to this script And then once again at the end make sure you have a line that Says provide provide single quote app dash launchers And then in the config file the config.org require single quote app dash launchers sources it So I could still run those app launchers since I have this source of course if you didn't want this I mean you could always comment this out most people probably won't use it I wouldn't ever comment out the buffer move Stuff because I think most people will find that useful the alpaca setup definitely never needs to be commented out Otherwise, you're not going to have a package manager setup for emacs So I'm really happy with the way that turned out that really cleaned up the config.org a lot It probably saved us, you know 150 lines or so of space in the config and now The next thing I wanted to do is you guys if you haven't already you probably Want to get rid of the annoying default feature that emacs has where it always creates backup files when you're working on files If I zoom in for example, I have a comment here Imagine you're working on file.el. Well, you go and save it Well at some point emacs is also going to save a backup file for that file It's going to be file.el and then the tilde character at the end You have all of these files all over your file system right now probably that have that tilde at the end Because emacs is constantly creating these backups Which is a nice feature that it creates backup files that it can you know recover from if need be But the problem is the default feature of it It saves those files in the directory that the file you're editing currently lives in So that's annoying. Why not have it save all of those backup files But throw them all In some directory and it makes sense to throw them all in the trash directory, right until I empty my trash folder I can go find those files if they're there when I empty my trash folder, which I probably don't do You know once or twice a month, you know, then I lose all the backup files But that's fine. Honestly, you don't need the backup files that often So what I've done is I've done a set queue set queue assigns a value to a variable The variable is backup dash directory dash a list and I want to send them all again to the trash directory The next thing I wanted to do and something you probably notice since the beginning of this video is I wanted to do some more with theming I showed you guys how to create your own custom theme in emacs on the previous video By control wv to get this vertical split here and I go into the themes directory Remember, I created dt max dash theme el This is just a emacs script. It's a theme file Where you can assign colors to certain variables That emacs knows what to do with so that's a pretty neat little theme Matter of fact, you guys if you want to see this in action, I could do meta x load dash theme and then search for dt max And that was the theme I was using but now what I've decided to do is I've decided I wanted to go back to The theme I was using back when I was using doom emacs, which was the doom one theme Let me tell emacs that it's safe to use that theme So now under the theme section before all I had was Add to list custom theme load path and then dot config slash emacs slash themes where my custom theme script lives And then I could somewhere below that have load theme Single quote dt max and then space t for true to load the theme by default Well, I decided I was going to go ahead and install the entire doom themes package as well because doom emacs Has a collection of I don't know probably 30 or 40 really nice color schemes And these are the common color schemes everybody uses such as Solarized grub box and Dracula and the doom one and tomorrow night and all of that stuff You know really nice pretty just gorgeous themes and they're all in this one package the doom dash themes package So let's install it well to install it once again Just use package doom dash themes and then colon config what I've done is I've enabled bold fonts and italic fonts If the particular theme that I set does have those available Then finally I've decided to just go ahead and load theme doom one t for true that way every time I launch emacs It's going to know that I want the doom one theme loaded and the doom themes also are really nice because they already have Configurations available for neotree which we enabled on a previous video And you can see I have doom dash themes dash neotree dash config So if I do space t in to toggle neotree, you can see it uses the doom one theme as well With the icons and everything and that really looks very slick Now it didn't make much sense to me to go ahead and install the doom themes package and still have a plain vanilla Mode line in emacs because I really didn't edit the mode line You can create your own mode line if you want. It's kind of a deep topic You got to be kind of a nerd and want to waste a lot of time creating your own mode line Personally if you want to do that you can for me Why not just use a really nice mode line that somebody else has already created and packaged up such as Doom dash mode line since I'm using doom dash themes It makes sense to use the mode line that they created as well So once again to install a package use package space name of package So doom dash mode line and this use package block for doom mode line and doom themes Actually, I just ripped straight from the github for doom mode line and doom themes So the if for some reason you're struggling with creating these use package blocks a lot of times If you just go to the github or the get lab page wherever these packages Exist write the source code for them The developers usually give you the use package statement that you just paste in your config To make this work in the doom mode line use package statement We have colon and yet so initialize right we need to do this before we do anything else We need to set the doom mode line mode to one when you set a mode to one You turn it on if it was set to zero It's turned off and then of course we have our colon config section where we set you again We're assigning values to variables and the variables include things like the doom mode line height and I set it to 30 That's the 30 pixel height of the mode line if I wanted to of course I could change that Matter of fact, let's do a hot reload I'll change it to 50 just to show you that this works and then I'll do space hr r Remember that key binding we set to actually reload our config. So now let me go back. You can see the mode line This is 50 pixels high and which kind of looks neat, right? That's a little too high for for my days. You know what? Let's Let's make it 35 so make it a little higher than what I had it initially But 50 was way too big. I do think having that tall mode line though It's not bad. Is it wasted space? Maybe but I think it it looks kind of good having a little extra space to your mode line And since I had just ran the space hr r key binding to reload emacs Of course, that's does uh tells elpaca to do a hot reload to reload our new config file That was kind of broken in a previous videos. Actually, it's been broken since the very first video I but on on the older config what I was doing is I created kind of a hacky solution to do that hot reload I created this custom function that basically Reloads our user init file so our init dot el file twice because just reloading it once for some reason doesn't work elpaca Kind of bugs out on that. But if you reload it two times in a single function It kind of works, but still that is rather inelegant and it's definitely a hacky solution Well, I had a issue opened on my get lab that where the elpaca creator the the maintainer of elpaca Actually did a merge request and wanted to fix this code for me. He's like, hey try this out So he actually gave me this new function. It was just a lambda function I I could actually have put this as a named function But I think I'm just going to leave it as this lambda function here. So now space hr r does this lambda function It's just a an anonymous function. We're not naming it. It's just a one time throw away function And the function does a load file on the init dot el which is expected But then he has this ignore and he's ignoring the elpaca process q So I guess that elpaca process q's function was what was causing The problem before and now by ignoring that when we load the file Everything works on that space hr r hot reload if I scroll back up through my config You'll also notice that I added a lot more key bindings. I spent a few hours actually Thinking of a lot of the key bindings and the functions that I was missing because eventually we're going to have hundreds of key bindings set for this thing But for example, the space b key bindings are any commands related to bookmarks or Buffers and there were a few that were missing here I think I only had five or six of these key bindings on the previous video But I kept running into commands that I wanted key bindings for for example clone indirect buffer So if I do space bc clone indirect buffer creates this indirect copy It's a straight copy a twin copy of the buffer I was working in in this split here So you could certainly find a use for that, you know, sometimes I do use that command So I wanted I wanted to have a key binding for it I don't really use a lot of bookmarks and emacs, but you can create bookmarks So if I did space bl this is the list bookmark command So this is your bookmark list kind of like a buffer list if I had bookmark said I don't So there's nothing to see here Let me escape space bp And of course space bp was buffer previous which I've already had those set space bp for buffer previous space bn for buffer next Some other commands I added where I added space bm for bookmark set So this set's a bookmark I also added a key binding space br to revert a buffer Sometimes I just want to reload a buffer that I'm in you know I've refreshed it or I edited the file outside of emacs maybe in a different editor at the command line We are using something like grip or set or alt or something and I just want to reload the buffer So it reflects those changes. So that is a very useful key binding too But really what I spent a lot of time in because I think it's the most important set of key bindings Especially for those of you that are following along And you're new to emacs or the space h key bindings that I've set up here So these are all the help related key bindings and there's a lot of them And the reason there's a lot of them is because emacs has such good documentation emacs is self documenting There's a lot of programs inside of emacs that will give you Help information So if I do space h and then just wait for which key to give us the hints for the other key bindings You can see space ha is the apropos command So I could search for some kind of emacs program here and get some information kind of like a man page here Let me escape I have space hb for describe binding and you can see I get a list of all the key bindings that are set That are either default key bindings or that I've personally set In all of their various states visual state normal state remember evil mode calls it states rather than modes To not get confused the fact that emacs of course has modes evil is a mode But the modes the vim like modes that would be an evil They call them states normal state insert state visual state I created this section of space hd bindings within space h So this is space hd for documentation specifically emacs Documentation because there's a lot of it space h and then d for the emacs Documentation key bindings and you can see space hd a would give you the about emacs page here space hd again To get that list space hd d would view emacs debugging information space hd f is the FAQ for good new emacs space hd and I really didn't want this could I queue to quit yet Space hd again to get our list of emacs documentation related key binding space hd m is the manual So this is where you would go and you get a very nice manual with a lot of chapters Of course, all of this information is online as well, but it's all here locally on your machine So this is great if you need to get help information and for whatever reason you're on a machine that Doesn't have internet or is just the internet is down at the time I do space bp for buffer previous This doesn't work because evil mode is not working in this type of buffer But would queue to quit would that quit out of the buffer? It does queue to quit out of that buffer and then space bp would work in that buffer and i'm back to my config There's even a binding or a program called describe gnu project So that's a built-in emacs function to describe what the gnu project is I've set that to space hg anybody that wants to read that space hg what it does It opens your browser. My browser just opened up the gnu project page here So that was very very cool So that's just a little bit of what i've been working on here in the emacs config cleaning it up quite a bit again Moving a lot of the code that nobody really needs to ever play with Moving all of that out of the config.org into these scripts that then get sourced here. That saves a lot of space We've added a ton of new key bindings We fixed that annoying bug where emacs was creating backup files All over the system and we also fixed the annoying bug where we had that hacky solution to restart To do a hot reload of our emacs config and thankfully the lpaka Maintainer helped me out with that. He gave us that really neat lambda function now that space hrr Does a nice hot reload and it doesn't involve that hacky little custom function that I was using before So i'm going to push all of these configs to my git lab here as soon as I finish editing this video So look for the configuring emacs repository over on my git lab and look for the directory I'm going to create it's going to be titled zero six and then it'll have some description as far as what the video description Is about today, so go grab that if you want the latest config file as it exists right now Now before I go I need to thank a few special people I need to thank the producers of this episode and of course i'm talking about Gabe james matt paul royal west armor dragon commander angry george lee met those nate irion paul peace watchin fedor Reality's for less red profit role in souls astrey tools devler warden two and a boon two and willy These guys and they're my hyster patrons over on patreon Without these guys this episode of configuring emacs would not have been possible The show is also brought to you by each and every one of these fine ladies and gentlemen all these names You're seeing on the screen right now. These are all my supporters over on patreon without these guys I couldn't do what I do. I don't have any corporate sponsors If you like my work and want to see more videos about free and open source software like emacs Subscribe to distro tube over on patreon peace This config is going to be 2000 lines long once I add all the bindings