Lecture Notes

Learning assistant supported notes for CS 35L


Project maintained by UCLA-CS-35L Hosted on GitHub Pages — Theme by mattgraham

Emacs Intro

The key software quality attributes we care about for applications are as follows:


Aside. Sometimes, persistence is referred to by the term “nonvolatile.” Be careful when using the term “volatile” since it has a different meaning in C, C++ (the volatile keyword) than it does when you’re talking about persistent/nonvolatile storage. The volatile C/C++ keyword will be briefly covered later in the course.


Aside. Professor Eggert likes to call to refer to how Emacs refers to things as “Emacsese.” For example, C- is Emacsese for the control key (see below).


We’ll use Emacs as a “window” into application writing. It’s just another program; you could have written it, if you had the time, or you could write a substitute.

Why Emacs?

To startup Emacs:


Aside. Professor Eggert will talk about character encodings like ASCII later in the course. For now, all you need to understand is that any character is encoded as a number. For example, 'a' corresponds to the number 97. This is the “ASCII code” of 'a'.

It is common to use 0x to prefix hex values (base 16) and 0b to prefix binary values (base 2).

We can find the corresponding ASCII character for control codes by taking the original character and bitwise and it with 0x1f. A bit pattern like 0x1f and using it to bitwise and with another number is commonly referred to as a bit mask.

For example, the value of C-x (see below) can be found as follows:

See the ASCII control characters here on Wikipedia! https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0_controls

Some generally useful ones to know include the following:


When using Emacs, you’ll be constantly using certain keystrokes, combinations of keys. All keystrokes in Emacs correspond to a string of ASCII characters. Colloquially, we use the following shorthand:


Aside. Depending on your system, the meta key may be bound to a different physical key. The ESC key should always work. On some systems, ALT or OPTION should work.


Common Emacs Keystrokes


Aside. The following keystrokes and terms are things Professor Eggert has specifically thought of. It is certainly possible you will need more for the exam and to finish Assignment 1. See GNU Emacs Reference Card. https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf


Let’s start with some definitions:

Some good keystrokes to know:

Emacs Modes

Emacs is a modeful editor: the action it takes when type a character depends on the mode that Emacs is in.

Some users hate multiple windows, and work just like in this lecture, one big Emacs controlling the screen.

For now, assume there are only two types of files (actually there’s more, but let’s pretend).

  1. Regular files are sequences of bytes.
  2. Directories are mappings from file names to files.

To edit a regular file, Emacs creates a buffer, copies the file’s contents into this buffer, and then you edit the buffer. When you C-x C-s, Emacs copies the buffer contents back into the file!

Emacs Backups

Emacs convention for file names: