 Welcome to video number two of configuring Emacs. Now, this is a series of videos that I'm doing where I started with a standard vanilla GNU Emacs, and then I slowly transform it into something more akin to DOOM Emacs by installing things like Evil Mode and various other packages and adding various customizations to turn Emacs into something more than what it is out of the box. For those of you that want to follow along in this configuring Emacs series, I created this repository over on my GitLab at gitlab.com dwt1, that's my GitLab, look for my configuring Emacs repository, and in this repository I'm going to have a subdirectory for each video in the series, and if you click on it, you will get the config files as they existed at the end of each video in the series. So look for that on my GitLab. Now let me go ahead and close that out. Let's launch Emacs, and let me go ahead and navigate to my config.org file. So Ctrl-X, Ctrl-F is the standard GNU Emacs key binding for the find file command, and then I'm going to navigate to .config-slash-emacs-config.org. And this is our config. If I do Ctrl-X plus, I can zoom in a little. We're going to change all of those key bindings really quickly. I'm actually going to make those much more friendly in just a second. But the very first thing I want to talk about is the LPACA package manager, because we set that up on the first video. And this rather lengthy block of code here runs all the way down to here. So, you know, from line 23 to line 86, right? That's a large block of text that was basically just a straight copy and paste job from the LPACA GitHub. That set up the LPACA package manager. But it had a strange error. Now, a lot of you guys pointed out the other day on that first video of the series, where I was constantly quitting Emacs and then restarting Emacs every time I made a change to the configuration file. And people were asking, why are you doing that? Emacs can just do a hot reload. Emacs has several things actually built into it that you can use to do a hot reload. And if you change your config, you can see those changes immediately. You can do an eval buffer command. So if you do meta x eval-buffer, if that buffer happened to be your init.el, for example, you would see those changes take place immediately. You could also do a load-file command. If you do load-file, and then give it a file name, give it your init.el, it should reload your config. But you can see that doesn't actually work. That's why I didn't show it on camera the other day. I just quit Emacs and restarted Emacs every time. So I wasn't sure what was causing this error. I had to investigate the problem. See, wrong type argument, yada, yada, yada. Well, what it is is this LPACA block. Since I just did a straight copy and paste job, you know, one of the things is this line here is uncommented. When you just do the copy and paste from their GitHub page, and you see LPACA, NUEL, some NUEL is false, a message deferred. Basically, it's deferring some kind of already running function, right? And that is a problem when you're doing that kind of hot reload when you do a load file and you're init.el or whatever it is you're doing to do a quick reload of Emacs. This causes that issue. So that is why I have that line commented out now. And the next thing I want to do is to make this hot reload much more convenient, I want to actually add a key binding. So I'm actually going to scroll down past evil mode to the general key bindings. You remember this section here where we already did this block here where we were adding buffer related key bindings. I'm going to go ahead and add a new section for eval related key binding. So we're just going to create some space here. And we're going to do dt slash leader dash keys. Of course, this block will be E. And of course, E is going to stand for eval, but we need to do ignore T for true. So ignore means this isn't actually a command to run. This is just a description that will appear in which key. So instead of buffer, this time we'll do evaluate for E. And I went ahead and added several more of these evaluate key binding, some of the most important ones. I'm going to do space eb for eval buffer, space ed for eval defund, which is when you're defining a function space ee will be the eval expression command, space el will be the eval last s expression command and space er eval regions, if you select a region of elisp code, you can do space er to evaluate it space eb would evaluate an entire buffer if it happened to be you were working in an elisp file that would evaluate all the code in that elisp file. And if you wanted to see this in action, we can't use these key bindings yet because I haven't actually reloaded emacs. But what I could do to show you one of these eval commands, let me just in visual mode, I'm going to select this block here, I'm going to do a meta x and let's do an eval dash region. See if that actually works. And if it did, it just evaluated this section of code, which means I should be able to do a space e and look, there are all of those new key bindings that we just added to the config and by doing that eval region, they're now available to us. So how cool is that there's a few other things I want to do I want to go back to the buffer key bindings here because I kind of like the way I defined the e key bindings, the evaluate key bindings by putting a space between the letters. Now it doesn't really matter, you can do it the way I did it up here by not having a space between the key bindings. But honestly, for readability, I think this looks better for people actually following along with the config. So I'm going to make it a point to put a space between each of the keys and the key cords, if you will. So one other thing I noticed is the buffer commands, I did not have a I buffer key binding and I buffer is very important. I buffers basically your buffer dashboard, it's a listing of all the available buffers. So let's make sure that we have a key binding for I buffer. So I'm just going to go ahead, create this and let's go ahead and write that. And once again, I'm just going to grab this region of text. And I could do the eval region command, I could do meta x and then type eval dash region. But remember, we have a key binding for space e r for eval region. And assuming that works, I'm not sure if it worked, I didn't get much of a confirmation down here in the mini buffer. Let's do space B and see if I have I, yeah, I do have I down here in which key for I buffer. So space B I will take us to the I buffer menu here. Basically, it's a list of all the open buffers, which right now are just the Elpaka log, the scratch buffer, the messages buffer, these are just standard buffers that are always present in Emacs. And then we have our config.org buffer as well to go back to the previous buffer. Remember, I set the key binding space B P for buffer previous space B in for next. So that's how we're going to navigate buffers. The next thing I wanted to do is I started a new block of key bindings here. Now these are like the buffer key bindings or the evaluate key bindings. These are just some random key bindings that they'll be like general key bindings that really don't fit in any other block category. But I want more convenient commands for fine file. I want a more convenient command to always get to my config.org rather than having to type it every time. And I want a convenient command to comment and uncomment lines as well. So I'm going to add the space period key binding for the fine file command. That's the standard command in do me max space period runs fine file. That's a lot easier to type than control X control F right. And then I'm going to do space FC for space find config.org essentially. And that's just going to run the command. It's going to be a lambda. It's an anonymous function is all lambda is the anonymous function. What it does, it's going to run the fine file command except we're giving fine file a path. And when you give fine file a path, it just takes you to that file so you can edit it. And the description that which key is going to get will be edit E max config. All that's going to do space FC will open my config.org then space tab tab will come in a line or uncomment a line. And to see these in action, let me go ahead and once again, I'm going to select a region space ER to evaluate that region. And now let's see if space period runs the fine file command. And it does. You see fine file is running down here in the mini buffer. Let me escape three times to get out of that. And let's see if space FC works. Well, we're already in this fall. So let's do space period for fine file. Let's navigate to my net dot EL. But now let's do space FC. And it takes me to config.org and to see if the comments work. Let me just select a couple of lines here and do space tab tab. And of course it commented those lines out. Let me do an escape and then you to undo that's just a standard of them key binding there. Next, I'm going to add this very important block of key bindings. I suggest you add them as well. This will be H key binding. So everything begins with space H for help. So these are all the help related functions there. I'll probably add a bunch more. But these are ones that I use all the time. You'll probably use all the time space H F will be the describe function command space H V will be the describe variable command. If you're new to Emacs, every function and every variable that's written in Emacs list that Emacs knows about, which is going to know about everything is going to know about every package that is installed in Emacs, right? Every piece of code that you write every function you define every variable that you assign a value to, it's going to know about it. Emacs just knows about it. And you can use describe function and describe variable to get information about those functions and or variables. And then I wanted a hot reload. So in do me max space H or R restarts do me max or it reloads the new config file. So I was going to do space H or R. Originally, I was going to do this command here, this lambda function again, an anonymous function, an anonymous function, because it's just a one time function. It's just a throwaway function that just could use this one time for this particular key binding space H or R runs the command load file on our net dot el. So it reloads our net dot el our config files, right? So that is what space H or R should do. But I was running into an issue with it. For whatever reason, this was not working quite as I expected, because if I do space H or R, let's make sure we don't get any errors, we don't. That seems like it works. But let's actually test it. Instead of space H V for describe variable, I'm going to change that key binding to space H Z me colon W to write the config.org. Now let me do space H or R. Now let's see if this works. If I do space H for help is Z there. It actually is. Now before I was having an issue, I was having an issue where, but for whatever reason, the first time I did space H or R, it did not work. I had to do space H or R a second time. So I actually come up with a hacky way. I don't know if I really need this because it looks like it's working right now. I came up with this version. I was going to run this custom function that I created this function I named reload dash and it dash file. And if I scroll down to the config, I actually had a section reload E max. And this was the little function I wrote. So define is how you define a function define and then name a function. Again, I called it reload dash and it dash file and then opening closing parentheses out to the side of it. And then down below it interactive interactive means that it is available when you do meta X. So if I actually search for reload dash and it dash file, it is there in meta X if I want to run it that way. And then you can see what I want this function to do. I want it to load file user init file user init file is just a variable for dot config slash E max slash init dot E L is just an easier way for me to write the path of the file. And you notice I have it running that command twice. Because again, space HRR wasn't working the first time I ran it. I always had to run it two times. At least that was the case yesterday when I was playing this with this. So what I did is I created this really hacky function where reload and yet file basically does the load file twice. And then I set the keybinding for space HRR to run that particular function. But it looks like I don't need it because it looks like it's working correctly. Just doing the load file one time. So I'm going to keep that for now. If it causes me errors later, I may go back to using my hacky little function that I created. Let's go ahead and keep on adding some important keybindings that I think are just very important. And that would be these here. That's annoying. How these org source blocks sometimes just auto indent themselves for no particular reason. You guys have probably noticed that as well. That's an annoying default functionality that's built into org mode for some reason. I don't know why they have that turned on. We're going to turn it off in just a second. But I want to start a new block of key bindings. This will be space T and then some other letter for all the toggle commands, which they'll eventually be a bunch. But here's the most important ones that I want to deal with right now. TL to toggle line number mode and TT to toggle truncate lines. So I'm going to do colon W to write space H R R and assuming that works space BP for buffer previous. Let's see if that works space T to space T is undefined. So see, this is the problem that I was running into before, which by the way, I should probably change H V to describe variable again, colon W space H R R space T space T now works space H. Let's see if it changed. Yeah, we're back to having to describe variable as space H V. So I'm what I'm going to do. I'm just going to go back to my hacky little solution where space H R R will definitely work now because it's going to run the reload a net file function that I created, which basically does a load file twice. And for whatever reason, running it twice always works. And now I could do space TL to toggle line numbers space TL to toggle line numbers, right to toggle truncated lines, truncated lines would be, you know, by default, lines are truncated. But if you wanted them to just run off the side of the page, I could do space TT to toggle truncated lines off or space TT to toggle them back on. Now there's some more important key bindings. We need to go ahead and add, but I'm going to take a quick break from key bindings because I want to fix this annoying org mode source block indentation thing that keeps happening. So I'm going to go down to the org mode section. And let's add a new subheading here. So this is going to be disable electric indent. So in the source code block is only going to have this line here, electric dash indent dash mode dash one. Remember, at any time you have a mode, if it's set to one, it's on if it's set to minus one or anything that's not one, it is off. So let me colon W and now space H R R. And now let's see if we have any more of that annoying thing where well, let me just start typing where I kind of break lines. And yeah, it doesn't look like it's doing any of the weird indentation stuff that it was doing before here in the source code block. So hopefully the spacing stays correct from now on. But let me go ahead and fix the annoying two spaces it added to the beginning of this block for really no apparent reason there earlier. And now that we fix that annoying indentation problem with org mode, while we're working with org mode, one thing that is on my mind, we need to go ahead and do something about let me click on the org mode hitting in the table of contents just to take us to that one thing the other day, these source code blocks. The other day on the first video, I was just writing them out long form, which I think, you know, you guys needed to know, you know, how to do that with the pound sign plus begin underscore source and pound sign plus and underscore source. But a lot of people pointed out that there is a standard GNU Emacs key binding that speeds this up a little bit. You can do control C control period. And then from this menu, you can choose what kind of block you're trying to create, whether it's a comment, an example, a quote, or in my case, S for source. And we get the source code block. You still got to fill in the language. Emacs lisp in this case. But there is a better way to do that. Actually, I wanted that source code block. Let me undo. Yeah, to get that back. What I could do is org mode has built into it a program called org dash tempo. And what org dash tempo does, it creates a really handy shorthand form for you to get the source code blocks very quickly. And even though it is built into org mode, it's not turned on by default. So do a require and then space single quote org dash tempo. No ending single quote. The single quote just goes at the beginning of the function that is required. And now if I do a space HRR after I write space HRR, then space BP for previous buffer, let's see if this works. So I'm going to create a new line here, a couple of lines here. And let's do a less than sign S less than sign. That's the left pointing Chevron S for source code block. And then the tab key. And you can see I get the begin source and the end source. All I have to do is type the language. So that is how that works. And of course, that works with other blocks as well. For example, if I did less than E, I believe that is an export block. Now that's the example block. I believe less than capital E is the export block. And then you could do less than sign Q. And that is the quote block, etc, etc. And above the org tempo source code block, I'm going to go ahead and add a second level header under the top level header org. I've already got several second level headers for org. Org is going to be a very big part of this config. But I'm going to add source code block tag expansion just to explain what org tempo is. I've got a little description here. And then I created this little table with the examples of all the blocks that you can create and their shorthand forms. For those of you not familiar with org tables, they're just pipe symbols. So you do pipe and let's just create one name, pipe, description pipe, we'll do a second column value, pipe, and then you know, if I just hit enter and start a new line with the pipe symbol, and now if I hit tab, I believe, yeah, it's just going to create the rest of the table here. And, you know, I could fill this in, but I'm not going to, you know, that was just an example. We'll play more with org tables, but I'm going to add a lot of these tables, especially as we get very complicated into adding hundreds and hundreds of keybindings. I'll probably add tables just to make some of that information a little easier to read for those of you that go to like the GitLab for this repository and read the readme's. One other thing I wanted to do, I wanted a better keybinding for zooming in and out. So I'm going to go back to the fonts section of our config. And we just had this here. Let's go ahead and actually make this a second level header here. So this would be setting the font face. And this was just defining the fonts, the variable pitch font, the fixed pitch font, and all of that that we did. But now I'm going to have a second level header here. And the second level header is zooming in and out. And I'm going to do some keybindings. Now I'm not going to do the general.el keybindings. So this will be using a standard GNU Emacs command global set key. So this is another way you can set keybindings. And the reason I'm just using this is because these are very simple keybindings that won't involve the leader key, the space key, in any way. So I'm just going to do your standard control equal sign, control plus essentially, for increase control minus to decrease. And then the mouse wheel, control and mouse up increase, control mouse wheel down decrease. So it's not just key bindings. It's also mouse bindings as well. So let me colon w to write space hrr to restart space vp for buffer previous. And now let's see if that works. Control plus to zoom in, control minus to zoom out. Let's do a control and then the mouse wheel up that works, control and mouse wheel down that works as well. And one last thing I want to do on this video, I know this video is going to run rather lengthy, but when I first switched to Emacs, one of the things that always calls me a problem was I'd open a file that I needed sudo privileges to edit. And you know, it was always annoying to have to figure out how to get sudo privileges. And there is a package called sudo edit that is available. So what I'm going to do is I'm going to go ahead and install this package sudo edit and remember how to install these packages. You just do a use package block to install and configure the program. So a use package sudo edit that's going to install sudo edit for us, lpagle will install it. If it's not already installed, if it's already installed, it won't install it because it's already there. And then I've got colon config and then in parentheses after that you should have whatever configuration options you want to use for sudo edit. I'm actually going to do a dt slash leader keys, you know, do some of these general key bindings. And the reason I can do that down here is because these key bindings set this way have to be inside one of these use package blocks, all the key bindings up above, you know, in that very lengthy list of key bindings. They're all in a use package block. They're in the use package block for installing general. So, but you know, you can actually put these in their own blocks for the particular programs that they're associated with because that makes sense too. So for all the sudo edit key bindings, I'll just go ahead and put here. I'm going to do space fu, that is not or what you think it stands for, space fu is going to be sudo edit find file. And then space f capital U is just sudo edit file. So let me do it, co1w space hrr, and I'll show you these in action, space bp for previous buffer. So space fu is just the find file command except anything you open from this find file, you have root privileges, you have sudo privileges. That's all that is. Now what if you're already in a file and you realize, oh, I needed to open this with sudo privileges, like say config.org. I don't need sudo privileges for it, but imagine I did. Well, I could do space f capital U and it's going to ask me for my sudo password. I'll type it in and I'll hit enter and all of a sudden this file that I'm working in, I'll now have sudo privileges. So these are very important key bindings that are something I always add to my emacs configs. So let's recap a little bit of what we've already done here, the table of contents, of course auto updates every time I add something to it, so I don't have to fool with the table of contents myself, but we've already set up lpack of evil mode general key bindings. We got the fonts, we got zooming in and out with both key bindings and the mouse. We got our graphical user interface tweaks, which are the tool bars, line bars, scroll bars, line numbers, truncated lines. We got some various org mode settings, some very basic org mode settings. These are the important ones because basically all I've done with org mode at this point is to get rid of some annoying stuff. We really haven't done any cool stuff with org mode yet. We're just getting rid of some of the annoying defaults. Reloading emacs, that was that custom function for spacehrr. I created sudo edit and which key, so let me close emacs, let me restart emacs because let's once again rehash some of the key bindings if you're following along with my config. Space period is now the find file command, right, and then I could type the name of a file to go to, or what I could do if I wanted to go to my config file, which is all I'm going to a lot right now, spacefc for find config.org. So space period for the find file command spacefc just to open your config.org. Remember the toggle command space tt turns on truncated lines, there were no truncated lines here, space tt would turn those back off, space tl turns the line numbers off, space tl turns the line numbers back on. Remember space e and then other commands are the evaluate commands, escape, space h and another command are all the help commands, it's also the reload command as well, space b are all the buffer commands including space bi which is your iBuffer dashboard where you can navigate to various buffers and we have spent so much time on this config in these first two videos, I know we were kind of all over the place, you know, it seems like this wasn't very directed, it wasn't scripted out real well and part of that is on purpose, is I wanted to get a nice working config up and running before we really dive deeper into any of these topics because if I had just started, you know, with a really deep topic right away like L packer or evil mode or whatever it happens to be org mode without actually getting all of the little niggles worked out, all the bugs, for example that annoying indentation thing that we took care of today, getting org bullets working doing the source code expansion with org tempo, like these are little things that we just had to take care of so I know these first two videos are kind of lengthy and kind of all over the place as we go forward, we're going to dive a little deeper into more specific topics and for those of you that want a little preview, probably the next couple of videos, I know we're going to spend a lot of time either in this next video or the one after that, we're going to have to talk about all the various terminals and all the shills available in emacs because you're going to spend a lot of time in those terminals and those shills so we need to talk about that, I also want to talk a little bit about theming this default color scheme that we're using this default theme it's not bad, I like it, but you know I want something better so I'm going to create my own custom color scheme, I'll show you how to do it as well it's not as hard as you may think now before I go I need to thank a few special people, I need to thank the producers of this episode, Gabe James Maxim, my homies to bald map, Mehmet Mitchell, Paul Royal West, Armor Dragon, Bash, Potato Chuck, Commander Ingrid, George Lee, Marshawn, Methos, Nate, Erion, Paul, Peace, Archon, Fedor, Hollytech, Realities for Lust, Red Prophet, Roland, Tools, Devler, Willie and Zenibit, these guys, they're my high-steered patrons over on Patreon without these guys episode two 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 I don't have any corporate sponsors I'm sponsored by you guys the community if you like my work and want to see more videos about free and open source software including Emacs subscribe to distro tube over on Patreon peace guys