[001.1] Introducing Emacs

A basic introduction to the Emacs text editor.

Subscribe now

Introducing Emacs [05.15.2017]

Hello and welcome to the DailyDrip's emacs videos.

In this first video we will take a look at some of the language that is required to be able to understand emacs content online, and we will take a look at some of the basic actions required to be productive with emacs quickly. We will also take a look at the interface because it's important to know what we're looking at, and there's not that much fundamentally, even though it's kinda foreign the first time.

So, let's dive right in.

What we're looking at right now is the splash screen. It is just what you see when you launch emacs, there's nothing special about it. It's called a buffer. Everything in emacs is a buffer. Everything that you look at. The container for text in emacs is a buffer. So that means that this is just a buffer. We can do many things with buffers. Let's create a buffer ourselves and type stuff in it.

So, Control + x, Control + f (C-x C-f) is how we go to find a file, as you can see at the bottom. We're going to create something in the tmp directory and we'll call it foo.rb because, why not.

So this is a new file, if you look at the bottom, emacs tells us that we visited a file that didn't exist. This is not a problem.

We can type things, and you can see that when I press enter it's indenting for me, which is very kind. So, this is how a dog would speak. Woof.

class Dog
  def speak

And, that's it. You can repeat that with everything. We can do the same thing with a Javascript file, with a C file, and so forth.

So now let's save this, because it would be a shame to lose this very hard work, this very elegant code that I wrote here. Saving is very simple, you just do it with Control + x, Control + s (C-x C-s), and you can see at the bottom, it says Wrote /tmp/foo.rb. That's really quite convenient.

So now let's take a look at what we have at the very bottom. We have this U -- this is the modeline. We have U:---. This is the state of the buffer. Right now it has three dashes, that means it's unmodified. If I make changes to it, like press enter and add a new line, there's two stars U:**-, which means it's modified again. I can undo or I can just save again and you'll see we're back to three dashes.

To the right of that is the name of the buffer, foo.rb, you saw me type that earlier, it's not a surprise, it's just a good place to have it, you know that the filename is there.

To the right of that is the word All, that's just telling you how much of the file you can see right now. If the file is very big you'll only see how far you are in it, so you'll see Top or Bottom or a percentage of how far you are in it.

To the right of that, you can see L3 which is the line number.

And to the right of that, you can see the word Ruby. That tells us that this is a Ruby file. This is the major mode. So let's take a quick look at what would happen if I created a file called foo.js. I visit a file with C-x C-f, I call it foo.js, it's a new file again and it says JavaScript. So I can write any Javascript I want, I can create a function, and again like in Ruby it indents the way I want it to. And then I can save it and everything works just fine.

function foo() {
    return "hi!";

I can switch between the two with Control + x then b then enter (C-x b RET) just like so and you'll even notice that the indentation is different. It indents Javascript with four spaces and Ruby with two. So those are what we call major modes, those are the driving engines for the buffer. That is how emacs thinks about things, how it will make particular choices about this buffer, and it is also how we as humans will think about what we're editing generally.

So that's really all you need to think about when you hear major mode is, this is the level of thinking that a human makes about this editing.

There are also minor modes, because of course, if you have MAJOR modes, you will have MINOR modes. Minor modes are secondary modifications. We will get into them later, they are very powerful and very useful, but for this first video they're no very interesting to us.

We're going to end this video by discussing keyboard shortcuts. So let's take a quick look.. Ah.. Let's cancel this with Control + g (C-g) and create a file called keyboard-shortcuts.txt and you'll see this is a buffer in Text mode.

So, if you want to read emacs content online you will read a lot of keyboard shortcuts. You will see things like this for instance: C-x d. This C means press the Control key. The - means keep it pressed, x means press x, and because there's nothing afterwards it means release x and release Control, and then d means press and release d.

So: it would be Press Control, press x, release x, release Control, press d, release d.

You will also see things like M-e. M is the Meta key. This would be press the Meta key, whatever that is, keep it pressed, press e, release e, release the Meta key. The Meta key is just the alt key, or the option key on OSX. There's no mystery, that's just the name it has because emacs existed before those keys were called alt or option.

Finally let's end the screencast with the most important keyboard shortcut, C-x C-c which is how you exit emacs.

This one has two Control keys in a row, and the way you would do that is press Control, press x, release x, then you can keep Control pressed because the next key also requires Control, so you can press c and release c, then release Control. One ore time, this would be 1. press Control 2. keep it pressed 3. press x 4. release x 5. press c 6. release c 7. release Control

So that's it, that's all you need to know to get started with emacs. Thank you for watching, and join us next time.