All right, so you've seen a video where we used Emacs to write a simple little file, save it. We added it to get submitted to the grading system. Emacs is a really powerful editor. It has lots of features. We're going to show you some simple ones like searching, undoing, some cool features of Emacs's undoing. And a little bit more advanced features like keyboard macros. We're obviously not going to cover all of Emacs in this video, but we're going to show you some of the more useful features, and then you can learn a lot more as you go. So if I look in this directory, I have a text file and a C file to work with. And I open up this text file and start working with that. It's just a bunch of text from chapter two of all the programming. You probably read most of this in your readings in course one. So one of the things I might want to do is search. If I hit Ctrl+S, you'll see at the bottom of my xterm it say isearch. Emacs has incremental search which means as I type a search term, it will start searching for whatever I have typed so far. So if I type i, for example, it goes to the first instance of i and highlights all the other ones. If I type im, afterwards it's going to refine that and start showing me things like important and sometimes and simple. If I were to type e, it comes down here to sometimes and refining that further. This is really nice when you're programming because you want to search for a function name or something. You hit Ctrl+S, you just start typing a little bit. You'll quickly get to what you want and you generally don't have to type out the whole thing. If I hit backspace, it goes back to im. I might want important, but not this one so if I hit Ctrl+S again, it will search forward for the next instance of im and I can keep doing that. And at this point it needs to scroll down. In a normal x term this wouldn't happen. X term JS has a little bit of a weird bug where it doesn't always redisplay the screen correctly. If that happens just hit Ctrl+L, and that'll make Emacs redraw the screen completely. So then I can just resume by hitting Ctrl+S again and searching some more. That bug's a little annoying, but xterm.js isn't my thing. Okay, so that's searching. You can also search backwards. If I hit Ctrl+R, it will say I search backwards. And I can search backwards and it will go backwards. And I can change between these with Ctrl+S, Ctrl+R to move forwards and backwards through my searches. All right, so that's searching. What else might we want to do in our editor? We might want to undo things. So if I type some stuff, for example, and then realize I didn't want it I can hit Ctrl+XU and it'll undo that change. All right, now that's pretty normal. Let's just suppose for a second that I made a bunch of changes. So I do some changes here, blah, blah, blah, some other stuff. And then I go and do some really important stuff. Really important complicated stuff I want to keep. Now I realize all that other stuff I just did I want to undo it. Maybe this happens in programming. I might make some changes in one function and go work on some other piece of code, and somehow realize that I messed up that function. If I hit Ctrl+space, it's going to say mark set and start highlighting a region. And once I've highlighted a region and selected it, I can undo in that region. So if I undo Ctrl+XU, it will undo in region and it will start only undoing the changes in that area of this file and not the later changes that I did somewhere else. Which is really nice when you're programming or even editing other things in general. I'm going to come down here. So sometimes I want to move to beginning of a line. Ctrl+A will do that. Ctrl+E will go to end of the line. going to to take out this line of text. So Ctrl-K cuts an entire line. If I wanted to paste it somewhere else, Ctrl+Y pastes the previous thing that i cut. If I want to copy or cut a region, I can select it, Ctrl+space, begin selecting and then Ctrl+W will cut, Ctrl+Y will paste. If I wanted to copy instead of cutting, I can hit Esc+W and then paste. Now one of the other really cool features about Emacs is after you paste, you can change back through previous things you have pasted. So immediately after pasting, if I hit Esc+Y, it will un-paste what I pasted and paste in the previous thing. And I can do that again and get back to previous things that I have copied and pasted. So sometimes you copy and paste things and you want to paste not the most recent thing, that's really cool. Okay, I'm just going to revert, actually I'm just going to save that, it doesn't matter. The other feature I'm going to show you in this video, which I think is really cool, I'm going to open up this enum example, where I've written enum a bunch of things. It has all these things in it. And what I'd like to do is write a function that takes this enum and prints out what it is. Now I just told you how to copy and paste. So I'm going to copy. And while I'm copying, I can actually like search for a curly brace. And just sort of jump down here without scrolling through the whole thing, so I'm going to copy all that. I'm going to write a function, printThing. It takes enum. That name was really long. I'm kind of lazy, so I'm just going to hit Esc/. It's going to complete that name for me. Oops, I need to give that a name. t){switch(t), and now I just pasted all those things. And Emacs is telling me what my curly brace matches even though it's off screen. And it's not lining up right because I don't have any semicolons in there so Emacs knows there's something wrong with the syntax of this. This tells me what I've matched. Also, if I hover on something, it'll match up if they're on screen. Just going to search backwards for this. Now what I'd like to do is I'd like to take each of these names of enum cases that I just pasted in here, and I'd like to change each of them to look like case.thing print f that thing break. Now most editors you'd have like a tedious 15 minutes of copy and paste and change, and it'll be really boring. But Emacs has this really cool feature called keyboard macros. So basically I want to do the same thing to each line, so here's what I'm going to do. I hit Ctrl+X open parenthesis, and it says defining the keyboard macro. And now, Emacs is going to remember the sequence of commands I do and let me replay that sequence of commands. So what I'm going to do is go right twice. I'm going to write the word case. I want to start highlighting a region to copy, so I hit Ctrl+space. I want to search forwards for a comma, and then I want to go backwards. So hit left, and then I want a copy. So I'm going to Esc+W. Now I want to come over here and replace that with a colon, type printf. I'm going to paste that thing, so hit Ctrl+Y. Let's say I want to new line and break, and then I want to go down the line and to the start of the line with Ctrl+A. Then I hit Ctrl+X close paren, and it says keyboard macro to find. So that sequence of commands I just did to that line, I can hit Ctrl+XE. And it'll do that again to this line. And after I've done that, it says, type e to repeat macro. I can just hold down e. Well, on this it makes me repeat it. But on most terminals, you can just hold it down. And then this one isn't going to quite work because it doesn't have a comma. But if I just put a comma there to make it look like the others, boom, and now that's syntactically legal. I might put like default: print f('invalid thing\n ), break, but I got Emacs to do all that work for me with keyboard macro. So there's some of the cool features. You'll read about more of them in your readings and you'll learn a lot of them with practice.