Emacs From Scratch #1 - Getting Started with a Basic Usable Configuration

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Hey folks, join me this morning (in about 2 hours from this post) as I start building a fully custom Emacs configuration from scratch. This is a huge topic so we'll likely do a few streams as we go deeper into what's possible with this amazing program. Be sure to subscribe and hit the bell to be notified of all future streams!

Hope to see you there!

👍︎︎ 12 👤︎︎ u/daviwil 📅︎︎ Sep 11 2020 🗫︎ replies

9:15 am PDT happens when this comment is 2 hours and 8 minutes old.

You can find the live countdown here: https://countle.com/QuN1-yFwi


I'm a bot, if you want to send feedback, please comment below or send a PM.

👍︎︎ 7 👤︎︎ u/the_timezone_bot 📅︎︎ Sep 11 2020 🗫︎ replies

Kudos on the idea.

👍︎︎ 2 👤︎︎ u/agumonkey 📅︎︎ Sep 11 2020 🗫︎ replies

View in your timezone:
9/11, 9:15 am PDT

👍︎︎ 1 👤︎︎ u/timee_bot 📅︎︎ Sep 11 2020 🗫︎ replies

It says the video is restricted and I must be approved to view it. I am located in Illinois and don't use a VPN. It's 8:15 PM here (CDT)

👍︎︎ 1 👤︎︎ u/FluentFelicity 📅︎︎ Sep 12 2020 🗫︎ replies
Captions
what's up everybody david wilson here and i'm very happy to get started this morning on a new series in uh our live streaming adventures um where we start to build in a custom emacs configuration from scratch um so emacs if you don't already know but i assume you probably have heard of it if you're here um is a well some would call it a text editor but i consider it more of a like complete productivity environment um it does the basic text editing capabilities but it provides like a platform for building pretty much anything you would want to do whenever messing with stuff on a computer you know writing code or you know organizing your life or you know just managing your computer in general so i think that it's really interesting to dive into how to configure emacs from the ground up because you learn a lot more from doing it that way as opposed to using a pre-packaged configuration system like space max or doom emacs etc so my background with emacs is that i started using it probably like on and off since about 2007 but i didn't really get really into emacs until maybe a year and a half ago where i really got deep into uh customize customize my configuration and trying to figure out what i could do to just make my own full workflow using emacs so at this point i basically live in emacs all day i you know use exwm as my window manager um i use mostly emacs packages for everything except for things that i can't do that with like you know applications i need to use for work etc so i think it's gonna be really interesting for us to dive into um both how i've configured my system and also how you could make your own configuration from scratch uh using similar techniques so um this is live obviously so if you are here in the chat please say hello and uh please ask questions anytime if you're interested in any more details about anything that i cover here um i i figure we'll probably do a lot of streams about this because there's a lot of things you can do with emacs so we're going to start just like from the basics we're going to start from the ground up and then over time we will probably experiment with different packages based on what people ask about and try to like build like a full workflow using using emacs so uh to kick things off i will i'll go over my configuration um a little bit just to sort of show you what my world looks like on a day-to-day basis and then we can jump into starting from scratch on a new configuration so um whenever uh emac starts up or actually let's take one step further back um whenever i log in to my desktop environment it boots up emacs emacs takes up the full screen it uses exwm to manage the screen and manage any x windows applications that are being run inside of that if you're using windows or mac os unfortunately you can't use exwm but this should still be interesting to you from a sort of conceptual perspective of what's possible with emacs so you can see i'm here in e-shell which is basically a built-in uh terminal emulator sort of in emacs it's pretty powerful we can go into that um for uh in another time hi james good morning um so from this point usually i will like you know navigate to a particular project um so let's just you know open up a file here so i can hit uh find file and then go into the readme for this project um and you know we can use d-red to navigate around the file system so i have a key binding setup for that where i can you know pop around through different folders uh it's very easy to do that i've got like custom keybinding setups that it's easy to navigate with them style keys like hjkl et cetera um using uh my git for git functionality if i go to my dot files repo you can see that we can pull up the git you get really nice things like you know history list or you know staging of chunks or pretty much anything that um you would want to do with git repository is a super powerful package and i feel like if you've never seen it before this may be one of the major things that turns you to emacs forever at least even just for for this functionality alone because uh it's it's super powerful it saves me a lot of time so um i mean that's not really a great run through i guess of what you can do you can see that i actually have a next windows window here on another workspace um so i have like the the repo for this project we're going to do and i can switch windows pretty easily i actually use separate browser windows for every quote unquote tab that i have open and i can use emax buffer switching commands to switch between those which is pretty nice so anyway if you get really into emacs you can go really far and and basically customize your whole computing life which is pretty cool uh i'll quickly bring up my personal emacs configuration so you can see what that looks like i've gone with a literal configuration format where we build um our configuration files out from org mode files and if you haven't heard of organ mode it's basically like a um it's an organizer but it's also kind of like a markup language for writing documents and it can do live code evaluation within blocks inside the file so it does a lot of things it's super powerful that's another one of these features that you'll hear a lot of people talk about whenever they talk about how cool emacs is in this case we just have a whole file set up here with a bunch of different sections for all the stuff that's in my configuration and as you can see there's a lot in here but uh even though there's a lot in this single file it's easy for me to manage because of all the headers you can navigate through headers pretty easily and a lot of the configuration blocks don't actually get loaded until they're they're needed so some command from the package gets run or mode gets activated so it's it's been working pretty well for me in this case so at some point the future will get to this point of using org mode to do our system configuration in our e-max configuration but for now we're just going to stick with a plain emax list file instead um uh james x excuse me jamesx asks is this linux yes this is um this is indeed linux is a distribution of linux called gnu geeks and uh i will also go into that in more detail one day because it actually fits in pretty heavily into my workflow but for now we'll just focus strictly on emacs so um without further ado how about let's try to get something started here so we're going to be using emacs 27.1 since that came out recently and thankfully my distro has now got that working so i i get the benefit from that yes pepsi says nice timing just installed doom emacs and exwm yeah that's a good combination i haven't really used emacs very much i do use do mode line and doom themes but doom e-max i kind of like before that got popular i started working on my own configuration from scratch so um i never really got into that i did use spacemax in the past though and that was that was pretty useful so let's try to start emacs without loading my own configuration so we're basically going to be running emacs and emacs here we're going to have a little bit of emac exception but it should be it should work fine we're going to run emacs q which i think inhibits startup and since i do have an empty in the el here oh i don't have an empty init yield we'll just touch it and make that there so we'll say emacs dash q init.el oh i think we need to say load well let's use the nice little help here oops i think it's uh load load path load okay it's just dash l all right so emacs q l init.el and it's going to pop open a vanilla emacs window and uh yeah so we're basically confronted with this white screen and the text is super super small because my screen is high dpi and uh the font isn't set correctly yet so it's probably not very readable at the moment but we're gonna fix that so uh if you've ever downloaded emacs like so so imagine this like you've you've been looking around on like let's say reddit on our slash emacs or you're looking around at other people's like you know configurations or whatever um and you're or someone's video or something where you see them using a cool configuration uh you probably saw like something look really cool you know look nice and minimal like what i was showing you before and then you go download emacs you're excited to start using it and you're like okay because it's gonna be really nice then you you run emacs for the first time and you see this screen where you've got this kind of toolbar and you've got the menu bar and you've got this welcome screen with the weird old looking emacs logo and the colors are kind of crappy you're probably like well i don't know about this this doesn't really look like my kind of tool well thankfully it's easy to turn a lot of the stuff off and then get to a more minimalistic view that you can start from that feels more like what you would expect from an editor um or at least if you like minimal editors like them etc so we're going to start with that we're going to try to get rid of some of the stuff in the ui and then we're going to try to set a theme that will allow us to you know tolerate what we're seeing here because this white screen is kind of blinding me right now all right so um i'm going to back out of this real quick so that we don't have to look at that and then i'm going to open up the init.el file and i'm going to cheat a little bit because i have some bits of my configuration that can work for this so i'm going to split this window and i'll pull up my own configuration so the first thing that i want to do if i can get down here is find my configuration settings for simplifying the ui apparently i've buried it let's see visual bell i think it's there oh yeah okay match required give me a break obviously this morning i've lost the ability to type so um menu menu bar mode okay great here we are so um what one thing we can do let's say the first thing we'll do is we'll just inhibit that startup message which shows you sort of that the landing page in emacs i mean it could be useful for some people but for me i prefer to just start from like a blank screen as much as possible and also we're going to uh set some settings to remove some of these ui elements because we don't really want to see those anymore so i'm going to get rid of some of this indentation since i'm copying it over from for my own configuration and then [Music] i think that's a good starting point actually let's get rid of the menu bar also and i'll throw in the visual bell uh since i tend to prefer not having um my editor beep at me all day long whenever i like hit backspace at the beginning of line or anything like that i turn on visual bell so that i at least see a flash on the screen uh like let's see can i invoke it yeah you see that sort of the top and the bottom of the window flashing right now whenever i hit backspace that's what a visual belt looks like so some people find it annoying uh i do find it more annoying on mac os because it throws up this huge like triangle thing in front of your face but at least on linux it doesn't seem to be that annoying so let's go with that for now so um we will split this window so i can go into eshell again and then we can run emacs with that init.el and let's see what we get and i'm going to full screen this so you can see it all right cool so now we see that we are initially dropped into the scratch buffer and there's no menu bar there's no toolbar and yeah it's very very minimal and simple presentation so this is like it only takes about five six lines of code to get to the point where you have a very simple starting point um so next we want to probably make the font size bigger so that we can actually tolerate using this so um i'm going to copy over some font settings i have the values i'm using for the font size are going to seem really really big and that's just because i have to compensate for the dpi for some reason whenever i updated from emacs 26.3 to 27.1 the font sizes i was using before don't really work anymore uh i had to like double them at least to make them bigger and i think the reason why is because they've changed text rendering engines from i'm not sure what it was before but now they're using harf buzz which actually has improved the look of the text shapes a lot for me so i find that to be a very nice improvement despite the fact that i have to jack up my font size to a ridiculous level so i'm going to search for face attribute here and if you're wondering what i'm doing for searching right now i'm using a a package called swiper which allows me to hit a key binding to do fuzzy matching across all the lines in the file just makes it really easy to find things whenever i need to jump into that so i found the wrong one it seems let's go do that again face attribute to yeah let's go get these absurdly high number font sizes uh i'm going to use the uh fira code retina font for this so we're going to drop here and we're going to paste this all right and uh i'm gonna leave that as font size 280 because that's what i'm using right now i'm not exactly sure why oh okay yeah so i have a flightcheck running on this on my emacs list buffers and it's trying to help me out but right now it's a little bit annoying we'll just ignore that for now so let's run this again and uh i know some of you are probably thinking wait why don't you just like evaluate this configuration setting right in emacs instead of keeping instead of continually reloading it well i'm gonna start doing that now so now we can actually read what's on our screen which is good we've got the font size set we've got a decent font uh configured uh this looks much better so uh now what i will do is use well there's okay let's start with uh opening the init file here so that we can start editing it and evaluating changes from from this point so oops um since i use uh evil mode which we'll get into later it's basically a vim emulation mode um i might make some weird edits to the file every now and then because i'm like doing mode changes and stuff and forgetting that i don't have it but we just ignore any kind of weird text that you see me type in so what we want to do um first let's see i think is it like i really wish i had an iv here let me figure out what that command is supposed to be so if i was to say theme uh load theme enable theme let's see what i think this council theme we want to pick one that's already built in we'll go with tango dark so this is just going to be temporary so that we don't have to look at this white screen the whole time uh james says at the end we would love to know the top must-have packages you like for a new config yes i'll definitely let you know what that is because i have some opinions there um i think that what we're going to try to do at least in the first couple streams is to get a configuration together that uh uses some of these top packages that i like just because they are kind of like the best exemplar of what emacs can be so we will definitely get there um load theme let's see so uh if you've never used emacs before one thing that you really should learn about is the help commands or describe commands actually um they are bound to the um control h uh and then letters under control h keys and they allow you to do things like describe variables in emacs or describe functions in emacs and that becomes really helpful when you're trying to figure out how to do certain things or if you want more information on what a variable or function does there's also a bunch of things for like describing font faces and describing modes and like a lot of stuff so we'll get into some of that stuff later but for now i'm going to use this describe function to see what load theme does ah vincent says also mention which packages one can do without for example a couple of years ago i stopped using undo undo tree and haven't missed it yeah yeah this is something that is also important uh and it changes over time um so yeah i'll definitely talk about this that as well so remind me if i don't talk about it at some point okay so i used uh describe function and that uh i asked it about load theme and now we've got this documentation here about what load theme does so the first parameter is a theme and then there is some optional parameters for no confirm no enable we're not going to worry about those parameters the main thing is we want to say what theme you want to load so i'm going to tell it tango dark and now i'm going to try to run this code directly from this buffer by using control x control whoopsie invalid theme name tango dark that's interesting i didn't even try to execute it yet so uh invalid theme name all right so let's see if anybody knows the right way to call this just shout out in the chat so i use something different than this oh actually in my configuration i think i have something for this so let's see load theme ah okay so um sometimes you have to be aware of what type of parameter gets sent and maybe describe a describe function was going to tell me that and i just didn't read it but in this case it wants a symbol instead of a string and that's sort of a thing in lisp languages they have this concept of symbols where you can put an arbitrary string as a sort of like a language symbol so we're gonna put this uh single quote in front of this text without quotation marks around it and then we're gonna run it yes thank you abdullah so um we are gonna try to run this uh i will select this text first and then control x control e and that did not seem to run it so let's just evaluate the buffer so if you run uh mx come on i hit escape too many times because i'm you know used to evil mode and it's giving me trouble so mx uh eval buffer all right now we do have theme loaded as you can see we have a nice darker background i'm not really like a big fan of this theme but it's gonna get us where we need to go for the time being so uh now we have our theme loaded up and we have our ui looking a lot more minimal which i think is a great start so um now you know we could go into some of those built-in packages that emacs has for doing certain things which you know there's a lot of built-in stuff one of the things that a lot of people are surprised about whenever they use emacs is that there's a whole lot of stuff already built in and a lot of stuff that you probably don't really want but i think the benefit is that if you don't really have internet access or you don't really want to install custom packages there's a lot of things already built into emacs that you could use for certain things like completion frameworks or um uh thanks to passing one yeah cxe works after the s expression thanks um there's a lot of things that are already here but um since we have this very healthy lively ecosystem of emacs packages on melpa which i'll show in a little bit um we it we'd be better off trying to find things that are out in the world that we can use that are like community packages that give us some really nice functionality so to make it possible to use these packages um we're going to use a another package called use package and use package basically is a it's kind of like a package manager there's already a package manager built into emacs like for instance if we were to run list packages this is a function that will just give you a list of all the possible packages that are in um oh boy i think we have a lot of packages here that are from my own emacs config that's okay so um basically any package that's available on i believe this is elpa so there's like a sort of default package repository for for emacs called elpa and that has a lot of packages but then there's one in the community called melpa that has a lot more so if you look for emacs melpa then i think it's melpa.org yeah and uh on this site you can go and search around for things that you want to use like if you use a specific language you're trying to find packages for like let's say closure you can see whoops you can see that there's a lot of closure packages um because you know i think that there's some you know uh affinity from lisp users and emacs so since closure is a list i think a lot of closure users are emacs fans so uh we're gonna use melpa as a place to install packages from but first of all we just need to get use package uh setup so i'm also gonna steal some stuff from another configuration that i have here and i'll explain what all this stuff does whenever i get it turned on okay okay so uh first of all what we're going to do in our configuration for package loading is we're going to initialize package sources i'm going to get rid of melba stable for now since we're just going to use things from the main melba repository first we're going to require the package package which brings into the environment all the package management functions i think that may be auto loaded but i just have this here as part of my configuration just in case uh and this package archives is a variable that holds all the different package repositories that you can pull packages from as you can see when i hovered over this uh right when i put my cursor on this variable name it tells me down in the in the mini buffer that package archives is an a list of archives from which to fetch so that's helpful now uh we call package initialize which initializes a package system and then prepares it to be used and we also check whether uh package archive contents is present because on the very first load like let's say you install your computer from scratch and you want to pull down your emacs configuration and install everything um you need to look to see whether there's already a package archive cloned to your computer or if there's nothing and you need to pull it down so in this case we're saying unless this archive exists we're gonna call package refresh contents which refreshes the package list so that the future calls to package management functions know what package or packages you're talking about and then we're going to require oh we're going to try to install use package if it's not already installed so this package installed p function anytime you see a functioning ematch that emax that ends in dash p that is a like a predicate function or it's basically a function that returns true or true or nil i think and the idea here is that you can use it to say is this package installed like i want to see if this package for this particular name is here and if it is returned true and in this case we're saying unless it's already installed we're going to use package install which is built into emacs to install use package and then once we install that we're going to load it using require so now at this point we have used package available to us and one extra thing that i'm going to do which i don't know if it's by default or if i just did that in my own personal configuration but we can find out very easily by saying control hv for describe variable and then i'm going to say use package always ensure so we get this helpful window over on this side and i think my panel is in the way let me kill that oh i need to get out of this first pill panel okay so use package ensure is a variable to find and use package and share.elo its value is nil so that tells me that before running this the default value of the variable is nil which means it doesn't ensure packages by default in used package terms ensure means that whenever you evaluate a used package form um if insurers set the true then it will try to download the package whenever it evaluates that form which you do want if you are loading up your config from scratch and you want to make sure that all of the the packages that you are using are going to be downloaded and installed before they are run so this will make sure that all of them will be insured so um from from this point i want to like insert one little thing here that is not needed in a normal configuration but it's going to be very useful for us going forward we're going to say actually let me let me evaluate all this stuff first before we move any further so i'm going to run eval buffer again and i'm using the alt x command binding to um to call up in the lower uh left-hand corner of the screen you can see i'm typing eval buffer so i'm basically running the eval buffer command and what that does is take the contents of the buffer the emax list buffer and evaluate them into the emacs environment so now what it's doing is uh you can see let me switch to the messages buffer if i can get there messages so uh in the messages buffer this is actually a pretty useful thing so if you ever see a message pop up in the mini buffer at the very bottom of the screen and you're like oh it went by too fast i don't know what actually happened if you switch to the messages buffer make sure to note that there's stars before and after if you do that uh you'll see the contents of all messages that were print out printed out before so what we want to do right now is see what happened whenever we reload all of our configuration so um let's see okay so you can see that it contacted melpa to download the package repo there and then it started downloading a bunch of packages that we need for our configuration from elpa yeah use packages coming from alpha etc so uh now we'll move back to our uh excuse me keep hitting escape and it's causing me problems here we're to switch back to init.el and we're going to install a package called command log mode and what that's going to do is pop open a buffer on the right hand side of the screen or pop up in a window uh on the on the right hand right hand side of the screen that's going to show us all the key bindings that i'm using while i'm doing things so that you can tell what key bindings i'm using without me telling you and also what commands they run that's actually a really useful package so let's type use package command log mode and i'm going to use x control x control e to evaluate that and i can't have actually evaluated that fast let's see oh maybe it did okay so um we're gonna run command log mode i think there's a command for showing the window but i don't remember which one it is right now so let's see yeah let's let's do that so uh one useful thing that you can do whenever you're trying to figure out how a package works i mean obviously you would go try to find documentation first but um the the describe function or describe variable uh info panels that pop up will give you a link to the code where the um the thing was defined and if you click on that we can actually go into the code of the package which ends up being really helpful for finding certain things so if i want to toggle the command log buffer it seems i need to run the clm toggle command log buffer so let's try that now clm toggle whoops toggle command log buffer all right there we are and i'm going to move this over a little bit and let's see if it actually will stick with us oh boy wow did i just close emacs okay ctrl z ctrl z don't do that so uh let me get back in there because i think it just killed our emacs or actually probably what i did was suspend it but i don't know how to get back from that so we'll just go load it again okay i'm gonna go back to our init.el file and uh let's see one interesting thing about emacs is that it will save stuff that you're doing in the behind the scenes just in case you crash your emacs or kill it like i just did so you can see down in the mini buffer here it says consider running mx recover this file as you can see all of our stuff that we added for use packages gone now so let me try this recover this file and recover auto save it tells me about the date and time whenever the auto save file was created i'm going to say yes because i want to recover it so now we're back to where we were and i'm going to save that now so we don't lose it again okay so let's val this buffer again and now i'm also going to run global command log mode so that we can have this in every buffer and then i'll do the clm toggle command log buffer okay here we are so now if i do if i put my cursor on this and say control h f you can see over in the right hand side of the screen i did ctrl h f and then it uh that's mapped to describe function so this should be pretty helpful going forward okay so now we have uh use package set up we have our basic configuration going where we have something that looks fairly decent um moving on from here i think like the most important package that you can have installed um after just a very very minimum setup is one of the uh main two completion frameworks for emacs and those are helm and ivy i'm not really going to go into details about what's different between them because there are a lot of similarities they're just a sort of slightly different mentality in some ways personally i prefer ivy because i find it to look more minimalistic and it sort of fits into my workflow better so this is what we're going to use here however if people are interested in looking into helm i'm more than happy in a future stream to um to change the configuration to use helm instead so we can kind of compare and contrast those and also uh because emacs is sort of like an open ecosystem you can actually install both of them and use them simultaneously if you want to like if there's something that helm does in one particular context you like better than what what ivy does you can use them both and just run them in whatever context is necessary so it's not like you have to pick one and stick with it it's not like a vim versus emacs thing where they're completely incompatible no you can do everything all at the same time in emacs which is kind of great so let's get ivy set up i'm gonna refer to my existing configuration example again because i do not remember the default setup for that so i won't copy all this yet because uh it's not entirely necessary but we will talk about some of these configura configuration options in a bit so i'll paste this stuff in and um save the file and then i will try to run this i'll eval the buffer and this should cause iv to be installed so you can see down in the in the mini buffer there were some commands you could see like iv elis files being evaluated so now um what we can do i'm trying to see if we already have some bindings set up for this yeah okay good so we don't have any binding set up yet so if i if i were to say uh control x control f to find file i'm still going to get the normal find file command that is bound by default in emacs and that just gives you really simple completion in the bottom of the window here so instead of doing that what i'm going to do i need to figure out how to uh to cancel without vim mode setup so what we're going to do is we're going to uh remap the default binding for find file to use uh ivy instead in fact i think that we can just make that easier by i think there's a command you can run from council i want to say that does some automatic mapping or remapping of things but i do not remember at the moment ah okay here's one thing i really want to do at the moment that will save me some some pain and suffering here uh we're just gonna take a minor digression um i'm gonna add this uh little snippet that says for a global set key whenever you hit escape it's gonna run this keyboard escape quit command and that's going to be really useful for um keeping me from going crazy because i keep hitting escape because i'm used to using escape all the time so let's say if we open find file and i want to get out of that one way to do that i think is hit ctrl g um but another way would be to hit escape now that we've got this bounce so if i do this again hit escape it will cancel out that that mini buffer prompt which is pretty helpful if you are familiar with them key bindings so that's one thing to keep in mind so back to ivy let's see um i really want to find where that configuration is because i'm pretty sure i did not set that up myself it must be built into console i think if i just install console maybe it works if anybody in the chat knows just let me know okay i think that it must just be by default in council so i'm going to load cancel so uh the thing to know about ivy is that um the base functionality is contained within the iv package and it gives you this sort of buffer completion in fact let me just show you what it looks like before i move any further if i were to run iv find file i think where is it guys council here council's here council find file um then we get this better completion buffer at the bottom which um lets us see what files are in the current directory and we can also navigate the directories uh in a way that makes sense um that was not intended and like if i wanted to go to the readme.org i just use my arrow keys to go to readme.org and press enter and then it will open that file so that does end up being helpful or really helpful for navigating your file system quickly especially if you get some custom key binding setup to make it more easy to use so um now we're going to try to get the default binding setup and i'll show you what buffer switching looks like with iv so if i run console switch buffer then i can switch over to interesting okay um i'll try that in a second so i will switch back to init.el all right so uh vincent says uh that he doesn't have anything special for find file he just runs iv mode one and it sets everything up curiously it did not do that for me but let's try running it directly now if this works all right so yes that's correct so all we need to do is run iv mode 1 and by running that major mode it's going to set up all the key bindings necessary at a global level for the default emacs key bindings for finding files switching buffers etc all the sort of common things that you would need to do so um to prove that for switching buffers i'm going to use oh let's get the command window back i don't know why that disappeared clm yeah now see how much easier this is mx is another big one so anytime you see one see someone talking about mx the m in the front let me type that out so you know what i'm talking about m x so hey alex so m m-x is a uh a command-binding name but it has special significance in emacs because this is like the main way that you would run an interactive command in emacs so the m stands for meta but actually that maps to the alt key in most keyboards i don't really know what other keyboards might have that map to but for me and for the majority of people that i've heard of it's alt so if i press alt x we get this list now and this is coming from ivy also it gives us this nice view of all of our commands and uh i can run um which one was i was trying to do counsel something cancel switch buffer yeah so i could see i could fuzzy match basically if i just type out the command bits with spaces in between i can switch for certain things so if i type counsel swif buff it gives me everything with those uh sort of substrings in it so that can be really helpful for finding commands that you forgot the name of if you just know like sort of what you're looking for you might be able to triangulate it so um now we've uh we've used switch buffer and we can go up and down and go back to the init.el so at this point i mean we've got a pretty decent little configuration going uh there's some other things you can do which i find really useful if you're sort of exploring a little bit to try to make emacs look better you can run a command called uh console um let's see i'm gonna type the council theme it's council load theme if you can see this down here in the command list if i run that it gives me a list of all the custom themes that are available and you'll see that there's some doom themes here because i haven't isolated my um my personal emacs configuration folder with all my packages installed so apparently we're seeing some things that shouldn't be here but there is a small subset that are installed by default and i believe wombat is one of them so um actually i think i like that theme better so i might just stick with that one so if i want to go and make that the default i could go here to where oops where i set uh tango dark and then i can put this to wombat and then in my configuration this should get loaded by default whenever i start up from now on okay so um we're doing pretty good here we have just the basic configuration now um i want to talk a little bit more about use package and how it works um use package in fact we'll pull up the website emacs use package use package uh simplifies a lot of things that you need to do for configuring emacs to use a package that you get from the package request repository if you were to try to download packages yourself from like a github repository and then set them up you would have to do a lot of extra coding work in your configuration file to require the package to set up its mode to setting key bindings all kinds of stuff like that um with use package it takes care of all that for you which i find to be extremely useful there are some other packages out there that will do things like this for you i really haven't used them but i might experiment with that some in this uh stream series because i don't know it would be interesting to try them out but use package has been very solid for me for years so i just kind of stick with it so if you go look at their readme there is quite a lot of stuff here explains how to do a lot of things but the most important stuff is just that you can just very simply just say use package with a package name and it will just install it for you and make it available and it does not load the package by default or it might load the auto loads for the package so an auto load is basically a function that has a special signature on it in an emacs list package that says don't load my code at all until someone tries to run this function and then load it on demand so i think if the package has auto load setup then this really doesn't hurt your startup time because all it does is just try to install the package if it's not there already and then make it available to you so but the bare minimum use is just just that you just have use package and uh the package name now um you might see that i have something called diminish here um i probably should take that out so you can see what it's like without it but diminish what that does is uh typically in emacs there is a mode line which is this bar at the bottom of the screen and this gives you details about your um the mode that you're in the file that you're editing the the line column that you're at whenever you're editing the file it also says um what minor modes you have active and for some reason oh here it is yeah this is the list of uh modes in minor modes so the main major mode i should explain that as well but the main major mode is lisp interaction mode and there's a minor mode called ldoc installed or activated so i think with the init el file uh normally iv would have its mode yeah now that i evaluated ivy mode it's showing up here i'm not exactly sure why this is not running by default on startup i'll have to look into that but um yes that's probably why so whenever i load up the iv mode we'll see that it adds this iv down here but if you as you start to have a more oh thank you uh d-pass in that we want to re-enable the command log so c toggle command log buffer there we are thank you so uh as you get more in depth in your emacs customization you're probably going to be using a lot of minor modes for a lot of different packages that are installed and this list is going to get a lot longer and it's going to take up more of your screen space and it's going to be noisy so what i like to do on certain packages is to diminish the mode which does some stuff behind the scenes so that emacs will not show the mode name in this list um i don't really know like if people think that's a bad idea but for me i like to keep a very minimal view so that i don't have a lot of things distracting me whenever i'm using my editor or when i'm in my environment so i try to diminish things that aren't necessary so this is why i would add this diminish part here it just keeps that iv out of uh the uh uh the mode line also you can see that there's this bind section and this is super handy because otherwise you would have to do a lot of like uh define key or there's a lot of a lot of ways to bind key bindings in emacs but this happens to be a very straightforward way to do it which i find to be very nice so um you'll have to look at the documentation for for buying because there's a lot of things it can do but at the at the top level what you can do is just say for the command-s or command-s keybinding i want you to call swiper so if i was to hit control s right now did that command control control s now that calls up swiper um are you saying alex are you saying it's difficult to read right now alex says that the bottom of the emacs window is difficult to read so uh this binding was set up whenever use package loaded um ivy and there's also this idea of key bindings that are specific to certain modes like a major mode or a minor mode which right now you see there's like the iv mini buffer map um that is like keybinding that's only active for a very particular mode so one thing i like to do for iv that makes a lot more convenient for me is that whenever iv is displayed in the minibuffer whenever we have that sort of selector list i like to use ctrl j control k to select the next and previous lines so that i don't have to leave my home row of keys the way that i have my key binding set up in my linux distribution is that i make caps lock work as a control key so that i have my hand on the home row all the time and i can use my pinky on caps lock to do control instead of like bending my finger down there uh you've probably heard a lot of people talk about emacs pinky because if you have to keep hitting control all day long to do all these key cores and whatnot it could be really taxing on your finger if you do that simple little key binding switch where you replace capstock with control it makes your life a whole lot easier in emacs so i highly recommend doing that it is possible to do that across linux mac os and windows so uh at some point if people want to know how to do that i can add some instructions to the the readme of this repo so that you can uh you can see that so alex says that the bottom line is kind of half cut off let's see if i can fix that if possible does anybody else notice that where the bottom line is cut off of the screen capture can't tell yeah ah okay so it's a youtube problem all right anyway back to the story so um so what we're going to do is i'm going to show you what it looks like with iv and i think the command log window here should uh be able to to give us that information i just hit escape and it disappeared that's not cool let's pull that back up again clm toggle command log buffer apparently escape kills it i need to find a way to make that not happen so thanks bruno all right so i'm going to pull up uh the console switch buffer command oh actually i can do it here so now that i'm in um this list i can hit control j control k to go up and down so i don't have to use the arrow keys anymore to select these i can just use control j control k and that helps me to navigate these without leaving the home row and uh if you use a computer a lot all day if you're a programmer and you're typing on the computer all day the best thing you can do for your hands to not get super tired is to stay in one place and not jump around a lot or not contort your fingers to do key bindings and also try not to reach to the mouse all the time either or to the touch pad so um if you can avoid that as much as possible which emax does enable in in large part you should try to do that because uh it will save your hands a lot so um we see now that we can do that unfortunately this uh command window is not showing that probably because it's in the mini buffer um unfortunately that's the case but let's this thing keeps popping away this is what happens whenever you just get like so used to e to vim key bindings is that you just hit escape all day long just unconsciously just to clear out whatever you're doing and then it causes problems whenever you don't want it to all right so um i mean i think that we've gotten to a pretty good place with this today so moving forward what we what would we want to do so uh one big thing we can do to make this look better is to set our mode line to something more appealing and if you see what i have in my [Music] setup i have this nice more minimal looking mode line that has a little bit of icons and some you know nice fonts and colors and whatnot that's doom mode line so if you use doom emacs you probably are familiar with this already if you've seen um oh maybe maybe you're right let's try that real quick global command log so um deepass and says or deepass and i'm sorry if i'm pronouncing your username wrong uh it says that probably global command log mode needs to be run before the mini buffer commands will show up and i believe you are correct so if i go yep there we are so i'm hitting ctrl j in the list and ctrl k and it's going up and down so uh various suit observation i appreciate you telling me that so um going back to the mode line discussion um yeah i i find this to be very um minimal giving me only the information i need to be doing the work that i'm doing um i think the default mode line in emacs is quite cluttered and um kind of like really just looks old i mean it's all text characters and stuff and it gives too much information so for your ability to focus and also your sort of aesthetic pleasure i guess you could say having a more minimal mode line that has a nicer style can be can go a long way to making you feel more at home in emacs so we could try real quick to see if uh do mode line is easy to set up in this case so i'm just going to go to the doom mode line github repo and see what happens there because i think that the default configuration is pretty good and integrates with a lot of packages that you might use so it's a good place to start if you wanted to have a nicer looking mode line they have a lot of screenshots for what do mode line can do which is nice um so i init yes all right so we're going to copy just this little snippet here and throw it into our configuration file and then i'm going to i'm going to execute that with ctrl x control e all right and basically right away it uh configures itself to look much nicer so um the one thing i can say about this is i find the height of the mode line to be a little bit tall for my pleasure to start with there is a variable you can use to configure the height i keep having to open this thing again and um i've had sort of varying success in using it i mean obviously you can see my mode line is not that tall so um i think that there's a little bit of combination of setting the mode line height plus the uh the font size for the mode line um can help you to manage that size let's see what it says here size or height okay customizable mode line height so if we were to set um i think this configure so config this is another thing in there there are two things for use package i'll describe right quick whenever we do this but let me just get this added really quickly um in fact let me look at my own configuration uh emacs.org so mode line height okay 15 i have mine set to it and it's in custom all right cool it's like this all right so um i'm going to paste that in and then we'll finish that out whoops all right cool unbalanced parentheses this is what happens whenever you paste it in it correctly also we need something that will show us the parenthesis balance void function do mode line height really oh okay i need to have an extra um parenthesis around this is why i was giving me problems that's interesting let me see what did i do wrong here custom that's right okay so config is wrong we will try running this one more time okay so uh i think that i need to restart doom mode line for that to work and it's hard to tell whether it actually did anything but sometimes it you actually have to go to a different buffer before you will see the effect of doing that so if i were to go to another file let's say i go to package.json file okay it still seems to be fairly tall but um suffice it to say um there is some configuration capability there um and we won't worry too much about that right now i mean i think it looks pretty good as it stands so uh one thing that you can see here is that we actually have an icon for for node.js or for npm whenever we open a package.json file so that's just one of the nice little niceties that that doom mode line can give you so i hope that uh with this little intro i have convinced you that writing your own e-max configuration is not that hard and it doesn't take much code and you can get something that looks really nice very quickly this obviously is not organized very well it looks kind of dirty but there's a lot of things we can do to fix that up going forward so we will look into that in future streams um i think maybe next time we will try to set up some other packages possibly like my git or other things that i find to be pretty useful um and please definitely give suggestions if you have other packages you would like to talk about in the future streams like either you can give them in the chat or ideally in the comments of the video after the stream is done so that we kind of have a history of those because the chat kind of disappears after the stream is gone but um yeah for now i think that we can call that finished for the stream if you want to see the contents of this file um actually i will show you one thing real quick as a little a little bonus at the end i'm going to make a commit of these changes i'll just back out of this emacs right now and go back to my own let's not save that one yes exit okay so i will open up the init.el here so this is the actual same file and i'm going to use my key binding to pull up uh migit status and uh what this does is it gives us this buffer that tells us about uh the current status of our git repository and i'll show you what repository that is in a second um we have our untracked files here and i want to commit my init.el so i'm going to use my keybinding for that and actually i can pull up a command nicer looking command log here since i've set my stuff up correctly command log window yeah okay on this computer it's not working it works on a different computer we'll do that another time so i'm going to stage this file for for commit and you can actually see that we have all the contents of the file here uh also it helps helpfully shows me that i have some errant white space at the end of that line so i'm gonna get rid of that and uh now i'm gonna make a commit by hitting cc and uh initial commit of init.el and i'm gonna hit control c control c to finish that commit i'm going to hit capital p then p to push it to the repo and then i'll put in my passphrase to do ssh auth against the repo and now it's finished so we can go over to the repo page i've got this called it looks like it's called run emacs um which if you've ever used emacs on windows you've probably seen the run emacs command but a co-worker of mine whenever he downloaded his emacs hi chris uh he saw run emacs and he says wow this comes with rune max so uh we're going to call our custom configuration roon max just uh as an homage to my co-worker chris um so now i'm going to reload this page and you'll see that init.el is here all the stuff that we worked on in this stream is available so if you want to go and take that and start hacking on your own configuration please feel free um this is another place where you could file issues if you wanted to like ask questions or uh give feedback or you know like request certain packages to be uh given demonstrations of etc so uh please do feel free to like leave comment on the video or in this repo if you want to see more things in the future so um any final questions from the audience here before we in the stream today uh by the way thanks a lot for everyone showing up it's really cool i think this is the highest viewer account i've had on the stream yet so it gives me a lot of confidence that emacs is the way to go at least in the short term on the streaming front i'll give people a couple seconds just to ask any questions if they have any also uh if you want to see a more complete system configuration that goes far more in depth on emacs as a desktop environment and window manager uh check out my dot files repo it's at github.comwheels.files and if you go down to the readme here i've kind of explained my principles and stuff kind of lame but uh it links to my different configuration files so how i configure emacs how i configure my desktop environment and how i configure my linux distributions uh all using emacs all using org mode so if you were to go to my desktop environment configuration you can see that i have a whole lot of stuff here that configures both emacs packages and also things like polybar and dunst and other programs that kind of put this whole desktop environment together and all these configuration bits actually are used in my system they just get written out by org mode whenever i save changes to the file so this this file is like my source of truth um whenever i am changing my system configuration and then the sort of files that get created by that are sort of ancillary and i still check them in but uh but they they aren't really the ones that i added i added my org mode files to configure all my systems so that's another interesting topic to talk about on another day uh bruno asks maybe demo install projectile yes that's a great point i should do that probably on one of the next couple streams so uh yeah we will definitely talk about projectile if you do coding with um get repositories of various different types of languages and whatnot you definitely want to use projectile okay well i think i've had your attention for about an hour now so i'm gonna go ahead and call it here but uh thank you again so much for joining us today i hope to see you at the next stream um i'm gonna target possibly monday possibly wednesday for the stream so just keep a look out uh for that uh subscribe to the channel if you want to be notified whenever uh new streams are scheduled or started on the channel if you hit subscribe also hit the bell as well because sometimes youtube doesn't send out the notifications i don't know why it does that but just make sure you hit the bell in case you want to be notified whenever the new live streams are coming but uh anyway thanks a lot folks we'll see you next time happy hacking
Info
Channel: System Crafters
Views: 72,911
Rating: 4.9255934 out of 5
Keywords: emacs, configuration, vanilla emacs, ivy, exwm, magit, org-mode, org, doom emacs, spacemacs, vim, evil, live-coding, live coding, coding live
Id: 74zOY-vgkyw
Channel Id: undefined
Length: 58min 29sec (3509 seconds)
Published: Fri Sep 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.