We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Gavin Freeborn · 8.0K views · 363 likes
Analysis Summary
Worth Noting
Positive elements
- This video provides highly specific, actionable Elisp code snippets and regex explanations for customizing the Emacs compilation buffer.
Be Aware
Cautionary elements
- The sponsorship segment uses 'parasocial' framing (sharing personal life updates like a haircut) to soften the transition into a commercial pitch.
Influence Dimensions
How are these scored?About this analysis
Knowing about these techniques makes them visible, not powerless. The ones that work best on you are the ones that match beliefs you already hold.
This analysis is a tool for your own thinking — what you do with it is up to you.
Related content covering similar topics.
Java classpath tutorial (ClassLoader, NoClassDefFoundError, JVM, javac, javap -c, java -cp, jar cvf)
Fred Overflow
Emacs: easily set timers with TMR
Protesilaos Stavrou
Embedding Scheme in C Apps with Chibi - System Crafters Live!
System Crafters
Declarative UIs in Emacs with vui.el - System Crafters Live!
System Crafters
Emacs Goodies - #7 Proced Mode
Goparism
Transcript
how's it going everybody I love emac emac is a perfectly great editor and it has a lot of amazing things built into it and one thing that I think I as well as probably the majority of people that have used emac have wanted to do is compile programs run tests and run interpreters you know the usual stuff that you would expect to be able to do in an IDE now I've seen a lot of people create packages and come up with their own personal ways to do this in emac however I don't think as many people realize that this is built into emac you don't need to use some special Plugin or package to do it and it's actually really powerful and I see a lot of useful features that I don't see enough people taking advantage of so in this video I wanted to dig into the compile package which is built into emac that can be used for doing all of these different things and more hey everybody future Gavin here yes I did get a haircut thank you very much for noticing now in this video I'll be referring to the programming language python quite heavily if you aren't familiar with python and would like to learn it for free be sure to to check out today's sponsor brilliant brilliant offers an amazing interactive and multi-level python course and if that's not your thing then maybe try and dip your toes into any of its multile levels of math data science and computer science courses with new courses every month you'll never run out of content and you'll never run out of learning opportunities in addition to brilliant letting you learn at your own pace it can make the chaotic life that a lot of us live much easier and much more of an opportunity to learn at any given moment whether you be sitting on the bus waiting for a call anything like that you can always pick up brilliant and get a little bit of learning done each day for me this has been a huge impact in my life since I don't have a lot of time day-to-day to research and learn new things now I only have a few minutes to myself every few days because of that brilliant's been a huge help in this area since I can pick it up for a few minutes do a bit of learning and since it's so interactive I tend to absorb it a lot better than a big binge moment where I try to learn a bunch on a topic in a few hours to try everything brilliant has to offer now for free for a full 30 days check out brilliant.org Gavin Freeborn the first 200 of view will get 20% off Brilliance premium annual subscription now let's get into the video now for this video we will be using the compile package so we can just evaluate that eisp right here just to get the compile package installed and then what we can do is we can use MX compile and this will by default it will give you make- K and so this is basically a simple one if you're using make files for your project um but that's not very helpful in our case cuz we're not going to be using make we're going to be using python and a python file so just to open up a python file right here this is just a temp file and we can go ahead and try this out so we can do alt X compile this will give us a prompt where we can put in any command we could do pilent python we could even run any program on this really and by default you could also do it without the file name obviously so hitting enter on that will simply run python tmpy as you'd expect and this will give us the result right here hello world and and if we do compile again we get the same result we can also do uh recompile and this will just run whatever the last command we had was alternatively in the compile window you can hit G and this will rerun as you can see down here recompile which is pretty powerful now if you're in a project and you're using project. you can use control xpc and this will do the same thing but it will compile from wherever project. thinks the root of your project is which is pretty helpful and we'll use that later on in this video so you can use the compile command for a bunch of different things the most important one is finding errors so by default if you are in our python file and we made an error so let's put l at the start of this and let's maybe hit a couple extra lines just for the sake of uh showing this and then if we did compile and we compile it you see that we will get an error now we can actually navigate between these errors by hitting n and p by default and enter will actually take us to the error itself so how does it know about these errors well it's using special filters that we'll talk about later in the video but this is super helpful and Powerful for General debugging and testing and stuff like that now compile has a few other useful features this is uh one that I got from the emac wiki actually is if you go to a file like this this right here is an X resources file and whenever you modify an X resources file and you want to update it you have to run a command called xrdb and then the file name which right here I've added this little comment which will actually set the compile command so if I run alt X compile it actually sets xrdb and the file name as the compile command so you can actually use it for a bunch of different stuff um other than just compiling code and this is a really easy way to set it on a perile basis for example when I was using dwm actually I have a little uh shortcut right here so that way when I do compile it will do pseudo make clean install which is uh super useful and so you can use this for basically any file alternatively you can set up a default command so right here this is basically a really quick little command it will set the local variable called compile command this is what compile by default uses and I'm basically con catting python with the current buffer name so let's go ahead and add that and then we'll add this to the hook to python mode so whenever I open a file in Python mode this will be a set up for us I opened it brand new this time and so when I do compile instead of giving the US the previous thing that we had before it's able to actually determine the path for us so let's just go ahead and test this out with our error here and when we do compile yes it will give us the error message as we would expect so what if we want our errors to scroll so for example if we get a ton of Errors let's go to D.C and we do compile make clean and make so this will just basically rebuild our project we get a bunch of errors but by default it's not going to know to auto scroll to kind of just bring us to the bottom and so what we can do to do that is just evaluate this emac code right here and then if we go ahead and compile again it will scroll our errors with us which could be very helpful now what if our compile command produces colors well this is pretty easy to handle so let's go ahead and give you an example of what this would look like so in let's go to this project and we will compile but instead of using our previous command what we're going to do is we're going to do gp-- color equals always and this will be searching actually let's search for base so this will be searching all throughout this project and as you can see right here we are getting a bunch of garbage because of the Escape sequences so that's not going to really work for us so to solve this we can use the an color package as well as this filter right here um which I will link both these down in the description this basically adds an extra filter to our compilation buffer to basically filter our ansy colors into something we can can actually use so let's go ahead and go back to here compile run the same compile command and now as you can see we get pretty little colors no longer all these ugly Escape sequences now this setting right here for the special environments isn't useful for everyone but say for example you're compiling something and you need to set some special variable so here I'm setting the home directory as root for when I'm compiling things and if I go ahead and do compile and we Echo home you'll see that we get root now if I was to get the environment of home we would get Gavin okay because this is only available in the compilation buffer uh super useful if you guys are ever um needing a special environment that's not going to be available when you're programming this is kind of useful if you don't want to mess up your LSP but you need to do some special compilation settings um at certain points this can be useful for that now I alluded to a way to kind of set up different filters I talked about the sort of filters that were able to determine what kind of Errors we're getting and so these are actually determined using a regular expression now there's two important variables we have here so if we did uh let's go to a python project and if I did actually let's do a smaller python project uh if I did alt X compile and I Chang this to pyite Dot and hit enter just give it a second and we will get a bunch of errors and here we go so as you can see we have a bunch of errors but it's not really able to kind of determine where the errors are coming from and so this is because there isn't a regular expression available for it to use if we go back here and we look at these variables so we do hvv and we take a look at this variable this variable is basically a list of different filters it can use or different regular Expressions it can use and there's a big old breakdown down here and basically all these values are looked up in this compilation error rega XP aist aist so the A-list A-list is an a list of all these different values that we get rather than the original which doesn't really have anything other than just these symbols which are basically references to the actual regular expression in this A-list down here so what we need to do is we need to basically add a symbol which is going to represent our different compiler and we're going to add that to just the regular A-list and then we also need to actually add something to the um the A-list A-list I know kind of annoying that basically references that symbol and the regular expression and then how we want to match that regular expression to each of the different uh values so here I've set up one for pyite but we can actually kind of derive something like this on our own so let's go ahead and go to the errors and so what we can use to derive this is we can do alt X and we can do regex Builder now what we can do here is we can kind of come up with how we want to do this so what we want to do is we want to capture things so as we can see our error messages are basically two spaces so we want to do back slash back slash space why do we need two backslashes well a backslash is an escape and since this is a string we need two backslashes and if we did that again in space then we've matched those two spaces leading up to it now a back slash backs slash and a parenthesis this will basically capture something and so now what we want to capture is we want to capture uh any combination of a slash A to Z A to Z basically saying you want to capture against a slash any letters we also need to handle a dash or an underscore and then we want to repeat that so any repeated thing of any of these varieties so this will capture our file oh and I forgot the period there we go now we can capture the pi at the end and so that will capture our file name now we need to do a colon and then we need to capture our line number so doing the same thing we will do 0 to9 Plus so basically any number from zero to nine and then that's what we are going to capture and then colon and then we need to do the exact same thing because we're basically instead of capturing a line number we're capturing a column and that should be enough for now so as you can see pretty easy to capture all of this stuff and then you could just say do a DAT star dollar sign uh basically just as a way to capture everything else all right cool now we have created our regex now if we put put that here it's basically I think it actually is identical yeah okay that is identical to what I ended up writing originally now we want to add this to our a list aist but the big thing that we still need to do is determine how we're going to map from this file which is here the line number that is here and the column number that is here now the nice thing is that basically the way that the actual matching works is in our A-list we give it our um obviously the symbol to match to it we give give it a regular expression and then each of these represents one of the things that we've captured so the first one is our file the second one is our line number and the third one is the column now if we were to transpose this that basically means that the first thing we captured was our number our line number the second thing was our file and the third thing was our column uh so basically luckily it's pretty self-explanatory out of the box when you go into this so if you actually look at this variable it explains it decently well um but you'd probably want to look at it so basically what's our reex and then the first thing that it captures is your file and so we just say that the file is the first element and then optionally you can give a line number you can give a column number and a type that's kind of how you can add your own filters if you have questions about that feel free to ask me because I feel like this was actually kind of a questionable example to use um but yeah now we can add it by doing CR X CR e on each of these guys and then if we go down into here and we hit G to rerun our compile compilation we will actually get something useful and there we go so now we can like navigate by hitting NP and we can see all of our errors very powerful very simple okay now this one is kind of just something that I never expected to see in the editor but I found really cool and so that is if we go to a Shell let's go to the same project we were looking at before and we did pyite dot so there we go we get our errors now obviously in the Shell we're not going to have the same available to us as we did in compile mode but you can do shell minor mode hit enter and this will actually allow you to use those very same regular Expressions as you had previously and then if you do contrl alt P this will navigate between them and if you hit enter it will jump to the file and you can use all those same rxes it works exactly as you'd expect it works with your mouse too now this is pretty sweet but some people don't even use the shell uh functionality well let me tell you this it works in other places there's even more uses for it so let's go ahead and kill this shell and instead we will open V term now in V term if we CD to the same thing CD Aries uh endorser and we do pyite dot we get the same errors just a second and there we go we've gotten the same errors now if we enter the same mode yep that's right it works just as you'd expect most support and everything even in V term which is super awesome not really something that I expect Ed to see and I actually was just only recently told about this the other day so pretty cool a really awesome feature if you guys make a lot of use of the shells or terminals you can make use of the compilation functionality right from there anyways guys I appreciate all of you for coming and watching this video I hope that really last part got you as excited as it got me excited when I found out about it because even though it's not something I use every single day it's something that every once in a while I'll find like a back trace or an error message in some logs when I had a shell open and I can just run this and boom right away I can jump to the errors and I don't have to like reverse engineer where it would be which is really awesome uh highly recommend giving some of this stuff a try especially just the general compile functionality um yeah anyways that's about it for me today uh I would like to give a big shout out to my supporters on patreon and GitHub sponsors you guys have done so much for me um yeah it really means a lot that you guys have supported me especially when you know sometimes I'm not able to upload as much as I would like and yeah I I really appreciate it great seeing you guys great talking to you and I hope you have a wonderful [Music] day
Video description
To try everything Brilliant has to offer—free—for a full 30 days, visit http://brilliant.org/GavinFreeborn/. The first 200 of you will get 20% off Brilliant’s annual premium subscription. This tutorial is focused on Emacs's Compile package. We can use it to lint, compile, and run our code. Let me know what you think and if there is anything specific you would like to learn about. Emacs Config: https://github.com/Gavinok/emacs.d ----------------► Come Join The Community◀︎---------------- LBRY: https://odysee.com/@GavinFreeborn:d Matrix Space: https://matrix.to/#/%23gavinfreeborn:matrix.org Discord: https://discord.gg/JJk5KKU This video was sponsored by Brilliant 00:00 Start Of Video 02:04 Intro To Compile 03:14 Compiling Projects 03:29 Navigating Compilation Errors 04:07 Per File compile-command 05:01 Per Major Mode compile-command 05:41 Auto Scroll Compile Buffer 06:11 Handling Colors & Escape Sequences 07:11 Setting Env Variables When Compiling Code 07:56 Creating Your Own Filters (optional) 13:11 Finding Errors In Shell-mode and VTerm 14:42 Conclusion