Notes on Mastering Emacs: Chapter 3: First Steps
The following notes were taken while discussing Chapter 3 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
- Starting Emacs
- Emacs Client-Server
- The Emacs Interface
- Keys
- Terminal Limitations
- Definitions for Key Sequences
- Key Examples
- C-g: Universal Bail Me Out
- Caps Lock as Control
- M-x: Execute Extended Command
- Interactive Commands
- M-X: Execute Extended Command for Buffer
- Universal Arguments
- Discovering and Remembering Keys
- True Color
- The Customize Interface
- Customize Commands
- Evaluating Elisp Code
- Info
- Apropos
- Describe
- Links
Starting Emacs
Here are some frequently used commands to start Emacs:
-
emacs -nw
: Tell Emacs not to create a graphical frame, i.e., run Emacs within a terminal instead. -
emacs -q
: Do not load an init file, i.e., do not load~/.emacs
,~/.emacs.d/init.el
, etc. -
emacs -Q
: Do not load init file, site-wide startup file, or X resources.
Emacs Client-Server
The key sequence M-x server-start RET
turns the current
instance of Emacs into a server. If we kill this instance of Emacs,
it kills the server too.
Another way to start an Emacs server is to enter the
command emacs --daemon
. This too internally
invokes server-start
to start an Emacs server but this
command ensures that Emacs runs in background mode. Therefore,
killing any particular instance of Emacs window does not end up
killing the Emacs server.
To open files, say foo.txt
and bar.txt
in
an already running Emacs server, enter the command emacsclient
foo.txt bar.txt
. This command blocks the terminal and waits
for us to finish editing the files. While editing the files, we
need to type C-x #
to tell Emacs that we are done
editing the current file. Emacs then switches to the next file we
are editing. When we are done editing all the files
opened, emacsclient
quits and returns control to the
terminal.
The book does not mention how to stop an Emacs daemon. One of the
several ways to stop an Emacs daemon is the
command emacsclient -e '(kill-emacs)'
.
Here are some commands to run emacsclient
:
-
emacsclient -c
: Create a frame. A graphical frame is created if graphics is available, otherwise a terminal frame is created. -
emacsclient -nw
: Create a terminal frame. -
emacsclient -n
: Client returns immediately without waiting for us to finish editing the file.
The Emacs Interface
The book mentions that many Emacs users disable the menu bar, tool bar, and the splash screen. The following Elisp code shows how these UI elements can be disabled:
(menu-bar-mode 0)
(when (display-graphic-p)
(tool-bar-mode 0)
(scroll-bar-mode 0))
(setq inhibit-startup-screen t)
After saving the code in the initialisation file (such
as ~/.emacs
, ~/.emacs.d/init.el
, etc.) and
restarting Emacs, these UI elements disappear.
It is worth mentioning here that disabling the menu bar may not be a good idea, especially, for beginners to Emacs. The menu bar contains a lot of helpful shortcuts that could be useful to beginners. Further, the menu bar often displays certain menus that are specific to the current buffer. Therefore, it may be a good idea to leave the menu bar enabled.
Regardless of whether the menu bar is enabled or disabled, the menu bar can accessed easily by typing F10.
Keys
The book mentions the following notation for modifier keys:
C-
: ControlM-
: MetaS-
: Shifts-
: SuperH-
: HyperA-
: Alt
Although not mentioned in the book, here is a quick way to test out all of these modifier keys:
(global-set-key (kbd "C-j") (lambda () (interactive) (message "You typed C-j")))
(global-set-key (kbd "M-j") (lambda () (interactive) (message "You typed M-j")))
(global-set-key (kbd "C-S-j") (lambda () (interactive) (message "You typed C-S-j")))
(global-set-key (kbd "s-j") (lambda () (interactive) (message "You typed s-j")))
(global-set-key (kbd "H-j") (lambda () (interactive) (message "You typed H-j")))
(global-set-key (kbd "A-j") (lambda () (interactive) (message "You typed A-j")))
Go to some buffer, say, the scratch buffer with
C-x b *scratch* RET
, then copy the above code to it,
then place the cursor at the end of each line of code and
type C-x e
to evaluate each line.
Then open a new buffer, say with C-x b foo RET
and
type ctrl+j, alt+j,
and ctrl+shift+j to test the first
three key bindings.
The fourth key-binding s-j
can usually be invoked by
typing command+j
or win+j depending on the type of keyboard you
have.
The H-
and A-
modifier keys are generally
not mapped to any actual key in modern systems. However, it is
possible to invoke the H-j
and A-j
key
bindings with the key sequences C-x @ h j
and C-x
@ a j
, respectively,
i.e., ctrl+x @ h j
and ctrl+x @ a j,
respectively.
In fact, similarly, s-j
too can be invoked
with C-x @ s j
,
i.e., ctrl+x @ s j
but that is rarely necessary because s-
is often bound
to a GUI key like the command key on Apple keyboards and
the win key on Windows keyboards.
A practical example of a real and useful s-
key binding
from vanilla Emacs is s-u
to invoke
the revert-buffer
command that reloads a file from the
disk.
Terminal Limitations
The book mentions that there are some key bindings that we cannot
use if we are running Emacs in the terminal. That is because a
terminal supports a very limited set of key bindings. An example
is C-/
that invokes the undo
command in
GUI Emacs. The terminal does not recognise that key sequence.
However, the undo
command is also bound
to C-_
and C-x u
, so one of these key
sequences can be used to undo changes in terminal Emacs.
Definitions for Key Sequences
The book provides a few definitions of key sequences that can be summarised as follows:
-
Key sequence (or just key): A sequence of
keyboard or mouse actions, e.g.,
C-d
,C-M-d
,C-x C-f
,C-x 8 P
,C-x
,C-x 8
, etc. -
Complete key: A key sequence that invokes a command,
e.g.,
C-d
,C-M-d
,C-x C-f
,C-x 8 P
, etc. -
Prefix key: A key sequence that is not a complete key,
e.g.,
C-x
,C-x 8
, etc.
Key Examples
The section Keys presents the following examples of key sequences:
-
C-d
: Callsdelete-char
which deletes the following character. -
C-M-d
: Callsdown-list
which moves forward down one level of parentheses. -
C-x C-f
: Callsfind-file
which is used for editing a file. -
C-x 8 P
: Insersts pilcrow, i.e., the symbol ¶, also known as the paragraph symbol. Here bothC-x
and8
are prefix keys. There are many more key bindings available under theC-x 8
prefix. For example,C-x 8 C
inserts the copyright symbol, i.e., the symbol ©. A set of keys like this that belong to a particular prefix key is called a key map. -
C-M-%
: Callsquery-replace-regexp
to replace text with regula-expression based matching. Since the key % is normally typed as shift+5, this key sequence involves holding down 4 keys together, i.e., ctrl+alt+shift+5. Annoyingly, this happens to be an example of a key sequence that does not work in terminal Emacs due to terminal limitations. -
TAB
: Callsindent-for-tab-command
that either indents the current line or region, or inserts a tab, depending on the context. -
<f1>
,<f2>
, ...,<f10>
: Functions keys that invoke various functions. Some of these are prefix keys while others are complete key sequence. For example,<f1>
is a prefix key that is available as an alternative to theC-h
prefix key. The key sequenceC-h m
shows help for the current major and minor modes, and so does<f1> m
. However,<f10>
is a complete key sequence that calls the commandmenu-bar-open
that shows the menu bar.
C-g: Universal Bail Me Out
The key sequence C-g
is used to cancel a partially
completed command. For example, normally, the key
sequence M-x whitespace-mode RET
toggles the visibility
of whitespace in the current buffer. However, let us say, we type
the partial key sequence M-x white
and then we change
our mind about it and want to cancel entering the command any
further, we can simply type C-g
to
run keyboard-quit
that signals a quit condition and
cancels the input.
Similarly, say, we type C-x
and then we change our mind
about it and want to cancel this partially entered key sequence, we
can simply type C-g
. The following message appears in
the echo area but this is by design:
C-x C-g is undefined
Don't let that message make you feel that you did something wrong by
entering an undefined key sequence. Key sequences ending
with C-g
have been intentionally left undefined, so
that it can be used reliably as the universal bail me out
key sequence.
Now of course, nothing stops us from binding C-x C-g
to
a command of our choice. For example, the following Elisp code
binds it to a command that prints a message:
(global-set-key (kbd "C-x C-g") (lambda () (interactive) (message "You typed C-x C-g")))
However, a key binding like the above one is a very bad idea because
such a key binding flies against Emacs conventions. If we were to
create a key binding like the above one, we can longer rely
on C-g
to be our universal bail out command. Key
sequences ending with C-g
are best left undefined.
Caps Lock as Control
The book recommends configuring our operating system to make the caps lock key behave like ctrl. Many people do find this type of remapping very convenient. Many discussions can be found online where people have claimed that this remapping has helped with overcoming repetitive strain injury (RSI). However, the article Moving the Ctrl Key on Emacs Wiki claims that for some people this remapping causes RSI.
I use the original ctrl keys as they come with the keyboard. Most keyboards have two ctrl keys on either side of the keyboard which I find very convenient. I touch type while editing text, so the two ctrl keys on either side of the keyboard turn out to be really useful. For example, when I need to type ctrl+a, I can hold down ctrl with the little finger of the right hand and type a with the little finger of the left hand. Similarly, if I need to type ctrl+p, I can hold down ctrl with the little finger of the left hand and type p with the little finger of the right hand. Using the original ctrl keys offers this advantage of distributing the usage of the ctrl to both hands. However, some Apple keyboards provide only a single ctrl key on the left hand side which can be quite annoying to touch typists. In such keyboards, remapping the caps lock key to behave like ctrl key can indeed be more convenient.
M-x: Execute Extended Command
The key sequence M-x
is pronounced mex, M
x, or meta x. It invokes the
command execute-extended-command
that brings up a
minibuffer to read a command name and execute it.
When M-x
key sequences are presented in written form,
often they may be written in a precise manner that includes
the M-x
key sequence, then the command name, and
finally the RET
key in the end, e.g., M-x
lunar-phases RET
. But sometimes they may also be written
without the RET
key, e.g., M-x
lunar-phases
. The RET
key is automatically
implied in the latter form.
Interactive Commands
The following function written in Elisp is interactive:
(defun hello ()
(interactive)
(message "hello"))
However, the following function is not interactive:
(defun hola ()
(message "hola"))
The (interactive)
expression declares a function as
interactive which allows it to be called interactively
using M-x
.
To see the difference between the two functions, copy both functions
to some buffer, say, the scratch buffer, and then put the cursor
after the closing parentheses of each function and type C-x
C-e
to evaluate the defun
expressions thus
defining the functions. After doing so, M-x hello RET
executes the hello
function and produces the "hello"
message in the echo area. However, typing M-x hola RET
produces no match for a function named hola
.
M-X: Execute Extended Command for Buffer
Emacs 28 introduces M-X
that runs the
command execute-extended-command-for-buffer
. The book
mentions this key binding as M-S-x
which is in
fact M-X
. In these notes, we'll write M-X
for consistency with how this key sequence is actually defined and
represented in Emacs (for example, note that C-h k
M-S-x
shows the key as M-X
).
To see how this function works, first open a file,
say, foo.el
with C-x C-f foo.el RET
, then
type M-x e RET
. A large list of function names
beginning with the letter "e" as choices appears. Now
type M-X e RET
. A much smaller list of choices that
are relevant for the current Elisp buffer appears.
Universal Arguments
Universal arguments are also called prefix arguments. The
list below presents some examples of complete key sequences where we
apply various prefix arguments to the key sequence C-n
.
C-u C-n
: Move cursor down 4 lines.C-u C-u C-n
: Move cursor down 16 lines.C-u C-u C-u C-n
: Move cursor down 64 lines.C-u 5 C-n
: Move cursor down 5 lines.C-u 15 C-n
: Move cursor down 15 lines.C-5 C-n
: Move cursor down 5 lines.C-1 C-5 C-n
: Move cursor down 15 lines.C-- C-n
: Move cursor up 1 line.C-- C-5 C-n
: Move cursor up 5 lines.C-- C-1 C-5 C-n
: Move cursor up 15 lines.
Note that negative arguments (the last three examples above)
reverses the direction of operation. The digit arguments of the
form C-<digit>
can also be entered
using M-<digit>
or C-M-<digit>
. Here are some examples:
M-5 C-n
: Move cursor down 5 lines.C-M-5 C-n
: Move cursor down 5 lines.M-1 M-5 C-n
: Move cursor down 15 lines.C-M-1 C-M-5 C-n
: Move cursor down 15 lines.M-- C-n
: Move cursor up 1 line.M-- M-5 C-n
: Move cursor up 5 lines.M-- M-1 M-5 C-n
: Move cursor up 15 lines.C-M-- C-n
: Move cursor up 1 line.C-M-- C-M-5 C-n
: Move cursor up 5 lines.C-M-- C-M-1 C-M-5 C-n
: Move cursor up 15 lines.
While entering multiple digits in a digit argument, we can also mix and match modifier keys as shown below, however doing so would be pointless and unwieldy:
C-1 M-5 C-n
: Move cursor down 15 lines.C-1 C-M-5 C-n
: Move cursor down 15 lines.
The reason why Emacs supports entering digit arguments or negative
arguments with all three modifier
combinations C-
, M-
, C-M-
, is
so that we can choose a modifier that is convenient. Usually, this
would be the modifier we anticipate that we'll use next for the
command we are prefixing with the digit or negative argument. For
example, if we are going to move forward by 5 words, then M-5
M-f
is going to be more convenient than C-5 M-f
or C-M-5 M-f
. To type M-5 M-f
, we can
simply press and hold down alt, then type 5
followed by f, and finally release alt.
Similarly, if we are going to move forward by 5 expressions,
then C-M-5 C-M-f
is going to be more convenient than
using any other modifier for the digit argument.
Choosing the modifier combination for a universal argument such that it matches the modifier combination for the key sequence coming up next helps maintain good tempo while typing the key sequences. The book often puts emphasis on the subject of tempo in various chapters.
While discussing tempo, the book presents the example of M--
M-d
which can be used to kill the previous word. Note
that M-d
kills one word forward, so M--
M-d
reverses the direction of the operation and kills one
word backward. The book notes that M-- M-d
maintains
tempo while C-- M-d
which does exactly the same thing
disrupts tempo.
Another example that the section Univeral Arguments briefly alludes to but does not provide a concrete example of is changing the case of a word that we just typed. Here are some concrete examples for it:
-
M-l
: Convert the text from the point to the end of the current or next word to lower case. -
M-u
: Convert the text from the point to the end of the current or next word to upper case. -
M-c
: Capitalise the text from the point to the end of the current or next word. Capitalisation involves changing only the first letter to upper case. -
M- M-l
: Convert the text from the point to the beginning of the current or previous word to upper case. -
M- M-u
: Convert the text from the point to the beginning of the current or previous word to upper case. -
M- M-c
: Capitalise the text from the point to the beginning of the current or previous word.
Discovering and Remembering Keys
To get help for a prefix key, type the prefix key followed
by C-h
. Here are some examples:
C-x C-h
C-x 8 C-h
C-x 8 " C-h
C-x 8 ' C-h
C-x 8 * C-h
Getting help for a prefix key in this manner shows an automatically
generated list of all keys that belong to the key map associated
with the prefix key. Note that a key map for a prefix key may
itself contain more prefix keys. For example, in the above
examples, we see that the key map for C-x 8
contains
prefix keys C-x 8 "
, C-x 8 '
, etc. Such
nested prefix keys are clearly marked in the output as "Prefix
Command".
True Color
There is a note with the title Supported colors in the section The Customize Interface that introduces the following commands:
-
M-x list-color-display RET
: Display names of defined colors and show what they look like. -
M-x info-apropos RET Colors on a TTY RET
: Find an info page on the subject of using colours on a TTY.
Since Emacs 28, we can easily enable 24-bit color in terminal Emacs
by setting the environment
variable COLORTERM=truecolor
. To quickly test it out,
first enter the following command in the terminal:
COLORTERM=truecolor emacs -nw
Then type the following in Emacs:
M-x list-color-display RET
The Customize Interface
The customize interface allows us to customize two things: faces and options. Here are some steps to get started with the customize interface:
-
Type
C-x 2
to split the current window into two. -
Type
C-x C-f foo.el RET
to open a new Elisp file. -
Type some code into the file such that it contains at least one string, for example:
(message "hello")
-
Type
C-x o
to go to the other window. -
Type
M-x customize RET
. -
Move the cursor to the editable text area. This can be done with motion key sequences or with the mouse.
-
Then type
font-lock-string-face
and press enter. The customization interface for the chosen face now appears in the buffer. The message next to the "State" button shows "STANDARD." which indicates that the face is set to its default value. -
Then move the cursor to the editable text area next to the "Foreground:" label, type
blue
. At this point, a preview of blue text is shown next to the "Choose" button. However, the string in the Elisp buffer still appears in its previous colour. The message next to the "State" button shows "EDITED, shown value does not take effect until you set or save it." -
Now click the "Apply" button to apply the new string colour. Alternatively, move the cursor over to "Apply" and press enter. As soon as this button is clicked, the string in the Elisp buffer appears blue. The message next to the "State" button says "Set for current session only."
-
Now click the "Revert..." button and then click "Revert This Session's Customizations" to revert the customization.
-
Now change the string color to blue again and click "Apply and Save". The message next to the "State" button now changes to "SAVED and set." Then check Emacs initialisation file (such as
~/.emacs
,~/.emacs.d/init.el
, etc.) and there should be acustom-set-faces
call added to the initialisation file to set the string colour to blue. -
To erase the customization from the initialisation file, click "Revert ..." and then click "Erase Customizations". At this point, the customization is no longer present in the initialisation file. However, the customize interface shows a confusing message next to the "State" button, "EDITED, shown value does not take effect until you set or save it." Further, the face is set to "-- Empty face --" in the customization interface. To add to the confusion, the "Apply and Save" button is enabled! Beware though! If "Apply and Save" is clicked now, it will set
nil
as the value for the face which will cause the face to appear black or white (not the default colour). -
To get rid of the confusing state of the customization buffer discussed in the previous point and restore the customization buffer to a sane state, click "Revert ..." and then click either "Undo Edits in Customization Buffer" or click "Revert This Session's Customizations". Doing so would end up showing the default colour of the face in the customize interface. The message next to the "State" button shows "STANDARD." again.
Customize Commands
Here are some examples of complete key sequences that invoke various customize commands:
-
M-x customize RET
: Display customize interface. We can reach a specific item to be customized by navigating the groups presented and the subgroups within them. For example, to customizefont-lock-string-face
, we can naviage to Faces > Font Lock > Font Lock Faces > Font Lock String Face. -
M-x customize-browse RET
: Create a tree browser for the customize hierarchy. -
M-x customize-option RET global-display-line-numbers RET
: Customize a specific option. -
M-x customize-face RET font-lock-string-face RET
: Customize a specific face. -
M-x customize-group RET faces RET
: Customize a specific group. -
M-x customize-group RET font-lock-faces RET
: Another example similar to the previous one. This one customizes the Font Lock Faces subgroup within the Faces group. -
M-x customize-mode RET
: Customize the major mode of the current buffer. -
M-x customize-mode RET python-mode RET
: Customize a specific mode. After the firstRET
, a prompt to enter the mode appears only if the current major mode has no known customize group. -
C-u M-x customize-mode RET python-mode RET
: Yet another way to customize a specific mode. Using the prefix argument ensures that we are always prompted for the mode name. This can be useful when we want to customize a minor mode, or a major mode that is different from the current major mode. -
M-x customize-themes RET
: Display a selectable list of custom themes. -
M-x customize-customized RET
: Customize all customizations set in the session but not saved. This is very useful to see all unsaved customizations together at one place. -
M-x customize-saved RET
: Customize all saved customizations. This is very useful to see all saved customizations together at one place. -
M-x customize-changed RET
: Customize all settings whose meanings have changed since the previous major Emacs release. -
M-x customize-changed RET 26.1 RET
: Customize all settings whose meanings have changed since a particular previous major Emacs release.
One thing worth keeping in mind is that when we apply, save, or revert customizations, only the customizations shown in the current buffer are applied, saved, or reverted. Here is an experiment that demonstrates what this means:
-
Type
C-x 2
followed byC-x C-f foo.el RET
to split the current window into two and load an Elisp file in one window. Then insert the following code:(defun foo () (message "hello")) ;; Demo
-
Type
M-x customize RET
, search forfont-lock-keyword-face
, set its colour tored
and click "Apply". -
Then search for
font-lock-function-name-face
, set its colour togreen
and click "Apply". At this point the macro namedefun
is coloured red and the function namefoo
is coloured green in the Elisp buffer. -
Now click "Revert ..." and then click "Revert This Sessions's Customizations". Only the colour of the function name reverts to the default colour. The colour of the macro name remains red in the Elisp buffer. This confirms that the revert operation takes only the customizations in the buffer into account.
-
Search for
font-lock-string-face
, set its colour toblue
and click "Apply and Save". -
Search for
font-lock-comment-face
, set its colour tomagenta
and click "Apply and Save". Inspecting the Emacs initialisation file shows that only the customizations for the string and comment faces have been saved to the file. This confirms that only the customizations shown in the current buffer are saved. -
Type
M-x customize-customized RET
. A new buffer appears and shows the customization for keyword because it was customized and applied but not saved. -
Type
M-x customize-saved RET
. A new buffer appears and shows the customizations for string and comment because they were customized and saved. -
Now search for
font-lock-comment-face
so that the customize buffer contains only the customization entry for comment. Click "Revert ..." and then click "Erase customizations". Inspecting the Emacs initialisation file shows that the customization for comment is removed but the customization for string is still intact. This confirms that only the customization shown in the current buffer is erased.
Evaluating Elisp Code
The chapter introduces two commands:
-
M-x eval-buffer RET
: Evaluate the entire buffer. -
M-x eval-region RET
: Evaluates only the marked region.
Here are some additional key sequences that I find very useful:
-
C-x C-e
: Evaluate the expression before the cursor. This key binding is available inglobal-map
, so this key sequence works in any buffer. -
C-M-x
: Evaluate the top-level expression on the cursor. This key binding is not available in the global map. Therefore this key sequence works only in those major modes that support it. For example, this key sequence works in Elisp buffers because this key binding is available inemacs-lisp-mode-map
.
Info
Info, also known as the Info Reader, is the
documentation browser of Emacs. Type
M-x info RET
or C-h i
to enter
Info.
The following points explain the navigation commands of Info:
-
Type
[
or]
to go to the previous or next node, respectively. Typing]
repeatedly is a nice way to go from one node to the next one without skipping any content. This provides an experience that very close to reading a book page by page althoughSPC
(explained below) might be an even better way. -
Type
l
orr
to go back or forward in history, respectively. -
Type
n
orp
to go to the previous or next sibling node. This is a nice way to go from one chapter to next while skipping all the child nodes, or to go from one section to the next sibling section while skipping all child subsections. -
Type
u
to go up one level to the parent node. -
Type
SPC
to scroll one screen forward at a time. TypeDEL
orS-SPC
to scroll one screen backward at a time. When a node boundary is reached, these commands automatically load the next or previous node. Thus typingSPC
over and over again is a nice way to read all the text in a node and then go to the next node. This provides an experience that is closest to reading a book paragraph by paragraph and page by page. -
Type
TAB
to go to the next cross-reference or menu item, i.e., anything that looks like a link. TypeS-TAB
orC-M-i
to go back to the previous cross-reference or menu item. -
Type
RET
to follow a node reference near point. This behaves like visiting a link. -
Type
m
to prompt for a menu item to go to. The menu item near the point is automatically selected as the default answer to the prompt. -
Type
q
to quit Info. The Info buffer is not killed. Therefore typingC-h i
will switch to the Info buffer and we can read the last node we visited again.
To summarise, the commands [
and ]
are
great for browsing every node. The command SPC
and DEL
are good for reading everything paragraph by
paragraph and page by page.
There are several ways to reach a specific node of a specific manual. The following points describe some of them:
-
When we open the Info reader with
C-h i
for the first time, immediately typingm
is a convenient way to enter a particular menu item for a manual and jump to that manual, e.g., typeC-h i m org RET
to go to the Org manual. -
Since Emacs 28, we can also use
C-h R
to open a specific manual from any buffer, i.e., we do not need to typeC-h i
first to enter Info. For example, typeC-h R org RET
to enter the Org manual. -
To look up the documentation for a command, type
C-h F
, e.g.,C-h F find-file RET
. -
Although not mentioned in the book, a popular way to point others
to a specific node in the manual is to provide an Elisp expression
to visit a node. For example, to read the node
named
Internal Links
in theorg
manual, evaluate the expression(info "(org)Internal Links")
. -
An alternative to the Elisp expression in the previous point could
be typing
C-h R org RET m Hyperlinks RET m Internal Links RET
or evenC-h R org RET m Internal Links RET
. However, the Elisp expression in the previous point is a convenient way to share a pointer to a specific node in a specific manual with other Emacs users.
Apropos
The following key sequences demonstrate how to use the apropos system:
-
C-h a ^whitespace RET
: Find all commands that match the regular expression pattern^whitespace
. -
M-x apropos-command RET ^whitespace RET
: Same as above. -
M-x apropos RET ^whitespace RET
: Show all symbols that match the given regular expression pattern. The matches include symbols defined as functions, variables, and faces. -
C-h d cleanup-region RET
: Show symbols whose documentation strings match the given regular expression pattern. Note that this command shows symbols likewhitespace-cleanup
andwhitespace-report-region
in the results because their documentation strings contain the string"cleanup-region"
. However, it does not show the symbolwhitespace-cleanup-region
because its documentation string does not contain this string. -
M-x apropos-documentation RET cleanup-region RET
: Same as above. -
M-x apropos-library RET whitespace RET
: Show all variables and functions defined by the librarywhitespace
. -
M-x apropos-user-option RET ^whitespace RET
: Show user options that match the given pattern. This includes variables that can be customized in the customie interface. -
M-x apropos-value RET ^[^ ]*text RET
: Show all symbols which have values whose printed representation matches the given pattern.
By default, the apropos commands show the results in alphabetical order. To sort them by scores, evaluate the following Elisp expression:
(setq apropos-sort-by-scores t)
To sort the matches by score as well as show the scores within parentheses next to the matches, evaluate the following Elisp expression:
(setq apropos-sort-by-scores 'verbose)
Note that sorting by score does not work for C-h d
(apropos-documentation
).
Describe
The following key sequences demonstrate the describe system:
-
C-h m
: Display documentation of current major mode and minor modes along with key bindings introduced by the modes. Mode-specific commands that are not bound to any key are not shown. -
C-h x calc RET
: Display documentation of thecalc
command. -
C-h f calc RET
: Same as above. However, note that whileC-h f
can display documentation of any function,C-h x
on the other hand can display documentation of only those functions that are also commands. For example,C-h f string-join RET
works fine butC-h x string-join RET
complains about no match. -
C-h v tab-width RET
: Display documentation of the variabletab-width
. -
C-h k C-x C-f
: Display documentation of the command bound to the key sequenceC-x C-f
.
Links
The following list includes some links that were discussed during the book discussion group meetings: