Notes on Mastering Emacs: Chapter 4: The Theory of Movement
The following notes were taken while discussing Chapter 4 of the book Mastering Emacs by Mickey Petersen (2022 edition) in book discussion group meetings.
An index of notes for all chapters are available at notes.html.
Contents
Basics
The following complete key sequences illustrate a few basic commands:
-
C-x C-f foo.txt RET
: Edit file namedfoo.txt
. -
C-x C-s
: Save current buffer to file. -
C-x b *scratch* RET
: Switch to the buffer named*scratch*
. -
C-x k *scratch* RET
: Kill the buffer named*scratch*
. -
C-x k RET
: Kill current buffer. In fact, like the previous key sequence above, typingC-x k
first prompts for the buffer name. However, the current buffer name is selected as the default value already. As a result, typingRET
kills the current buffer. -
C-x C-b
: List buffers. -
C-x C-c
: Exit Emacs. This command offers to save all unsaved buffers before exiting Emacs. -
ESC ESC ESC
: This command exits the current context. What that means depends very much on the context. It performs exactly one of the following actions: If there is an active region, then it is deactivated; if a minibuffer is open, it gets rid of it; if recursive edit is in progress, it quits one level of recursive editing; if multiple windows are open, it deletes other windows so that the current window becomes the only window in the frame. The aforementioned conditions are tested one by one and as soon as one of the conditions is met, the corresponding action is executed and the other conditions are skipped. -
C-/
: Undo changes. -
F10
: Activate the menu bar.
In my experience, I have found that ESC ESC ESC
is most
useful when a stray minibuffer is open but the cursor is on some
other buffer instead of the minibuffer and I need to close the
minibuffer. Here are some steps that demonstrate this usage:
-
Type
M-x white
and pause. We now have a partially typed command in the minibuffer. -
Now pretend that we get distracted by some imperfections in the text buffer that was open earlier and we want to fix those first. Type
C-x o
to move away from the minibuffer and go back to the text buffer to perform some editing tasks.In this step, we could have typed
C-g
to quit the minibuffer first but we did not do that. We pretended to get distracted by the text buffer and went straight to it from the minibuffer by typingC-x o
. At this point, the cursor is in the text buffer and the minibuffer remains open at the bottom. The open minibuffer can be distracting while performing the text editing tasks. TypingC-g
now will not get rid of the minibuffer because the cursor is no longer in the minibuffer. -
Now one way to close the open minibuffer could be to type
C-x o
to go back to the minibuffer window and typeC-g
. However, there is a more direct way to do this as explained in the next point. -
Type
ESC ESC ESC
to get rid of the minibuffer at the bottom. This works even when the cursor is not in the minibuffer but is in the text buffer instead.
Major Mode Load Order
The chapter mentions the following order for detecting major mode:
- File-local variables
- Program loader directives
- Magic mode detection
- Automatic mode detection
Let us start from the bottom of the list and share some experimental results that illustrate how the major mode detection works.
Occur Mode
TODO: More notes coming up here soon!