Waiting..
Auto Scroll
Sync
Top
Bottom
Select text to annotate, Click play in YouTube to begin
00:00:00
[Music] hey everybody and welcome back stevie's tech talk this week i do not have a guest lined up so i am going to do something new and exciting and a little
00:00:17
bit different for me i have figured out how to get obs to do display capture and so i'm going to do a guided tour of emacs i'm going to show you some of its features and and how
00:00:30
emac sort of approaches things and i'm going to show off a bunch of little mini applications inside of emacs and talk about some of the editing facilities that you won't find anywhere else i'm going to do it all as i sit there and type in real time
00:00:43
i apologize if you're on the podcast you can't see what i'm doing i do my absolute best to narrate everything that i'm doing generally speaking emacs is fast enough that you can do it as you're narrating it so just imagine that what it's going to be like and if you like
00:00:56
the the content then come back and watch this youtube episode uh so we'll get to it shortly but i just want to remind you that if you do like this content and you want to see more of it more guests more episodes and you want the show to
00:01:08
go on then please all you got to do is you got to like it and subscribe to the channel and then youtube takes care of the rest for us so with that let's get started all right we are officially looking at emacs
00:01:20
hope you guys can see this okay this is not normally the aspect ratio that i run emacs at usually i run it very tall and kind of narrow but because of the screen recording limitations it looks like it's going to be best if i run emacs looking
00:01:34
sort of like a terminal here so what are we looking at here emacs looks kind of like a shell in fact it even says shell here at the top and it says shell here at the bottom on this line right near the bottom called the mode line
00:01:47
mode line shows a bunch of information about the buffer that you're currently looking at now everything in emacs is a buffer this is a little bit actually this is a very different philosophy than most
00:02:00
programming environments or even productivity environments like xcode or final cut pro or you know any sort of a development environment they usually have a couple of different dedicated
00:02:12
areas right you know one for your code or for a timeline or for a preview or for a directory browser or whatever and then they have a whole bunch of menus and they have they all they're all special purpose they're all custom ui in
00:02:26
emacs everything is treated very very consistently as you can see what i'm looking at right now is two buffers and i'm switching back and forth between them the one on top is a shell it's just like a regular terminal shell except uh it's
00:02:39
an e-max shell so it's implemented in lisp it doesn't have all of the vt-100 codes and so there are certain things that if you try to run like top you're going to get strange output however you can run regular unix commands and
00:02:52
it'll dump all the output and then because it's an emax buffer which means it's just like the kind of editing area that you would have for your source code all this shell output a lot of processes
00:03:04
running no idea why so many processes are running on this machine but as you can see it's just like a regular buffer i can move the cursor around in it i can cut and copy things i can select regions i
00:03:16
can do pretty much any editing command on the shell output which is great because uh you know if i do a command you know like um like here i'll do an ls and look at the directories uh that i'm looking at currently i'm in my in my
00:03:29
game directory for my online game and it looks just like a regular shell but if i go up and i can grab a command i can bring it back down again and paste it and
00:03:41
then modify it before i execute it again so it's a really common thing you can still use the standard shell commands like normal but it's really powerful to be able to take this funk of text right that came out of this uh this
00:03:54
directory listing go to a temporary buffer i just gave it a name asdf asdf and now i can start editing it i can sort the lines right or i can i can delete a whole column right i can say oh
00:04:07
let's get rid of this column right here and all those tvs disappeared right and let's make all the staffs disappear too boom right so as far as text editing goes it's very very powerful i can i can um
00:04:20
right i can write little bitty macros and stuff to start making modifications um you know um like the ones that i'm doing as you're watching i've i've just been doing a
00:04:32
whole bunch of very fine-tuned uh little little edits so basically the philosophy of emacs is everything is a buffer well what do i mean by everything well we can run calendar and look it says february march
00:04:46
and april and the cursor moves from day to day and um i can um even see all the different holidays from a bunch of different uh systems but if i go and i say h on
00:04:58
february 14th it tells me it's valentine's day so this is a buffer which means again the text is all editable you can have read-only buffers but you can always mark them as not read only
00:05:10
and it means that all the emacs editing commands are available another example of a buffer is a scientific calculator oops i just did calendar again calc the scientific calculator as you can see this one
00:05:22
is a two buffers down at the bottom of my screen one is the actual calculator so i can uh put a bunch of numbers in and then i can stack and then i can start hitting plus some
00:05:33
times and whatever and i can see the entire history on the on the right side here of of all the numbers the intermediate results it's a very powerful scientific calculator as you can see what i'm doing right now
00:05:47
is i'm hitting the question mark key and it's telling me what all the key bindings are for you know sine cosine and exponentials and pi and whatever it's actually a really really cool calculator but the coolest thing about
00:06:00
it right is what if i just wanted to like go up to this buffer here and take these uh numbers right here you see i'm going to do is i'm going to take and i'm going to kill this column
00:06:13
and i'm going to see you can deal with columns of numbers just just as easily as rows of columns of text just as easily as as columns as as rows and emacs i can put them here and look i just
00:06:27
pasted them all into the calculator right now they pasted uh they just kind of funny but let's see if they add up oh yeah they do look i can add them all up so i just added up all the file sizes of
00:06:39
those last 10 files i listed in my directory by by pasting text from one buffer into a temporary buffer here i didn't have to but i just wanted to see if it would uh if it needed any cleanup first and then
00:06:52
i pasted it into the scientific calculator and i'll and i've had all my immediate results really pretty cool uh similarly the list of open buffers is itself a buffer so here i'm looking at
00:07:05
this is effectively all of the open tabs that i have in this emacs session okay as you can see a lot of them 20 plus are shells why do i have so many shells open okay well they're all named here's one for the server and as you can see it's in
00:07:18
the server directory what i did was i set up a function called wyvern init which and it's my initializes all the stuff that i want to open in emacs and then it just goes and it opens up a bunch of files and a bunch of directories because i'm always visiting
00:07:31
stuff in these directories like sandbox this is from my sandbox server which was where the the builders and architects of the game go and test stuff out before it goes live so it's like a staging server so each one of these shells is its own
00:07:44
process right and it's it's running an emacs and i can copy and paste stuff in between them all i can make modifications if i want to change all these us central 1bs to us central 1c
00:07:56
right uh for for whatever reason maybe i'm uh you know writing a document and i want them to show up differently in the doc then i got the listing so i can just say replace string central one b two central one c and boom
00:08:11
just change them all inside of a shell buffer this is a running shell see i could still do commands here in the shell but the text all up above is all editable and so it's kind of it's kind of cool because it knows where the
00:08:22
prompt is right my command prompt is set up so that it shows the directory that i'm in and i can go back up to older commands and hit enter or even modify them and hit enter and the
00:08:35
commands are all available so you can go all the way back into very long command histories find very old commands that you've written and like this one right here which does build it's an alias and and run them again boom and it
00:08:47
copies it down to the bottom and starts my build again and here's the gradle build output okay you say well this doesn't sound uh all that exciting um so it's got a calculator it's got a calendar
00:09:00
uh you know there's all kinds of basically you can write apps for emacs and it's quite easy to do like for example the old push a ball game soca bond let's install that so if i do package install
00:09:14
and uh then i say superbond so no i don't have installed here it's contacting the host it brought in two files and it installed another actually rather
00:09:26
quickly while my build was running in the background as you saw my gradle build which just completed successfully so now if i do soca bond the command notice the commands are going in the very bottom here that's called the mini
00:09:38
buffer it is also a buffer it is editable i can move the keys around and i can treat it like any other buffer i can copy text in and out of it but it is a little bit special because it's where all of your input and some of your
00:09:50
output goes you see how it says no go no goal column there at the bottom just as a segue i have a nervous tic um i i'm constantly unsetting the goal column goal column is where like let's
00:10:03
say it's it's kind of like multi-cursors if i always want the cursor to go to this column right here where i've got it on this this this row of uh uh of liver and dash whatever's then i can go control x control n and now i
00:10:14
have a goal column of 14 right and so now whenever i move the cursor onto the next line it always goes to that column right which is useful for if i want to um you know put something
00:10:26
right like at the beginning of each you know whatever you can actually do real multicurses and so on the goal column is a very old concept the problem is it's very easy to accidentally set a goal column and it's annoying and so i'm always on setting it and it turned into
00:10:39
a nervous tic see how it says no call call coming control u control x control n so unfortunately yeah that's my that's my nervous take when i'm when i'm in emacs is i'm always calling unsetting the ball column
00:10:51
just to be sure that there isn't one i guess but those messages where are they going well if i go to a buffer called messages which is one of the built-in emacs buffers i can see every message that it's given me since i started this session
00:11:04
right it's kind of handy and it's also in a buffer which means i can go and i can grab it and i can copy the text out go into a temporary buffer which is just a scratch pad a workspace i can put whatever i want there i can
00:11:16
paste the text in from this other buffer and boom i can do the same sorts of things i can sort the lines i can filter the lines i can you know list matching lines for quit it'll show me which ones and look
00:11:29
i did list matching lines of quit and look at that the output is yet another buffer and as you can see buffers are responsive and reactive they have their own mode this mode is called occur which is listing occurrences of a
00:11:42
particular pattern and some other buffer everything is a first everything is first class in emacs it's always a buffer the output is never in some dialog box right with its own fancy ui custom ui
00:11:54
it's always laid out in a buffer because that means that you can do all of the standard emacs editing and searching and sorting and all the other options that are available to you on the output of some command right or
00:12:08
on the output of some program so let's run that sokoban game we installed earlier boom look now we have sokobon with really ugly graphics but as you can see we can push the blocks around and uh if i wanted to the nice thing about
00:12:21
emacs is everything is customizable the source code is all there available to you i can find the function sokoban right it's defined in sokobond.el which we installed as a package just at the
00:12:33
beginning of this video and i can go there and visit it and here it is here's the sokoban um starting function that says what what all the keys are move left right notice that it says soca bond move left
00:12:45
soca bond move right those are commands that will actually move the little dude let's go back to our silver bond so that we can see here it is so in the right hand side i now have the sokovan source code
00:12:59
there's some of it i guess yeah this is it's all of it and on the left i have the actual sokoban game with graphics and everything they're terrible graphics i could probably change them to be graphics from my game which is a lot prettier
00:13:12
uh but whatever you know it works but uh hey i'm used to playing soccer bond with the old hjkl semicolon keys and unfortunately they are not bound for succubon right well i can do it manually i can say
00:13:25
local set key in this buffer because every buffer has its own you know large data structure of all of the currents configuration settings the whole context specific to that buffer including your key bindings and i can say
00:13:39
set h to circle bond move left which will auto complete for me and now i can use h to go left right and but but but l still doesn't go right for me so i'd have to do local set key again and i
00:13:52
could say l and this is what commands circuit bond move right and uh now type it on this computer i can move left and right with my h and l keys and i can also do up and down well if i wanted to
00:14:06
do that permanently let me show you what i would do okay i would use something called a well i'd use the scratch buffer which is a lisp editing environment it's very
00:14:17
powerful and i'd say um eval after load uh sokobon right meaning run this after i load sokobon or even better maybe there's a hook let's search to see the so-called source code there are no hooks so they
00:14:31
really messed this up so it doesn't matter emacs is still very powerful and can let you do things i'm saying allowed val after load so bond and i'm going to say um do a bunch of statements local set key
00:14:44
you know uh h two circle bond left and and then and so on and do the rest of them right and then put this into a config file somewhere one of my startup
00:14:57
files and app and it will it will put in this little snippet of code where after the sokobon game is loaded it will run my code that does modifications to the mode and in my case i add i would add four
00:15:08
different key bindings right so it's it's very squishy and very flexible uh the e-max shells that they're not like i said they're not full vt-100 compatible you know anti-terminals and that sort of defeats
00:15:20
the purpose um they're they're squishy meaning you run commands and you get the output and then you have a lot of customization ability you have a lot of ability to go back scroll through the output
00:15:32
you know search through the output copy and paste it and so i find that for most stuff having lots of shells seeding to the different directories is just like a super great way to go to work
00:15:45
and as you can see the buffer list itself i don't know if i said this the list of buffers these are the open tabs is a buffer and so again all the motion commands and all the searching commands and editing commands plus every every buffer has its own mode
00:15:59
okay meaning the key bindings and how it responds to you know mouse and how it how it colors things and a bunch of other settings and in this case we're looking at a mode is called buffer menu
00:16:11
that's the that's the major mode meaning the primary mode for buffers that are your buffer list when you want to list all your buffers this is so much more scalable than tabs in a browser or tabs in an ide because they're sorted
00:16:23
vertically and you can actually see metadata for each one of the buffers you can see the name of the buffer here and whether it's modified or whether it's read only you can see the total memory size how many bytes are in the buffer
00:16:35
and what mode it is and if it's uh cd to a directory what what the current working directory of that buffer is right really pretty cool uh because it can go on you can get thousands of effectively open tabs i
00:16:49
mean normally like you would be like order of hundreds probably be unlikely you'd have thousands but you could in certain situations and the thing is that becomes completely unmanageable in an ide or in really in any program that uses the tab model i
00:17:02
don't understand why people haven't stolen this model of the e-max's model of of everything being a buffer and that includes the sort of ui for managing other buffers but hey
00:17:17
it's something that only emacs does well all right one thing that you can do here is you can see that i have a gz file so a gzip file it looks like a an emacs lisp file and
00:17:30
so i can just open it up right oh it says the buffer has been killed so let me see if i can find another example let's go to documents and inside and zip uh there's one
00:17:43
okay so what do we got here we've got obs lut pack what does that mean a lut is a look up table it's a it's a filter for giving maybe cinematic effects to your video recording obs is the
00:17:55
broadcasting studio software open source that i that i use and right now we're looking at a zip file in emacs in a shell looking at the document directory we're going to go ahead and open it up so let's open it
00:18:07
obs let pack well what's inside of it well one cool thing is that we just opened a zip file inside of emacs and now we're appearing at its contents it has 79 files
00:18:20
total of what looks like 71 megs you can see all the file metadata inside of it so it's got a nice zip browser and it also works for bzip and and targe easy it's a generalized mode called
00:18:32
archive mode and so any archive can be can be opened up in emacs and then you can not only can you see the entries but you can actually open them i can go and open this one up right here and there it is e-max will
00:18:45
show me the ping file right uh let me see if there's any binaries in here that aren't pings there aren't so let's go and find a different binary
00:18:56
file in the documents directory downloads downloads is always likely to have some weird binary uh yeah here's one okay so let me show you something cool
00:19:09
i have what here the you know the new emacs uh there's a new image manipulation program and uh it's a very powerful editing program very cool a lot of fun uh you should definitely learn it it's like
00:19:20
photoshop and this is the installer archive so i'm just going to open it up boom i've opened it up it's parsed it it's uncompressing it it's reading all the the entries and the zip
00:19:32
there's 154 entries all in all and as you can see there's a bunch of dialib files which is dynamic library so it's all compiled c code and i'm looking around inside of the archive well
00:19:44
i can actually open up one of these die lib files in emacs why would you want to do that i mean if i just open it in raw mode it's a bunch of gobbledygook right because these aren't renderable they don't have you know unicode characters or ascii
00:19:57
characters for for all of these bytes inside of this binary file and so normally you wouldn't want to do that but every once in a while if you're working with binary files in some format okay you want to debug them well you can run something called hex mode
00:20:11
and now look emacs has switched the way that we're viewing the file contents okay and what you can see right here it says the mode is hex mode and so now we can actually see the strings inside of the binary and
00:20:24
they're all lined up on their byte boundaries and you can see where they start and end and you can put the cursor on any byte and check this out you can actually edit the byte i can go and edit this binary and i can change this to a six right
00:20:35
and a seven 36 37 i actually i i you can you can uh you can edit the bytes but what i did was i stuffed text 67 in there now if i were to save this
00:20:48
okay i can actually say well i'll just do it because i'm not going to use that installer archive anymore okay i just edited a binary file and now i'm going to save it and it's like it's going to start discard the undo info is that okay and i
00:21:01
say yes and it saved it it saved it not only did it save the binary file okay my edits to it uh but it also it also can write it back now into the archive that i opened it up
00:21:14
in remember this archive was for installing the game but it had all these files so now i save the archive boom it's compressing it and blah blah blah very very powerful now do you often want to go and edit binary files and start
00:21:26
inside of archives no has it been uh helpful at various points in my career 30-year career as a programmer there goes it saved it now it's officially corrupted right so i'll go ahead and i'm going to delete the
00:21:38
file using the command to delete this file what does that mean it means delete the file of the buffer that i'm visiting so delete this file is not actually a built-in emacs um command so i'm just going to show you
00:21:51
how i did it i'm going to say describe function delete this file okay and it says why it's an interactive lis interactive lisp function in efuncts which is emacs functions which is a file
00:22:03
that i've been maintaining for 25 plus years of a bunch of little helpers that i've written right and i have if you look at my list directory i have dozens and dozens of files of emacs lisp
00:22:16
code that i've written that does all kinds of cool stuff delete this file is lisp code and this is what emacs lisp look like and i'll tell you you know everybody's scared a list and everybody's like oh god list
00:22:27
but it's really hard to read and whatever and honestly i mean like a lot of languages are hard to read pearl is really hard to leave to read right you know c plus is really hard to read i mean if you don't know the language yeah it's hard to read but it turns out that
00:22:39
lisp is so regular and actually so straightforward that you you can learn it very quickly and you start looking at it as regular code you'll see it just like in fact if i'm switching back and forth i'm writing lisp code that modifies java and so on
00:22:53
sometimes you know you'll actually forget which language you're looking at because you're really only looking at the identifiers and the symbols and the syntax highlighting and so you have to squint at it and go oh yeah yeah that's lisp right
00:23:05
so don't be afraid to lisp lisp is the language that you use for for customizing emacs again there's a scratch buffer that can let you play with expressions like i can evaluate two plus two and it says it's
00:23:18
four the evaluator works right and you can debug things like if i want to debug uh where were we this delete this file function i can start basically just instrument it for
00:23:30
debugging just now with control x and now if i say um go back here and i say delete this file it goes into the the emax debugger okay
00:23:43
there's a debugger and look i'm stepping through the expressions and it's telling me the results and uh you know it's it's uh it's it's exactly what you need you can see stack traces you can put in error handlers all that stuff
00:23:56
there's a profiler i mean all the programming tools that you would want to be able to um to write your own emacs code so ultimately what you have is this really powerful system where everything
00:24:07
is in a buffer right we have that game sokobon was inside of a buffer we have our buffer list is a buffer we have we had a calendar and a calculator there's many many other you
00:24:20
know really cool applications written for emacs and i've written some of my own like for example if we go back to my e-lisp directory we go up a directory and do lily pond i have a bunch of cheap music that i
00:24:36
have been arranging so if i look here at uh chrysler page one as you can see i have this lovely formatted preludium and allegro in the style of pugnani actually
00:24:48
i'm going to be recording this soon um it's a guitar arrangement and it's guitar music and it has tab okay lily pond outputs this from an input language called [Music]
00:25:01
well it's the lily pond markup language it's a tech language and i don't have lillian pond mode installed on this computer because this particular computer is from my my video recording but as you can see it's a language a markup
00:25:13
language like sort of like xml and html or markup languages but this is this is a tech language and it shows which notes go in which measures and which dynamic markings and a bunch of other you know
00:25:26
instructions on how to tell the formatter how to format your beautiful sheet music okay well this was something that i was doing you know for hours a day and it went on and on you know it's really hard to look at this what we're looking at here in
00:25:39
this buffer which is you know the tech language and know what it's going to look like when it's formatted like this right so what i would do is i would i set up i basically created my own little ide as you can see i have
00:25:52
multiple frames open here we don't have enough space to really show you know how it's going to look but basically like if i if i have them both open on a desktop i can actually run a command now that i that i wrote myself and lisp right that
00:26:05
will run the lilly pawn compiler on the left hand side code here and if there are no errors it will refresh the ping image of the actual formatted music here on the on the right side and it's like a
00:26:18
mini ide that i put together right inside of emacs so emax gives you just tremendous power and flexibility for writing custom workflows and how often do you have to write a custom workflow well anytime you're
00:26:31
doing something over and over and over again you should start thinking should i automate this is this something i do for my job every day right well you know an automation you know can of course take the form of writing a program that's
00:26:43
kind of a lot of work or you can write a script scripting is you know very helpful for writing automation but emacs gives you some even finer grained and lighter weight sorts of automation opportunities let's let's do it let's do
00:26:55
a live example here i'm going to go to my content directory and in my game and we're going to open this directory up it's the armor it's the armor body armor subdirectory so it's all the built-in body armor there's
00:27:07
about well we see about 40 different kinds of armor dragon mail and cloth robes and ring mails and all that kind of stuff they're xml files
00:27:20
they're in a special mode so for starters i i defined this xml format as the you know the way that i declare custom objects in my game as you can see it has its own image if i click if i hit
00:27:32
return it's going to open that image oh look there it is leather armor if i open the dragon mail um i don't know blue dragon mail green green dragon mail we open that image there's some green dragon armor okay
00:27:46
so i had to teach emacs what my directory structure was like and where these classes are like i can click on the class and it will open it up for me right and i did it by writing my own mode i mentioned modes before modes are
00:27:59
they define the behavior of the buffer that you're looking at well i wanted my mode to start as xml so that it knows about xml you know close tags and and formatting and things like that but i also wanted to have
00:28:11
extra functionality for example when i'm hitting the return key on various things inside of my game object i want it to take me to the appropriate file well let's see how i did it so if i
00:28:24
describe the key notice you can see all your key bindings in emacs with ctrl h b and it'll put them all in a buffer as you can see i have [Music]
00:28:37
well over 1500 key bindings over globally overall in emacs and this is what they all are so again emacs is super self-documenting you can you can open up the info buffer
00:28:49
here info is a hyperlinked basically manual where you can learn all about different packages for emacs like you know mail readers and news readers and
00:29:01
org mode and all that stuff these are you know remote file editing and advanced directory editors and many many powerful tools right super powerful and it's all it's all hyperlinked and
00:29:14
it's all done in emacs's unique style but but it is it is a self-documenting editor because it predates the web and besides it's more powerful to have that stuff inside an info buffer because if i want
00:29:27
to take this text and i want to do something with it right like take this text and throw it into a temporary buffer and sort the lines i can do it right because it's super super powerful so we're going to go back to our thing
00:29:39
and we're going to say all right we're going to look at the key binding here for um the return key so um so it's describe key return key and it says it's map mode follow reference so i motivate a mode
00:29:52
called map mode for my game map files and archetype files which are both xml it's in a file called mapmode.el emacs list so here's all the code and the follow reference function
00:30:05
is [Music] is right here and as you can see it's some lisp code that basically says uh if the point is over some sort of like image path or another archetype or a class then we're going to go ahead and
00:30:17
open it up so i'll tell you a little bit about emax's programming model emacs's programming model is very different from uh from any other system that i've ever seen before because it treats it as if you were
00:30:30
basically writing macros you're actually you start with a cursor and the cursor is a little busy b that moves all over the buffer and the cursor is you you are the cursor and so at any given time it's called
00:30:43
point and all the editing operations actually happen at point so if you want to make an editing operation on line 39 you have to move the point there so you'll do go to line or go to go to character as you can see right here i'm
00:30:56
doing it i call this this macro called save excursion multiple times in this big when statement right if we're on a map preference do this if we're on an image reference do this et cetera and what i
00:31:08
do is i save the excursion which it calls it an excursion it really is an excursion your little busy bee is going to go off somewhere on an adventure and then when it's done uh you're gonna come back to where
00:31:19
you're at okay and so in inside of this xml file i'll put these things you know put these two two things side by side so you can see uh inside the green dragon mail my cursor's sitting here inside of the image path
00:31:33
halfway along the path well over here we're going to save excursion which means remember where the cursor is and a couple of other things and then we're going to go to care point at beginning of line so we're going to go here
00:31:46
you see and then if we're looking at an image ref or a christmas image graph because we have christmas images then we're going to call this function map mode open image on the first match
00:31:58
because looking at actually can take a regular expression let's go look at that image ref real quick i'm going to do a whole i'll probably do a whole episode on programming in emacs lists it'll be kind of fun but as you can see i've defined a regular
00:32:11
expression inside of a string here it's not pretty i mean regular expressions in emacs are kind of more awkward than they should be because the escaping isn't isn't the best they really need really emax lisp
00:32:23
needs regular expression literals that's one huge advantage that languages like say kotlin have but you can still do it you know the regular reg x's are powerful and they have pro 5 compatible reg x's and all that and so basically i say am i looking at
00:32:36
some white space followed by this image tag followed by path equals whatever followed by the image path and then i slurp it up and back in my code um and follow reference i say well if it's an image we're going
00:32:49
to call map mode open image on it so it's going to open it up and i'm going to see the green dragon mail again i've made myself a little mini ide now i would love someday to do a plug-in for intellij that understands all of the
00:33:01
custom stuff for my game code right you know i would love to but you know that's that's a project right i've gotta you know i've done intellij you know and android studio plugins before and they you know they're very
00:33:14
powerful and you know you can do a lot but it's it's like writing it's like writing your own desktop application whereas this little function right here is just a couple of lines of code and it does everything that i need right and
00:33:25
i've got it it's i've got it handling a whole bunch of cases it can go to classes it can go to other archetypes the parent archetype it can go to uh python files all that stuff so there's
00:33:36
there's this sort of continuum of like small plug-ins all the way on up like for example one thing that emacs loves to do is beep emacs loves to beep at you right and so eventually i wrote a little
00:33:50
command called nobel n-o-b-e-l which means no bell i don't want it to beep at me anymore so let's find where is nobel i don't even know what it is anymore let's go look it's in my e-max functions it turns off bell ringing and bell
00:34:02
flashing so that when i quit it's not beeping and flashing at me and i'd read the docs and it looks like all it does is it sets the ring bill function to a lambda that takes no arguments and returns nothing so the
00:34:14
ring bell function is it is a no up and i made it a little command with this keyword interactive and now and i added it in my in my hundreds and hundreds of little commands and now i can type in x
00:34:26
nobel if i want to turn the beeper off right that is a that's a that's a really a full application in in literally four lines of code one of which is the comment string the
00:34:38
documentation okay uh it's like html right with html you know you can build a web page with just a really basic markup and then you can you can get a little
00:34:51
more sophisticated and add style sheets and then get even more sophisticated and add in some javascript and you can go on go on it from there and they become arbitrarily complex but your basic html file is just a couple of lines of html
00:35:03
and it can be formatted and marked up it's really simple and it's that simple that learning curve that goes from the simple to the complex that is utterly lacking in ide environments it starts complex okay if you're going to write a
00:35:14
plugin for an ide prepare for your hello world to be days of learning and pages of code just to do the hello world whereas in emacs i can install a menu entry or a new command something that does something meaningful write a
00:35:28
workflow for myself with just a couple of lines of code stuffed into one of my config files right and so over time you build a dsl for your life okay as a programmer actually no beyond
00:35:40
programming as you can see as we talked about before i did a lilly pond thing i've done i've done um automation for final cut pro as well i've started adding more and more emacs functions to process files before i'm getting ready to you know do the editing
00:35:53
and things like that so it is it's just an incredibly powerful environment i want to show you one demo that i've mentioned a few times because i think it's important yeah one claim that i often make is that
00:36:05
one thing that i often make is that it's faster to use the keyboard than the mouse so here we have a mouse and we have the keyboard and i want to go to this spot right here 1200 31 right or what's what's it what's what's one
00:36:18
that's sort of unique this fur tree right here all right let's say the cursor is up here at the top now i can i can i've got my fingers on home row so which one do you think is faster do you think moving my hand down to the track pad and moving down to fir tree and
00:36:31
placing the cursor there is faster or this oh sadly i hit the first fur tree first so what i did was i did ctrl s and i typed fur and it took me to the first fir tree
00:36:44
but also highlighted the second one so one more click and i'm there so if i want to go to this location right here 543 then i'm there i just had i just type out the part of the buffer that i want
00:36:57
to go to and my cursor winds up there and then i can just move the cursor to leave it there you know what i found is that on average not having to move my hand back and forth to the trackpad or to the mouse
00:37:10
okay and not having to fumble around where where is the cursor the mouse cursor on the screen even you may have lost track of it and it's off in the corners so you have to wiggle it a little bit right where you always know where your text cursor is right because you're using it for navigation
00:37:23
and so you know if i want to go to this snow c i just type snow c and boom i'm there that's how fast it was now of course it does require to be able to type but i've told you again and again if you don't know how to type then you're not as good of a programmer as
00:37:36
you should be so go learn how to type i even wrote i wonder if it'll even run a typing test that's probably not installed on this machine i have a typing test that i wrote somewhere that actually keeps
00:37:48
track of how many my error rate and my typing and all that show that in another day the other thing that i wanted to show was there were two two things one is hey look at all these files what if i want
00:37:59
to take all the ones that have cloth in them okay and i want to reverse the order of cloth and the second word so these four files right here i'm going to rename them all okay i'm going to mark them to instead of cloth aired on our
00:38:13
channel rename it to aircloth.arch let's just say right let's say that i've got potentially you know hundreds of these things well uh what you can do in direct this directory editor is you can say percent
00:38:25
r means rename from regular expression and i can say cloth um whatever i can say capture the next bit and then end with dot arch so that's my
00:38:36
match and i'm going to replace it with the match group cloth dot arch and now it's going to say do you want to rename cloth air to air cloth and i go yeah bang and it just renamed all four of them you see that mmm and they're
00:38:49
renamed on disk right if i go to the armor directory in the shell say and then look at star cloth there they are they've all been renamed okay so that's the first thing is being able
00:39:00
to rename files by a regular expression i've never seen that functionality anywhere else and if it didn't exist in emacs you could really easily write that function right it would take you probably two hours or three hours of you
00:39:13
know writing a list but maybe writing a little test for it if you want although realistically we don't usually don't usually write tests for emacs list code that's not going to be distributed to other people right if it's your own just little personal functions
00:39:26
the other thing that i want to show you is macros so let's say i want to go into every one of these xml files and i want to change um like okay here's an idea what if i need to insert
00:39:38
one extra xml line at the end of every single file right before the closing arch tag right here all right that's something that's a little bit harder to do with a script you can do it but it's like with a said a said script it's a
00:39:51
little tricky but you can do it in emacs really easily by going i go to the first file and i do it by hand so i'm going to start recording a keyboard macro this is the last thing we'll do today i'm going to go ctrl x open paren it says defining
00:40:03
keyboard macro and now i'm going to say open that file search for go to the end backup one line insert a line insert two spaces and then i'm going to say foo tag equals var and now i've got the
00:40:16
tag i'm going to save it i'm going to close it move the next file and now i end the keyboard macro look i just recorded the keystrokes that i did and i chose the keystrokes in a way that they were sort of independent of the length of the file so now
00:40:28
if you open up gray dragon mail it does not have food tag equals bar at the bottom but if i hit meta j which is i bound it to call last keyboard macro and i go back and open it up hey there
00:40:40
it is so now i can do this macro on all my files and all of them now have that food tag at the bottom if i open this red dragon mail there it is food
00:40:55
tag equals body you see you see so it's really really powerful to be able to record keyboard keyboard macros and the programming model is actually sort of modeled on basically making the cursor go and do things as if you were typing
00:41:08
it with your fingers that's how emax's programming model is you can build higher level apis on top of course but the basic model is move the cursor somewhere and then take a look at where you're at and start doing some editing operations
00:41:21
so this was a quick tour of emacs i hope that you enjoyed it as you can see i use shells for everything i have tons of them i have my own custom modes and my own custom workflows you can open binary
00:41:33
files you can open uh you you can teach emacs about new kinds of files that it doesn't know about by writing special modes for them and so everybody always does so if you go to the emacs wiki you're always
00:41:45
going to find modes that people have written for almost anything on earth any programming language any markup language any uh any binary file that's in common use uh you know if there's a if there's something useful to be done like a play
00:41:57
an audio right or or open an image emacs either has it built in or you can you can write that mode yourself and because it's sort of a continuous start small define a variable define a little function and and it works its way
00:42:11
up from there it's much much easier to learn how to do plugins in emacs than it is for a big ide like intellij where you have to have a manifest and you have to have all this stuff right just to do hello world so
00:42:23
hey it's you know it's a super powerful model i hope this has been convincing i know that i've failed to show you a whole bunch of things that i do on a regular basis but but this is emacs this is emacs and this is why this is why i
00:42:35
swear by it because a lot of these things a lot of these like personal automations you just you can't do it realistically with anything else there's no there's nothing else on earth that works exactly like emacs because what it is is really
00:42:48
it's a command shell or more like a command orchestrator like a process orchestrator it can be sort of anything that follows the unix model of having a text i o or or it can even you know do binary
00:43:00
operations and work on binary files and and hey you never have to wait for somebody else to write the tool for you right you're not sitting around going man i wish my ide could do xyz and i'd
00:43:14
do it but it's a huge bundle of work with emacs you write it in an afternoon or an hour or five minutes or however long it takes you and you've got that function around forever forever emacs basically never defecates any apis and
00:43:27
so i've got code that i wrote you know 20 years ago 25 years ago that i'm still using today right and folks that that is an investment that's worth it here i'm gonna i'm getting into the prelude so i'm gonna go
00:43:38
back to the to the regular view now so there you go you know if if you put a little bit of investment every single day right or just you know four days a week into learning emacs
00:43:51
so learning the key bindings and what else capabilities are and learning its buffer model and and how to get help and how to find packages and how to install things and get your color themes and your key
00:44:03
bindings all set up the way you like them you know if you like vi use the you know one of the vi emulation modes they're supposed to be fantastic or don't just raw dog it and learn emacs right and then you know gradually start
00:44:15
writing yourself some functions right uh and learn a little bit lisp there's tons of resources i have tons of lisp books on my shelf emacs lisp is very similar to common lisp so that's the lisp that you'll probably want to read about go
00:44:28
get a book on common lisp there's tons of good ones and you're off to the races you'll be using it for the rest of your life emacs is gonna long outlive me emacs uh almost predates me i think emacs was invented
00:44:40
in the 70s and i was born uh in uh i was born around then and i swear emacs is gonna live you know at least a hundred years longer than i do so i mean look it's not it's not going to be
00:44:51
wasted time it's going to be time well spent all right folks well there you have it that's my quick little tour of emacs i hope you liked it and i will see you next week for stevie's tech talk
00:45:02
[Music] you
End of transcript