Intro to GNU Emacs

Table of Contents

1 What is emacs?

1.1 Emacs is an editor

  • Emacs is an editor, but not just any editor.
  • Emacs is also a lisp machine, and this has powerful implications
  • "GNU/Linux is a nice bootloader for the emacs operating system" joke… not too untrue
  • Emacs is almost infinitely extensible
  • But who cares?
  • You should care!
  • Do you spend all day writing? Are you a programmer?
  • A programmer spends all day in her editor. It makes sense that she should be able to fit it to her needs. It makes sense that she should want something powerful.
  • Not just for programmers! Documentation people too… I'm looking at you, Jim!

1.2 Some demonstrations

  • Just simple editing (of course, this is what we do more than anything!)
  • Opening a shell inside emacs and running pdb
  • nyan-mode
    (load-file "~/elisp/nyan-mode/nyan-mode.el")
  • My orgmode agenda
  • changing my mode line:
    (load-file "~/.config/emacs/mode-line.el")
  • Mail!
  • M-x butterfly
  • Tetris??!

1.3 Killer features

  • Modes for almost any language you would want.
  • Useful debugging tools
  • Easy ability to add customizations and even write entirely new tools
  • OrgMode! Oh my god… OrgMode!
  • Learning emacs lisp is a great way to learn to program!
  • Magit and vc-mode
  • Tetris??!

1.4 Is emacs for you?

  • Learning emacs does take patience, but the payoff is big
  • The "emacs patriarchy"?
    • There was a case where I suggested orgmode to jewelfox
    • Kind of a backlash

Earlier on, I lamented the lack of a decent Free Software notetaking app that would sync between all my devices. In response, one of my friends suggested using emacs and orgmode, and waxed enthusiastic about how "Since it's plaintext, [it's] easy to sync between laptops via git!" In short order, he revealed a number of assumptions that I feel are common in the Free Software community:

"Syncing" is something that happens between laptops, not between desktop and tablet computers and smartphones.

Recommending the use of emacs and git to solve a particular problem is a reasonable solution.

Recommending the use of emacs and git to solve a problem that most people would use a dedicated, well-maintained, thoughtfully-designed application for is also a reasonable solution.

I feel that the vast majority of potential contributors are discouraged from participating by assumptions like these. Which insist on a high degree of technical knowledge and a high tolerance for frustration in order to contribute to or enjoy Free Software … on the desktop. Which is one reason why the hackers and idealists inside much larger and healthier Free Software communities, like Mozilla's and WordPress', largely use Macs.

  • fwiw, I sent a reply saying I agree-ish… we need reasonable solutions that don't require such dive-in
  • But what about those of us who enjoy using things like emacs? Is it also bad to share our enthusiasm?
  • My friend Aeva and I had a conversation where we semi-seriously and semi-jokingly talked about the "emacs patriarchy"
  • By that, don't just mean gender issues (though I think there is a gender gap)
  • How do we make emacs accessible in the way other areas of free software are doing outreach?
  • That's mostly a question without answers
  • I do want to point to RMS's essay My Lisp Experiences and the Development of GNU Emacs

It was Bernie Greenberg, who discovered that it was. He wrote a version of Emacs in Multics MacLisp, and he wrote his commands in MacLisp in a straightforward fashion. The editor itself was written entirely in Lisp. Multics Emacs proved to be a great success programming new editing commands was so convenient that even the secretaries in his office started learning how to use it. They used a manual someone had written which showed how to extend Emacs, but didn't say it was a programming. So the secretaries, who believed they couldn't do programming, weren't scared off. They read the manual, discovered they could do useful things and they learned to program.

  • So maybe we should be careful to make sure we have easier, more cushioned software than as something as overwhelming as emacs for newcomers, or we'll scare people away from free software
  • But I think there's something interesting there, that there's a lot you can do if you don't already know you're supposed to be scared by it!
  • How to kill the emacs patriarchy? Use emacs, and help others use emacs! And that's true for other technical tools also.

I'll give some more encouragement on why I think emacs is really great in a few, but now one more warning.

1.5 A word of warning about RSI

  • You should know about RSI
  • My own story with Libreplanet
  • Your wrists hurt, you must be a programmer
  • Keyboard chording may increase risk
  • Not using emacs won't save you though!
  • I know users who use notepad and vim and have serious RSI, worse than I do
  • I have my own foot pedal related solution
  • Yeah that's pretty dorky
  • At the very least, you should remap caps lock to control. This is critical to avoiding "the emacs claw"
  • Demo of how to do so in GNOME!

1.6 Still here? Emacs is probably for you!

  • Emacs is fun. Every day I enjoy working in it.
  • I told myself I'd never become "one of those people"
  • I did anyway, because it was too much fun… and too efficient!… not to.

1.7 Don't panic!

            .'        '.  \|||
           /            \-_  )
     \\\| ,              ,__\\
      (  /(  ,'-_____'-, )---'
       ||//\ \ uuuuuuu //
       ',/  '.'----.'\\,

            _  _ , , ___
           |O)(_)|\|' |
          _             _
         |_) /\ |\ | | /  |
         |  /''\| \| | \_ o
  • Easy to get intimidated by watching someone experienced with emacs doing crazy things
  • That's just because they've been using it for a long time. My 2004 self might be overwhelmed by my use of emacs.
  • You can do a lot with emacs fairly quickly!
  • Start slow, but keep learning as you go
  • Have fun!

2 Some history

  • Emacs was a project at the MIT AI lab, originally written with terrible things called "teco macros"
  • At the time, a full screen editor of its type was revolutionary
  • Lisp machines swoop in, change computing in the AI lab. RMS works in the battle between some lisp companies to take revenge on what he sees as the AI lab destruction. Lisp lisp lisp, entire operating machines written in lisp!
  • Jump to 1984: RMS starts the GNU project. The first GNU project: a complete emacs rewrite!
  • As quoted earlier, was inspired by Multics MacLisp
  • Emacs rewritten to be an integrated editor and lisp machine
  • You can tell how similar the UIs are too:

3 Diving into emacs

3.1 How do I learn emacs?

  • Start with simple use
  • Read the tutorials
  • Read the manual
  • Force yourself to do projects in it!

    (When I was in college I decided to start learning Emacs and LaTeX simultaneously in the same night when I had a term paper due the next morning… I just barely survived, but I forced myself through!)

  • Read the emacs wiki and search the web if you need help
  • There's also a channel on freenode called #emacs… warning, it's a bit overwhelming sometimes, but I hang out in there :)
  • Keep trying and be patient. Like all "fighter jet" software, there's a high learning curve, but a high reward for sticking with it.

3.2 Opening for the first time

Pretty straightforward, let's do it via gnome

Okay, let's do it without my customizations on via a terminal :)

3.3 Opening files via the menu bar

3.4 Opening files via a keyboard command

Don't panic! :)

Or do it the keybinding way:

C-x C-f

3.5 Two helpful tutorials

3.6 Keyboard shortcuts (or: playing Mortal Kombat with your keyboard)

Escape-Meta-Alt-Control-Shift… emacs! ;)

  • Commands like "C-x C-f" to open a file might seem ridiculous and even impossible to learn
  • Like playing video games or even typing, if you keep doing it, it becomes second nature
  • You don't need to force yourself to learn commands, but try to pick up useful ones slowly
  • It pays to use keyboard commands! It's so much faster, and if you ever see someone doing "editing wizardry" it's probably because they have super keyboard command skills

If you see something like "C-x C-M-f" that means "hit Control + x at the same time, then Control, alt and f at the same time". Don't worry, most emacs shortcuts don't require hitting multiple things at once.

  • C-x means "hit Control and x at the same time"
  • M-z means "hit Alt and z at the same time" (M stands for "Meta")… meta is effectively the same as alt ;)

C-g is a special command, says quit, gets you outta there!

3.7 Understanding some goofy terms

Emacs was one of the first free software projects ever, and the first GNU project ever. It's got a lot of history, and had some terminology that existed before we came up with more modern terms..

  • frames and windows: swapped from what you expect!
  • killing, yanking, and the kill ring (translation: cutting, pasting, and paste history)
  • meta: this just means the alt key
  • point, mark, and the region: basically, the cursor, the start of the selection, and the selection area itself
  • modes: major and minor modes both… well, easier to explain out loud
  • buffer: basically emacs' representation of a file you have open… or some other representation of text (for example, a magit buffer)
  • the mode line: that line that says what file you have open and stuff
  • the minibuffer: the area at the bottom where sometimes messages pop up and you are prompted for things

3.8 Using the manual

Emacs comes with a manual!

Help->"Read the emacs manual" (or: C-h r)

It's a bit intimidating… but most things you'd want to know are in there.

Reading that will show it to you in the "info browser" which is cool but might be intimidating if you're new to emacs. There are also HTML versions online.

3.9 Emacs is a self-documenting editor

What the hell does that mean? Let's find out!

Let's say we wonder… what does C-t do? Emacs knows, and can tell you!

In the "Help" menu you'll see there's a "Help->Describe->Describe key" function. Press that, then actually hit the key you want to learn about.

Now we can try that with a keybinding first! "C-h k"

We can also find out:

  • what a function means: "C-h f"
  • find some functions that have a word in their name or description: "C-h a" for apropos
  • "C-h w" find out where that command is

Remember: emacs is just binding lisp functions to keys. That's all!

3.10 Interactive commands

Many commands can be run interactively via M-x

For example, all keybindings can be run this way.


  • M-x find-file
  • M-x make-directory

4 Down the rabbit hole: customization and lisp

4.1 Falling gently down the rabbit hole

Again: Don't panic!

4.2 The customize interface

Options->Customize emacs

I used to use this a lot, but I don't anymore.

Nonetheless you can do quite a bit of tweaking from this.

4.3 Your .emacs file

Basically, this is where we put customizations.

I'll show you mine :)

(find-file "~/.emacs")

Let's also look at my general file

(find-file "~/.config/emacs/general.el")

4.4 Dipping your toe into lisp


 (message "hello world!")

You can survive fairly far with barely any lisp knowledge. But there's a couple of things you should at least know.

Lisp is all about the parentheses.

A list (note the quote):

 '("dog" "cat" "rat")

Without the quote, the first argument is a function (or macro call..)

 (+ 1 2 3)
 (+ (* 2 4) (/ 6 3))

4.5 Going for a lisp swim

You will probably want to turn on show-paren-mode. (It might be on by default?)

(defun add-three (some-number)
  "Take SOME-NUMBER and return that number plus three."
  (+ some-number 3))

I'm willing to write something on the fly… :)

(defun tell-me-if-its-broken (is-it-broken)
  (if is-it-broken
      (message "Yeah that's totally broken.")
    (message "It looks fine, stop stressing!")))

Oh yeah, about nil, t, and lisp functions..

  • car, cdr and friends
  • it's all about the linked lists!
  • Anyway, parenthesis matching makes it a bit easier

4.6 Drowning in lisp

We're not going to talk about macros today, with the exception that I'll tell you what they are.

4.7 Learning from other lisp

Let's try:

C-h f "find-file" <RET>

We can read about the lisp stuff right here

4.8 Learning more

I highly recommend reading through the "Emacs Lisp Intro"… it's how I learned much of my first programming skills!

4.9 Lisp is beautiful

Lisp is a bit overwhelming because of its minimal syntax. But its minimal syntax also makes it super powerful: you can write new language features quickly, and the code you have is readable but also looks like the actual structure of the language.

4.10 How little can you get away with?

Well…. you don't really need to know

The most important thing to know is setq, which is how you set a variable. So, for example:

(setq some-variable "monkeys")

sets some variable to monkeys.

;; Make sure that pressing middle mouse button pastes right at point,
;; not where the mouse cursor is.
(setq mouse-yank-at-point t)

5 Wrap up

I showed a lot of cool things here, but also some intimidating things.

The key to emacs is: don't be intimidated! Work with what you know, and keep coming back and learning more.

Date: 2013-01-20T11:52-0600

Author: Christopher Allan Webber

Org version 7.9.1 with Emacs version 24

Validate XHTML 1.0