GNU Emacs

Table of Contents

Emacs is a keyboard-centric text editor.

emacs_screenshot.png

Figure 1: Screenshot of Personal Emacs Setup

1. Keybindings

1.1. Basic

macro command keymap package file description
C-(n,p)         next/previous line
(C,M)-(f,b)         forward/backward, a character/word
(C,M)-v         next/previous screen
C-M-v         next the other window
(C,M)-(a,e)         beginning/end of a line/sentence
C-l         center the cursor and move screen up half a screen
M-(<,>)         beginning/end of a file
C-u <number> <macro>         to feed <number> to <macro>
(C,M)-(d,DEL)         delete/kill a character after/before the cursor
(C,M)-k         kill to the end of line/sentence
C-SPC MOTION C-w         select and kill
C-y         yank (paste)
M-y         flip through the kill ring, <C-h> v kill-ring list them
C-j         newline, evaluate lisp expression in *scratch*
C-/         undo
(C,M)-x         simple/complex execute
C-g         escape
C-(s,r)         isearch (backward)
C-M-(s,r)         regexp isearch (backward) the groups are colored different
M-s o         occur, even during isearch
M-%         query replace, even during isearch
C-M-%         regexp query replace, that supports grouping
C-z         suspends Emacs
C-x ESC ESC         repeat last command
M-TAB         dab completion based on the text in the open buffers
M-T         (transpose-word) drag a word forward
M-\         remove all spaces between words
M-SPC         contract the spaces between words into one space
M-; comment-dwim global-map newcomment newcomment.el insert a comment, do what I mean
C-x C-; comment-line global-map . . comment a line

1.2. Extended

Prefix C-x (X as in eXtend)

1.2.1. Text

macro description
C-; comment out a line
C-TAB indent interactively

1.2.2. Buffer

macro description
C-s s save current buffer/selected buffers
C-w write current buffer to a file
C-f find a file
d open a directory
C-b b buffer menu/type buffer name to move to
k kill a buffer
C-c quit
<right> <left> next or previous buffer
i insert a file

1.2.3. Window

macro description
0 remove window
1 remove every other windows
2 duplicate window below
3 duplicate window to the right
4 0 kill-buffer-and-window
5 (0,1,2,o) do the same but to a frame
o move to other window
C-+ C-- zoom
^ - + enlarge, shrink if larger than buffer, balance windows
{ } shrink, enlarge horizontally

1.2.4. Frame

macro description
<f11> fullscreen
M-<f10> maximize frame

1.2.5. Register r

macro description
s R copy region into the register R
i R insert text form R
w R save workspace to R
j R load workspace form R

1.2.6. Rectangle r

macro description
o open rectangle filled with space
t string rectangle
d delete rectangle
y yank rectangle
c clear rectangle and fill with space
k kill rectangle
r copy rectangle to register

1.2.7. Bookmark r

macro description
m set bookmark at point
b jump to bookmark

1.2.8. Tab t

macro description
0 tab-close
1 tab-close-other
2 tab-new
RET tab-switch
m tab-move

1.2.9. Project p

A project is recognized if it's either tracked by a version control system, or EDE(Emacs Development Environment) has created the project.

1.2.10. Special Characters 8

  • It is the compose key equivalent.
macro description
RET (insert-char) insert unicode by its name or codepoint

Superscript letters in Unicode | Rupert Shepherd

  • e emoji
macro description
e, i emoji-insert
l emoji-list

1.2.11. Narrow n

macro description
d to function
n to region
p to page
w widen

1.3. Local Bindings

C-c may used

1.3.1. Buffer Menu

macro description
m mark
s mark for save
d, C-k mark for delete
x execute markings
u, U unmark (all)
b bury to the end of the list
RET, e, f open buffer menu window
o open on other window
V, O view (in other window)
T toggle show files only
% toggle read-only
g revert buffer
C-o close buffer
q close window

1.3.2. proced   builtin

list running processes, similar to top.

1.3.3. Dumb Shell

  • C-<up>, C-<down> previous or next input

1.3.4. Outline Mode

It is minor mode for markup files. It changes its behavior based on the major mode

  • Help mode: <, > beginning or end of buffer

Prefix C-c @, or sometimes C-c

macro description
C-e, C-s, C-b, C-a show entry, subtree, branches, all
C-c, C-d, C-l, C-t, C-o, C-q hide entry, subtree, leave, body, other, all
C-p, C-n previous or next visible heading
C-b, C-f backward or forward same level
C-<, C-> promote or demote
C-^, C-v move subtree up or down
RET insert heading (it copies the previous heading)

2. Commands

  • M-x execute command
    • Every keybindings are a lisp command that can be executed in here.
  • M-! run shell command and output to the minibuffer
    • It can run sudo with the help of -S option that read from standard input, or with the askpass helper which is ksshaskpass on KDE.
    • C-u prefix makes the output go to the current buffer.
    • Use M-| instead to accept a region as an argument.
  • M-: execute a Lisp expression.
  • view-register
  • compile run compile command and format the output.
  • grep run grep
    • rgrep search thoroughly
  • describe-mode describe the enabled modes
  • indent-rigidly
  • undo-only undo the region selected. It only works for the edits done natively by emacs
  • open-dribble-file record every input events into a file, recent-keys returns last 300 input events.
  • recover-file select file to recover from the auto-save file
    • recover-this-file also exists.

2.1. Text Manipulation

  • align-regexp align a region with ad hoc rules.
  • fill-region break a long line into smaller ones.

2.1.1. Encoding

  • describe-coding-system

Encode

  • encode-region

Decode

  • decode-coding-region
  • C-x RET r (revert-buffer-with-coding-system) try a new coding system.
  • toggle-enable-multibyte-characters toggle between unibyte and multibyte encoding

Translate

  • recode-region
  • recode-file-name translate from one encoding to another.

2.1.2. remember

Save text in ~/.emacs.d/notes

  • remember-region

2.2. Shell Functionalities

  • M-! (shell-command) run shell command in the minibuffer and echo the result.
  • eshell-command run eshell command in the minibuffer

2.3. File Manipulation

  • delete-file, rename-file
  • make-directory make-d
  • load-file: Load Lisp file, especially the .emacs.

2.4. External Functionalities

  • run-python
  • compile
    • It displays the result in a special buffer.
  • shell
    • Run the shell in dumb state
  • dired-mouse-drag drag and drop dired file entry
    • The core DND functionalities are provided by dnd and x-dnd builtins.

2.4.1. Drag & Drop Problem

Dragging files out of Emacs (dired) fails on Plasma Wayland — analysis and fix

2.4.1.1. Summary

Dragging a file from a dired buffer (dired-mouse-drag) onto a Wayland-native application (Dolphin, Chromium) fails with:

dnd-handle-multiple-urls: Wrong type argument: window-valid-p, #<frame org - GNU Emacs at arch 0x55cb3effbc38>

Root cause: the X11 build of Emacs, running under XWayland in a KDE Plasma Wayland session, searches for drop targets only among managed X windows (via the _NET_CLIENT_LIST_STACKING root property). KWin's XWayland→Wayland drag-and-drop bridge presents itself as an unmanaged proxy X window, which is invisible to that search. Emacs therefore concludes the drop landed on its own frame, and the "self-drop" code path then crashes on a genuine elisp bug (a frame is passed where a window is required) — producing the error above.

Fix applied (in init.el, and hot-loaded into the running daemon): two pieces of advice that (1) force Emacs onto its fallback window-walk target search during drags, which does find KWin's bridge, and (2) make the self-drop path tolerate a frame argument.

2.4.1.2. Symptom and environment
Error
dnd-handle-multiple-urls: Wrong type argument: window-valid-p, #<frame org ...> — note the object is the frame the drag started from, i.e. Emacs delivered the drop back to itself.
Emacs
30.2, Arch extra/emacs 30.2-3, X11/GTK3 build (system configuration features include X11 GTK3, no PGTK), running as a daemon (emacs --fg-daemon) on DISPLAY:1=.
Session
KDE Plasma 6.7.1 Wayland (kwin_wayland 6.7.1, xorg-xwayland 24.1.12). So Emacs is an X11 client living inside XWayland.
Drop targets
Dolphin (Qt, no QT_QPA_PLATFORM override → native Wayland) and Chromium (default Ozone platform → native Wayland). Neither exists as a window on the X display Emacs is connected to.
Trigger
init.el binds <down-mouse-1> to dired-mouse-drag in dired-mode-map; that command calls dnd-begin-file-drag / dnd-begin-drag-filesx-begin-drag (a C primitive).
2.4.1.3. Background: how a drag crosses the X11/Wayland boundary
2.4.1.3.1. The XDND protocol (X11 side)

In classic X11 drag-and-drop (XDND), the source application does all the work of finding the target:

  1. The source takes ownership of the XdndSelection selection.
  2. While the mouse moves, the source itself figures out which toplevel window is under the pointer and checks it for an XdndAware property.
  3. It then exchanges XdndEnter / XdndPosition / XdndDrop client messages with that window, and the target reads the data from the selection.

Crucially, "which window is under the pointer" is computed by the source — there is no server-side notion of a drag.

2.4.1.3.2. Wayland windows are invisible to X clients

Under a Wayland compositor, X11 apps run inside the XWayland server. Native Wayland windows (Dolphin, Chromium here) are not X windows: they don't appear in the X window tree, in XQueryTree, or in any EWMH root property. An X11 drag source can never address them directly.

2.4.1.3.3. KWin's XWayland→Wayland DND bridge

KWin bridges this gap (design: KDE Phabricator D15627). From the design description and current source (src/xwl/dnd.cpp, src/xwl/drag_x.cpp in the kwin repository):

  • KWin watches the XdndSelection owner. When an X client starts a drag, KWin tracks the pointer itself (it owns input on Wayland).
  • When the pointer enters a Wayland-native window, KWin maps a proxy X window — created directly on the root window, 8192×8192, carrying an XdndAware property, raised via workspace()->addManualOverlay(m_window) (see WlVisit::WlVisit in drag_x.cpp).
  • The X source is expected to find this proxy as the topmost window under the pointer, and speak ordinary XDND to it; KWin translates the messages into wl_data_device protocol for the Wayland target.
  • When the pointer leaves the Wayland window, the proxy is unmapped.

This works with GTK/Qt drag sources, because their target search is the classic "walk the window tree from the root with XTranslateCoordinates, take the topmost XdndAware window" — stacking order is all that matters, managed or not.

2.4.1.4. Root cause chain
2.4.1.4.1. 1. Emacs enumerates drop targets from _NET_CLIENT_LIST_STACKING

Emacs implements the XDND source in C (src/xterm.c). At the start of each drag (x_dnd_begin_drag_and_drop, around line 12911 in the 30.2 source):

x_dnd_use_toplevels
  = x_wm_supports (f, FRAME_DISPLAY_INFO (f)->Xatom_net_client_list_stacking);

KWin advertises _NET_CLIENT_LIST_STACKING in _NET_SUPPORTED (verified with xprop -root on :1), so this is true, and Emacs uses x_dnd_compute_toplevels (xterm.c ≈ line 3019), which reads the target candidate list from:

XGetWindowProperty (dpyinfo->display, dpyinfo->root_window,
                    dpyinfo->Xatom_net_client_list_stacking, ...)

_NET_CLIENT_LIST_STACKING is set by the window manager and contains only windows the WM manages.

2.4.1.4.2. 2. KWin's bridge proxy is unmanaged — Emacs never sees it

The proxy from WlVisit is an override-redirect-style manual overlay, never managed by KWin-as-WM, and therefore never appears in _NET_CLIENT_LIST_STACKING. So while the classic tree-walk used by GTK/Qt finds it instantly, Emacs's toplevel-list search cannot — the bridge might as well not exist.

This is an unfixed incompatibility as of Emacs 30.2 and current master (the master x_dnd_compute_toplevels differs only in allocation style).

2.4.1.4.3. 3. The drop resolves to Emacs's own frame (self-drop)

When you release the mouse over Dolphin, Emacs's x_dnd_get_target_window (xterm.c ≈ line 4154) checks its toplevel list at the pointer's root coordinates. The only X window there is Emacs's own frame lying underneath the (X-invisible) Dolphin window, so the function returns the source frame with was_frame = true. Emacs then synthesizes an internal drag-n-drop event: "the XdndSelection contents were dropped on this frame".

(Had the pointer been over a spot with no X window at all, the drag would have silently done nothing instead of erroring.)

2.4.1.4.4. 4. The elisp bug that produces the actual error message

The self-drop event is handled by x-dnd-handle-drag-n-drop-event (lisp/x-dnd.el). It computes (posn-window (event-start event)) — and because the drop coordinates don't fall inside a live ordinary window of the frame, posn-window returns the frame object itself. That frame is passed down:

x-dnd-handle-drag-n-drop-event
  → x-dnd-drop-data          (window-live-p check fails for a frame,
                               falls into the "other window" branch,
                               but still passes the frame through)
  → x-dnd-handle-uri-list
  → dnd-handle-multiple-urls  (dnd.el line 195)
      (with-selected-window window ...)   ; ← frame ≠ window

with-selected-window requires a valid window, hence:

Wrong type argument: window-valid-p, #<frame org - GNU Emacs at arch ...>

So the error message is only the last domino — the real failure happened in target detection.

2.4.1.5. The fix (applied)

Both changes live in init.el directly after the (use-package dired ...) block, and were also evaluated in the running daemon with emacsclient --eval, so no restart was needed.

2.4.1.5.1. Advice 1: force the fallback target search during drags

x_wm_supports_1 (xterm.c ≈ line 27760) begins with:

/* The user says there's no window manager, so take him up on it.  */
if (!NILP (Vx_no_window_manager))
  return false;

If x_wm_supports returns false for _NET_CLIENT_LIST_STACKING, Emacs sets x_dnd_use_toplevels = false and falls back to the classic XTranslateCoordinates tree walk (xterm.c ≈ line 4306 onward), which accepts any window whose XDND protocol version is readable (proto != -1, i.e. it has XdndAware) — exactly what KWin's proxy provides.

So the fix is to lie about the window manager only for the duration of the drag, via a dynamic let-binding:

(define-advice x-begin-drag (:around (orig &rest args) xwayland-kwin-dnd)
  (let ((x-no-window-manager t))
    (apply orig args)))

Because the binding is scoped to the modal drag loop, none of the other users of x-no-window-manager / x_wm_supports (EWMH frame activation, fullscreen, _NET_WM_USER_TIME, frame-move syncing) are affected in normal operation.

2.4.1.5.2. Advice 2: make self-drops tolerate a frame

Independently of the target-detection problem, a drop that resolves to a frame position (tab bar, internal border, out-of-window coordinates) should not crash. This papers over the upstream elisp bug:

(with-eval-after-load 'dnd
  (define-advice dnd-handle-multiple-urls (:filter-args (args) frame-drop)
    (when (framep (car args))
      (setcar args (frame-selected-window (car args))))
    args))
2.4.1.5.3. Expected behavior after the fix

During a drag, once the pointer enters a Wayland window, KWin maps its XdndAware proxy covering the whole screen; Emacs's tree walk finds it as the topmost window, performs the normal XDND handshake with it, and KWin forwards everything to Dolphin/Chromium over Wayland. Moving back over an X window unmaps the proxy and the walk again finds the real X window — so drops back into Emacs keep working too.

2.4.1.6. Alternatives considered (and why they were rejected)
2.4.1.6.1. Switch to the pgtk build (extra/emacs-wayland) — ✗

Verified against src/pgtkselect.c / src/pgtkfns.c (emacs-30 branch and master): the pgtk port implements only the receiving side of DND (pgtk-register-dnd-targets, pgtk-drop-finish, …). It has no x-begin-drag at all, and dnd-begin-file-drag errors out with "Dragging files from Emacs is not supported by this window system". Neither NEWS.31 nor master's NEWS announces a pgtk drag source. Switching builds would trade a cryptic error for a clean one.

2.4.1.6.2. Run the drop targets as X11 clients — ✓ but heavy-handed

Putting the targets on the same X server bypasses the bridge entirely and is guaranteed to work with unpatched Emacs:

QT_QPA_PLATFORM=xcb dolphin
chromium --ozone-platform=x11

Kept as a fallback if the advice fix turns out not to interoperate with KWin's bridge for some other reason.

2.4.1.6.3. Rebuild Emacs with a one-line patch — ✓ but costly

Setting x_dnd_use_toplevels = false; unconditionally in x_dnd_begin_drag_and_drop (xterm.c ≈ line 12911) achieves the same as Advice 1 without any lisp. Requires rebuilding the Arch package (native-comp build, long) and re-patching on every update. The let-binding gets the identical runtime effect for free.

2.4.1.6.4. Edit _NET_SUPPORTED on the XWayland root window — ✗ fragile

Any X client may rewrite root properties, so deleting _NET_CLIENT_LIST_STACKING from _NET_SUPPORTED would also push Emacs onto the fallback path. But Emacs caches the atom list per WM lifetime, KWin can rewrite the property, and it lies to every other X client. Strictly worse than the scoped let-binding.

2.4.1.6.5. Report upstream — recommended follow-up

Two distinct upstream bugs worth filing via M-x report-emacs-bug:

  1. xterm.c: the _NET_CLIENT_LIST_STACKING-based target search is blind to KWin's XWayland DND bridge proxy (unmanaged, XdndAware, top of stack). The search should also consider unmanaged XdndAware windows stacked above the matched toplevel, or fall back to the tree walk when the toplevel hit is the source frame itself.
  2. x-dnd.el/dnd.el: a drop whose position resolves to a frame reaches dnd-handle-multiple-urls as a frame object and crashes with-selected-window.
2.4.1.7. Code trail (exact places examined)
Layer File Item Location (Emacs 30.2)
dired lisp/dired.el dired-mouse-dragdnd-begin-drag-files/file-drag with allow-same-frame = t installed dired.el.gz
dnd lisp/dnd.el dnd-begin-file-drag / dnd-begin-drag-filesx-begin-drag; requires (fboundp 'x-begin-drag) ≈ lines 488, 586
dnd lisp/dnd.el dnd-handle-multiple-urls(with-selected-window window ...), the crash site line 195
x-dnd lisp/x-dnd.el x-dnd-handle-drag-n-drop-event — internal XdndSelection self-drop path, passes posn-window result (may be a frame) ≈ lines 464–490
x-dnd lisp/x-dnd.el x-dnd-drop-datax-dnd-handle-uri-list ≈ lines 425–460, 366
C src/xterm.c x_dnd_use_toplevels = x_wm_supports(..., _NET_CLIENT_LIST_STACKING) ≈ line 12911
C src/xterm.c x_dnd_compute_toplevels — reads _NET_CLIENT_LIST_STACKING only ≈ line 3019
C src/xterm.c x_dnd_get_target_window — toplevel path returns own frame (was_frame); fallback tree walk accepts any XdndAware window ≈ lines 4154, 4306
C src/xterm.c x_wm_supports_1 — short-circuited by Vx_no_window_manager ≈ line 27760
KWin src/xwl/drag_x.cpp WlVisit::WlVisit — 8192×8192 root child, XdndAware, addManualOverlay, mapped on entering a Wayland target current master
KWin src/xwl/dnd.cpp bridge bookkeeping / XdndSelection watching current master

Local copies of the elisp are in /usr/share/emacs/30.2/lisp/{dnd,x-dnd,dired}.el.gz.

2.4.1.8. References

3. Modes

Major mode can be enabled on at a time, while minor modes can be used alongside any other modes.

3.1. Major Mode

Major mode is determined by

  1. Local variables mode within -*- var:VAL; ... -​*- in the first line
    • add-file-local-variable-prop-line, delete-file-local-variable-prop-line
  2. Compare file extension against auto-mode-alist
  3. Infer from the interpreter in the #!
  4. Infer from the start of the buffer using magic-mode-alist
  5. Compare file name against auto-mode-alist
  6. Compare the start of the buffer against magic-mode-fallback-mode-alist
    • It checks for image files, markup files, PostScript files, Unix Conf files.
    • The major mode is remapped using major-mode-remap-alist

The default major mode can be accessed by M-x normal-mode

See Choosing Modes (GNU Emacs Manual)

3.1.1. Language

Python

  • python-mode
    • ein

Hex

  • hexl-mode hexedit.

Elisp

  • emacs-lisp-mode
    • C-c C-b (elisp-byte-compile-buffer)
    • C-c C-e (elisp-eval-region-or-buffer)
    • C-c C-f (elisp-byte-compile-file)
    • C-M-x (eval-defun)
    • eval-buffer

XML

  • xml-mode
  • sgml-mode
    • sgml-pretty-print

3.1.2. Special Text

  • picture-mode: draw a diagram, with cursor moving in any direction

3.1.3. View

  • View
  • DocView

3.2. Minor Mode

When a minor mode is enabled globally, it does not show on the mode line.

  • Minor mode can be set by -*- eval: (MINOR-mode) -​*- in the

File

  • read-only-mode
  • desktop-save-mode
    • It is not saved when emacsclient is closed
    • The frame position, search history, file history, registers, buffers are saved
  • auto-save-mode save buffers in #<file># periodically, when auto-save-default is non-nil
    • It is deleted on save, when delete-auto-save-files is non-nil
    • .#<file> -> buffer is temporarily created when the buffer is hot
    • Backup files named <file>~ are made on save when make-backup-files is non-nil
  • auto-revert-mode, global-auto-revert-mode
  • global-ede-mode
    • Emacs Development Environment
    • It is a built-in package that manages projects

GUI

  • tool-bar-mode
  • menu-bar-mode
    • the menu bar can be accessed with F10
  • scroll-bar-mode and horizontal-scroll-bar-mode
  • tab-bar-mode
  • display-line-numbers-mode
    • display-line-numbers-major-tick
    • The line numbers are not aligned correctly in variable-pitch-mode.
  • Mode Line
    • The file status <encoding><newline>@<modifiable><modified><file location>
      • Encoding: U utf-8-unix,
      • Newline: : Unix LF, <DOS> CRLF
    • line-number-mode display line number in the mode line
  • use-dialog-box let the mouse operation open a separate dialog box
  • display-time-mode display time in the minibuffer

Navigation

  • windmove-mode move and swap windows with keybindings
  • outline-mode applicable for any structured document

Text

  • abbrev-mode simple snippet mode that triggered by RET
    • Prefix C-x a
    • C-a or + or l: add-mode-abbrev
    • g: add-global-abbrev
    • ' or e: expand-abbrev
  • auto-fill-mode automatically insert line break
  • M-q (fill-paragraph) automatically insert line breaks and fill the line at the current paragraph
  • C-x f (set-fill-column) set the column numbers for the paragraph
  • fill-region fill the paragraphs in the region, fill-region-as-paragraph consider region as one paragraph
  • center-line center a line
  • visual-line-mode wrap the long line visually

History

  • recentf-mode remember recent files
  • savehist-mode save the history of the minibuffer
  • save-place-mode save the point position
  • Unibyte Editing Mode

3.3. Keymap

  • MODE-mode-map contains the keymap of the mode.
  • keymap-set and define-key can be used to modify the keymap of the mode.

Keymaps are layered with increasing precedence as follows:

  • global-map
  • MAJOR-mode-map
  • MINOR-mode-map
  • OVERRIDING_LOCAL-map

See keymaps with describe-keymap

3.4. Syntax Table

  • describe-syntax to view the full table

Each mode has syntax table named MODE-mode-syntax-table. It is automatically defined by define-derived-mode.

  • (modify-syntax-entry CHAR SYNTAX-DESCRIPTOR) set
  • (char-syntax CHAR) get

The syntax descriptor is a single letter that describes the syntax class

  • - , (OPEN BOX) whitespace
  • w word
  • _ symbol
  • . punctuation
  • ( open parenthesis
  • < comment start
  • \ escape
  • (syntax-ppss &optional POS) to see the parse state at current point
    • paran depth
    • start paran pos
    • current string stop char
    • is in non-nestable comment
    • min paran depth
    • comment type (nil = none,1 = a, 2 = b, 3 = c)
    • string or comment start pos
    • list of nested start paran pos

Syntax Tables (GNU Emacs Lisp Reference Manual)

3.5. Abbrev Table

Each mode also has abbrev table named MODE-mode-abbrev-table.

4. Applications

4.1. Calc   builtin

GNU Emacs Calculator

There's also calculator which is a dumbed down version of the calc with single stack and infix notation.

See Calc.

4.2. Org Mode   builtin

It is a mode for .org file, but it's large enough to be called an application.

See Org mode.

4.3. eshell   builtin

Eamcs Shell

  • There is shell and eshell. shell is the terminal called dumb that runs standard shells, and eshell is the shell and a terminal on its own.
  • eshell can run both commands and Elisp functions.
  • >>> #<buffer BUFFER> to pipe the output into a buffer.
  • C-c C-n, C-c C-p move to next or previous prompt
  • It has two different parser: one for Elisp and one for shell script.
    • $(...) for Elisp parser, and ${...} for shell script parser.
    • Some of the keywords has different syntax than the usual shell script.
    • The precedence is: alias, eshell/ function, lisp function, executable.
  • Runs the commands in eshell-visual-commands, in a special buffer.

4.3.1. Globbing Filter

*(...)

  • . file, / directory
  • ^ not
  • : modifiers: U uppercase

4.4. vterm

  • C-c C-t toggle VTerm-Copy mode that make the buffer into a regular one.

4.5. eww   builtin

Web Browser

It does not run javascript, and only shows the text from the HTML file.

4.6. calendar and diary   builtin

Diary is a simple way of remembering a data. Calendar integrates diary.

  • The diary is stored in ~/.emacs.d/diary file. which contains list of date-description pairs.
    • i d to create new diary entry

4.7. mpc

mpd client

The player is controlled by commands.

  • mpc-play, mpc-pause, mpc-toggle-play, mpc-stop, mpc-play-at-point
  • mpc-playlist, …

4.8. emms

Emacs Multimedia System

The add function and browser window is for Emacs exclusively. It tells the player through various backends within emms-player-list, one of which is emms-player-mpd.

  • emms-player-mpd-connect needs to be called first.
  • For the case of mpd the songs has to be within the mpd database, making new songs unable to play, unless the database is updated separately, either through mpc update or emms-player-mpd-update.
  • emms-player-spotify can be installed separately, which controls the local spotify app.
  • emms-all enables various features.

See The Emms Manual, mpd

4.8.1. Related

4.9. ses   builtin

Simple Emacs Spreadsheet

It is enabled in .ses files.

4.10. ispell   builtin

Spellchecking.

  • It uses ispell by default. Change it to hunspell by setting ispell-program-name
  • r replace, a accept for this session, i insert to dictionary, u uncapitalize and inser to dictionary, SPC skip
  • ispell-chage-dictionary for other language.
    • flyspell-mode highlights the misspelled words.
      • M-$ check the spelling at point
      • C-; to correct word in place
      • C-c $ to correct word interactively
    • ispell-buffer will check the buffer for spelling.

4.10.1. Configuration

  • personal dictionary is stored in ~/.hunspell_DICT.
    • noun: /10 (with final consonant), /25 (without final)

4.11. shr   builtin

Simple builtin HTML renderer

  • shr-render-buffer, shr-render-region

4.12. Amusements

  • dunnet text-based adventure
  • snake, tetris, pong
  • solitaire peg solitaire
  • gomoku, hanoi
  • decipher solve the monoalphabetic substitution cipher
  • morse-region, unmorse-region convert to morse code
  • nato-region, denato-region convert to NATO phonetic code
  • zone doodles with buffer when idle.
  • dissociated-press scramble the text in the current buffer and puts them in *Dissociation*
  • butterfly from the internet joke.
  • doctor therapist Eliza

5. Packages

Add MELPA for more packages

(setq package-archives
      '(("gnu" . "https://elpa.gnu.org/packages/")
        ("nongnu" . "https://elpa.nongnu.org/nongnu/")
        ("melpa" . "https://melpa.org/packages/")))
  • Packages are managed by the built-in package package.
    • (package-initialize) needs to run first to be able to use require. It is run automatically before .emacs since Eamcs 27.
    • But it doesn't seems like it runs package-refresh-contents also.
  • Add MELPA repository by modifying package-archives with M-x customize-option
  • package-vc-install REPO-DESC can be used to install from the source.
    • REPO-DESC can be the repository url, or a list that describe the package: '(org :url URL).
  • (package-delete PKG-DESC FORCE NOSAVE)
    • PKG-DESC is stored in the pkg-alist, which then can be extracted with cdr of assoc.

5.1. Evil

Vi emulation

  • It is customizable under Editing > Emulations > Evil
  • Viper is the default Vi emulation, but it is more primitive with less keybindings and less commands.
    • No q macro, no :register and :jumps, ci or ca.
  • It is required to (require 'evil) from the .emacs to properly set it up. Custom does not properly enable evil-mode
  • The initial evil mode for a major mode can be customized by the state mode variables or evil-set-initial-state function in the init file.

5.1.1. Keybindings

  • ? in the middle of key sequence to show helps
5.1.1.1. <N> Normal Mode
  • W, B move a WORD, which means space separated words.
  • WORD, word, line, paragraph and others are collectively known as text objects.
  • L bottom of the screen, H top of the screen
  • u undo, C-r redo
  • g f find file at point, g x open immediately
  • g q fill region (automatically add line breaks)
    • g q q fill line
  • J join the next line at the end of the current line.
  • = auto indent, >, < indent and outdent, S start a line with auto indent
  • ~ toggle case of a character
    • g ~ toggle case of a region given by the motion, g ~ ~ toggle case of a line.
  • i select in, a select around:
    • b, (, ) parenthesis
    • B, {, } brace
    • t tag
    • p paragraph
  • / regexp can be used in the query
    • \< \> match exact word
    • * search word at point
    • c g n change next match
      • This requires the evil-search-module to be evil-search.
  • m mark current position, ' goto the marked line, ` goto the marked position
    • The marks are added to the jumplist.
  • Jumplist
    • Show with :jumps
    • C-SPC creates the jump point as well
  • [ ', ]' previous and next mark line, [`, ]` previous and next mark
  • [(, ]) previous open and next close paranthesis, [{, ]} previous open and next close brace
  • [[, ]] backward section begin and forward section end, [], ][ backward section end and forward section begin
  • [s, ]s previous and next flyspell error
  • ! shell command, !! shell command again on the same region (:.!)
  • z scroll
    • b this line to the bottom, t this line to the top, z this line to the center, + bottom line to top, ^ top line to bottom
    • l scroll right, h scroll left.
  • z fold
    • c close one, m close all, o open one, r open all, O open subtree, a toggle
  • C-y scroll down a line, C-e scroll up a line.
  • g d go to definition
  • Q (Vim only) enter ex (ed extended) mode
  • Z
    • Q quit without saving
    • Z save and quit
5.1.1.2. <V> Visual Mode
  • v visual mode, V visual line mode <Vl>, C-v visual block mode <Vb>
  • Line based commands such as I, A can be entered after a region is selected.
  • g v select the previous selected region in visual mode
  • o to select in the other direction
  • '<,'> indicates a line in a selected region.
  • ! can be called on the region, using it as the standard input.
5.1.1.3. <O> Command Argument
  • most of the motion keys still words
  • z, Z the two character evil-sniper
5.1.1.4. <I> Insert Mode
  • C-r insert from a register
    • = put the result of simple calculator
  • C-w delete a word backward, C-h delete a character
  • C-o run a normal mode command
  • C-p, C-n complete from previous or next text
  • C-x Completion mode (only in Vim)
    • C-] tag completion from the ctags
    • C-f file completion
    • C-p, C-n context-aware local completion from previous or next text
    • C-l context-aware line completion
    • complete variable is used to determine where to look for completion
  • C-v insert special characters, such as .
5.1.1.5. <M> Motion Mode
  • It allows the other program to temporarily override the keybindings.
  • But some are reserved
    • hjkltfwb<C-f><C-b><C-u><C-d><RET>{}()=movement, =/?nN search, 123... numbers, v visual mode
    • <C-]> visit the tag under the cursor
    • [] ?
5.1.1.6. <E> Emacs Mode
  • Every keybindings are removed except <C-z> which toggles the Emacs mode.
  • It can be escaped from the other modes by using the escape character \. \ is one-time, <C-z> is persistent.
  • Numbers are bound to simply <C-u> [123...]
    • Emacs provide <ESC> 1 and <M-1> to function the same.
5.1.1.7. Registers "
  • " the last deleted, yanked, or secondary system copied
  • . the last manual insert
  • + secondary system clipboard
  • * primary system clipboard (highlighted text)
  • - last deleted text
    • it is also stored in "
  • : the last vim command
  • % current filename
  • = simple calculator
  • 0 last yanked text
  • 19 stores the last nine (non-unique) entires that was stored in " , with the latest unique one being 1.

5.1.2. Commands :

  • Address insert
    • /REGEX/ select a line containing the regex.
  • e[dit] FILE open file
  • r[ead] FILE insert the content of the file
  • norm[al] escape to normal mode programmatically
  • m[ove]±N
  • ab[brev] create an auto-expanding abbreviation.
  • !COMM execute shell command
5.1.2.1. Window Commands :, C-w

Creation

  • new, n new window
  • sp[lit], s split horizontally
  • vs[plit], v split vertically

Modification

  • , [rR] rotate down or right / up or left
  • , x exchange with the next
  • , = equal width and height
  • res[ize] ±N, [+-] change height
  • vert[ical] res[ize], [<>] change width

Deletion

  • clo[se][!], c close the file if it is not modified, or hide the window
  • q[uit][!], q close the file
  • on[ly][!] close windows except only the current one
  • , [jkhl<arrows>] move or create

5.1.3. External Keybindings

  • Info Page
    • p n previous/next node
    • u up
    • d the directory node
    • s regexp search
    • m menu in current node
    • i search in the index of current node. Leave empty to show all
  • Buffer Menu
    • Entered by <M-x> buffer-menu or <C-x> <C-b>
    • <RET> f select the buffer in place
      • o open in another window, <C-o> and not focus
      • 1 select in full-frame window
      • 2 select it as one window of the two-window frame
    • d s u flag for deletion/saving, remove flags(unmark)
      • x perform the deletion and saving as flagged
      • U remove all flags from all lines
      • m mark to be displayed in another window, v opens them at once with the current
      • . the flag is for the previous buffer that opened buffer menu
    • ~ mark as unmodified
    • % toggle read-only
    • q quit
  • (add-hook 'evil-local-mode-hook 'turn-on-undo-tree-mode)

5.1.4. Plugins

5.1.4.1. evil-numbers
  • it enables the C-a C-x inline number manipulation in Vim.
  • evil-numbers/inc-at-pt, evil-numbers/dec-at-pt is provided.
5.1.4.2. evil-surround
  • cs<old delimiter><new delimiter>, ds<old delimiter>, ys<motion><new delimiter> to surround.
  • S<new delimiter> in visual mode.
  • t can represent a HTML tag as a delimiter.
  • Open delimiters for spaced delimiter, and close delimiter for tight delimiter.

evil-embrace for custom surrounding pairs.

5.1.4.3. evil-leader
  • evil-leader/set-leader, evil-leader/set-key to customize
  • The global-evil-leader-mode needs to be enabled before evil-mode.
5.1.4.4. evil-snipe
  • evil-snipe-override-mode override f, t so that it highlights
  • evil-snipe-mode add 2-character search s and x
    • It is z and x (exclusive) in the operator state, the small cursor state that waits for the motion.
5.1.4.5. evil-tex
5.1.4.6. evil-org
  • gh, gj, gk, gl navigate between elements
  • vae select and element, vaR select a subtree
  • M-RET insert heading, TAB, g TAB fold/unfold
  • M-h, << promote a heading
  • M-l, >> demote a heading
  • M-S-h, M-S-l, <aR, >aR, M-k, M-j move subtree
  • (, ), previous, next table cell, {, } beginning, end of table
  • vae select a cell, vaE select row, var select table
  • GitHub - Somelauw/evil-org-mode: Supplemental evil-mode keybindings to emacs …
5.1.4.7. evil-fringe-mode

Display the markers in the fringe.

5.2. LaTeX

5.2.1. AUCTeX

  • auctex, auctex-latexmk, auctex-lua

Set TeX-engine to XeTeX or LuaTeX for ttf fonts.

  • <C-c> <C-c> run command
  • <C-c> <C-v> view pdf
  • <C-c> <C-p> <C-b> preview buffer

Useful minor modes

  • prettify-symbols-mode display symbols inline
  • cdlatex-mode quick input of LaTeX
  • outline-mode the contraction of sections

See LaTeX Input for Impatient Scholars | Karthinks

5.2.2. CDLaTeX

LaTeX input method

  • TAB
    • ali, ali*, equ, fg, fr, sq, beg, …
    • M-x cdlatex-command-help shows the full list
  • ` symbols
  • ' styling
  • ^, _ superscript and subscript

5.2.3. RefTeX

It is Emacs builtin, that recognizes the multi-file bibliography. It is used by CDLaTeX when inserting citation.

  • reftex-parse-all
    • It is run when a file is first opened.
    • It needs to be manually run for the changes to be recognized.
  • C-c [, (reftex-citation) insert citation from the bib database file specified in \addbibresource{} and the default bib database.
  • C-c ), (reftex-reference) add reference among the current file.

5.3. IDE

  • Integrated Developer Environment

5.3.1. elpy

  • No longer an active project. Replace with language servers.

Emacs Python development environment

It sets up a virtual environment for each projects in the background and communicate through RPC. The virtual environment is installed in .emacs.d/elpy/rpc-venv/ by default.

It completes using company.

  • elpy-rpc-reinstall-virtualenv solved the sentinel error.
5.3.1.1. Features
  • Run (elpy-enable) to enable all the modules.
  • <M-TAB> elpy-company-backend provide completion suggestions at point

See Elpy — Elpy 1.35.0 documentation

5.3.1.2. Related
  • python: python interpreter
  • jedi: It autocompletes the python script. It also uses virtual environment and communicate through RPC via epc.
    • company-jedi and jedi are the frontends of jedi-core for company and auto-completion respectively.
    • jedi:install-server to first set the virtual environment up.
    • jedi:get-in-function-call displays the function signature at the minibuffer. jedi:show-doc is also there.
  • flymake and flycheck is available for Python.
  • Python - WikEmacs

5.3.2. ein

Emacs IPython Notebook

  • ein:run ein:stop to start and stop the jupyter notebook server.
  • C-c C-c Evaluate current cell.
  • C-c C-b, C-c C-a Add a cell below or above
5.3.2.1. Related
  • jupyter It controls the Jupyter server.

5.3.3. rustic

Rust IDE

5.4. LSP

  • Language Server Protocol

5.4.1. lsp-mode

LSP Mode - Language Server Protocol support for Emacs - LSP Mode - LSP suppor…

It supports all kinds of languages and their servers. The servers are external programs that needs to be installed separately.

  • lsp-ui provides the sideline, childframe, and others.
5.4.1.1. Language Servers
  • ccls C/C++/Objective C
    • Additional ccls package required
    • Disable it with (setq lsp-disabled-clients '(ccls)).
  • clangd C++
    • Builtin
    • .clangd or compile_commands.json from the build system is required to figure out the compiler options.
  • python-lsp-server
    • Builtin
  • pyright
    • Additional lsp-pyright required
    • The successor of Microsoft Python server
  • (lsp-register-client CLIENT) is used to register a language server for a certain mode or file extension.
    • Many are registered by default. But an obscure one has to be registered manually.
  • (make-lsp-client ...) is used to create the CLIENT object of the type lsp--client.
    • :new-connection CONNECTION run and connect to the language server.
    • :major-modes MODE set the major mode in which language server starts.
    • :server-id ID ID can be anything of the form 'id.
5.4.1.2. dap-mode

Debug Adapter Protocol

DAP Mode

5.4.2. Eglot   builtin

  • Builtin language server protocol client

It is getting polular with its close integration with Emacs.

The official manual: Eglot: The Emacs Client for the Language Server Protocol

Example setup: Trying eglot, again

  • eglot-format auto formatting
  • eldoc open the documentation preview buffer in another buffer

5.5. Parser

5.5.1. syntax   builtin

Functions

  • syntax-ppss parse the parenthesis depth and others

5.5.2. SMIE   builtin

  • Simple Minded Indentation Engine

Uses very limited operator precedence grammar to parse the text.

5.5.3. Treesit   builtin

Treesit can be used to highlight text based on the tree-sitter queries via font lock. treesit-font-lock-rules is used to generate treesit-font-lock-settings, and treesit-font-lock-feature-list is used to determine the order of highlighting.

See Parser-based Font Lock (GNU Emacs Lisp Reference Manual)

Uses Tree-sitter.

5.6. Appearance

5.6.1. rainbow-identifiers

Highlight the unclassified variables using alternating colors, while same color is assigned to same symbol.

5.6.2. rainbow-delimiters

5.6.3. Font Lock   builtin

Three method used to determine the highlighting is tried in the following order:

  1. External parsing often by Treesit
  2. Syntactic parsing using syntax table
  3. Search based on regular expression

The highligting is applied for text in the following order:

  1. Comment and constant (fast)
  2. Keywords
  3. Function locals

Variables

  • font-lock-defaults various rules for search highlighting, including keyword
  • font-lock-keywords matcher list of for keywords

5.6.4. hs-minor-mode   builtin

  • Hideshow mode

Reliable and simple backend for evil folding.

5.7. Tool

5.7.1. eimp

Emacs Image Manipulation Package

It enables simple image processing within Emacs.

5.7.2. pdf-tools

It replaces the builtin doc-view for the case of PDF files, with almost the same keybidings.

  • pdf-tools-install on startup to enable it on startup.
  • n, p next, previous page, C-n, C-p next, previous line or page, SPC scroll
  • +, -, 0 enlarge, shrink, reset scale, H, W, P fit height, width, page
  • m mark to a register, ' jump to register
  • o show outline
    • TAB toggle children, RET follow link, C-o, SPC display link
    • a show all sublevel, Q hide all sublevel
    • s, d show, hide subtree
    • f, b forward, backward same level, u up heading
    • o return to the pdf, q quit
    • Outline mode also works
  • F link action perform
  • l or B, r or N history backward, forward
  • GitHub - vedang/pdf-tools: Emacs support library for PDF files.

5.8. Magit

Git user interface

5.8.1. Commands

  • c commit
  • s stage
  • P push

5.8.2. Authentication

The user field is filled by the git itself. Add username = <username> in the [credential] section of your git config.

  • magit-process-find-password-functions fill password automatically with these functions. -magit-process-password-auth-source is provided out of the box.

Git can manage password by itself. In that case you do not need magit authentication.

5.9. Edit

5.9.1. newcomment   builtin

Variables

  • comment-start the comment character
  • comment-add number of additional comment characters to insert
  • comment-use-syntax use syntax table to recognize comment

Commands

  • comment-dwim

5.9.2. undo-tree

Tree-structured undo system, compatible with evil.

  • <C-/> <C-_>: undo
  • <C-?> <M-_>: redo
  • undo-tree-switch-branch
  • <C-x> u undo-tree-visualizer

5.9.3. Iedit

C-;, possibly during isearch, enters the Iedit mode in which all the occurences are modified simultaneously.

The iedit-mode-occurance-keymap is only active when point is on the highlighted region. (iedit-occurance-keymap is the same but local map)

  • TAB next occurance
  • C-' narrow to selections
  • M-I to restrict to current line
  • M-C toggle case sensitivity
  • M-n and M-p expand to next or previous occurance
  • M-{ and M-} to expand the region

5.9.4. multiple-cursors

Multiple cursor does not work nicely with evil. The change is often not applied to every position.

It requires the users to bind the commands themselves.

  • mc/mark-mode-like-this-expand do expand, skip, shrink with arrow keys
  • mc/mark-all-dwim do what I mean
  • C-v (mc/cycle-forward), M-v (mc/cycle-backward) moves the point to the other occurances

5.10. Snippet

  • Autotype
  • abbrev.el: Abbreviation expansion, builtin
  • expand.el: Abbreviation expansion, builtin
  • skeleton.el: Lisp syntax for templates, builtin
  • tempo.el: Lisp syntax for templates, builtin
  • skempo.el:
  • srecode.el: CEDET template manager and code generator, builtin
  • aas.el: Auto activating snippets
  • cdlatex.el: Fast LaTeX insertion
  • laas.el: Latex auto activating snippets
  • muban.el: Lightweight template expansion
  • placeholder.el: Treat buffers as templates
  • tempo-abbrev.el: Abbrev integration for Tempo
  • snippet.el: Original snippet mode, with inline expansion (from EmacsWiki?)
  • tempo-snippets.el: Interface like snippet.el for Tempo
  • yasnippet.el: Template system inspired by Textmate snippets
  • templatel.el: Jinja2 subset
  • amno1/lite:
  • tempel: Template package which uses the syntax of the Emacs Tempo library.

5.10.1. Abbrev   builtin

Eamcs builtin

5.10.2. Skeleton

Emacs builtin

5.10.3. Yasnippet

Yet Another Snippet

  • yas-snippet-dir specifies the location of the snippets, with ~/.emacs.d/snippets/ being the user snippets.
    • Snippets in a directory named with a specific mode is only activated in that mode.
    • The directories are shadowed by others.
  • C-c & C-n to define a new snippet
  • C-c & C-s to insert snippet
  • LaTeX snippets with Yasnippet & Auto Activating Snippets - YouTube useful?
5.10.3.1. Snippet Format
  • $0 the final point position.
  • $1, …, $9 the tab-stoppable fields
    • {$n:DEFAULT_VALUE} set default
    • $n mirror: Use the same number again to mirror the field.
      • {$n:$(LISP(yas-text))} mirror with transformation: the value of the field n which is represented by yas-text is transformed with Lisp expression.
    • {$n:DEFAULT_VALUE$(LISP(yas-text))} field with transformation: the inserted value is automatically transformed with given Lisp expression.
      • {$n:$$(LISP(yas-text))} is used when there's no default value.
  • `LISP` is run as soon as the snippet is expanded, and the result is inserted.
  • Yet another snippet extension
5.10.3.2. yasnippet-snippets

yasnippet-snippets and other packages contain the snippets in yasnippet-snippets-dir for yasnippet to use.

5.11. Completion

5.11.1. Minibuffer

They provide the completion candidates through completing-read-function

5.11.1.1. Icomplete   builtin

Suggest the completion inline within minibuffer.

5.11.1.2. Ido   builtin

Interactive do

Suggest the completion inline within minibuffer. The old completion UI that list candidates separated with |.

5.11.1.3. Ivy

It shows the completion candidates in the minibuffer vertically, similar to Vertico.

The UI looks old though.

5.11.1.4. Vertico

It displays the completion under the minibuffer vertically.

  • PGTK might not work with Vertico, where the input events drops and vertico does not update.
  • vertico-indexed-mode
    • Enable the C-u N RET to select the N th entry.
5.11.1.5. Marginalia

It displays description or type of the item beside the minibuffer entry.

Symbol classes

  • Function
    • f function
    • c command
    • C interactive-only command
    • m macro
    • F special-form
    • M module function
    • P primitive
    • g cl-generic
    • p pure
    • s side-effect-free
    • @ autoloaded
    • ! advised
    • - obsolete
    • & alias
  • Variable
    • u custom (U modified compared to global value)
    • v variable
    • l local (L modified compared to default value)
    • - obsolete
    • & alias
  • Other
    • G custom group
    • a face
    • t cl-type

See marginalia--symbol-clases (f)

5.11.2. Buffer

5.11.2.1. dabbrev

Complete based on buffer content

5.11.2.2. hippie-exp

Function

  • hippie-expand try the functions in hippie-expand-try-functions-list

try-expand-dabbrev-all-buffers is really good

5.11.2.3. auto-completion

The oldest auto-com

5.11.2.4. company

It is newer compared to auto-completion.

Top Company User Manual

  • Modular architecture
  • <C-g> to stop suggestion.
5.11.2.4.1. Modules
  • company-jedi, company-auctex, company-bibtex, company-lua
5.11.2.4.2. Configuration
  • company-minimum-prefix-length=(Option): The length of string to activate the completion. default to =3.
  • company-idle-delay=(Option): The reaction time. default to =0.3?
  • company-frontends (Option): The UI part
    • Default to (company-pseudo-tooltip-unless-just-one-frontend company-echo-metadata-frontend company-preview-if-just-one-frontend) (List of Functions)
      • Use (setq VAR '(LIST)) to set it
    • tooltip: inline popup
      • (setq company-format-margin-function #'{company-dot-icons-margin|company-text-icons-margin|company-vscode-{light|dark}-margin})
        • #' is used to quote a function.
        • company-vscode-{light|dark}-margin (Function) uses the VSCode icons in the graphical interface only, showing nothing in the terminal interface.
    • preview: The inline suggestion
    • echo: Mini buffer suggestion
  • company-backends (Option): The completion part
    • (company-bbdb company-semantic company-cmake company-capf company-clang company-files (company-dabbrev-code company-gtags company-etags company-keywords) company-oddmuse company-dabbrev)
  • company-global-modes (Option): Major modes in which company modes is enabled by global-company-mode (Command).
5.11.2.5. corfu

Frontend UI that utilizes the emacs completion system, compared to company's own system.

5.11.3. Backend

5.11.3.1. Orderless

Additional completion-style

  • The default completion starts looking from the start, or from the middle if it starts with a special characters. But this style allows find in the middle
5.11.3.2. Cape

Extended completion-at-point-funcitons

  • cape-dict uses /usr/share/dict/words by default

5.12. Interface

5.12.1. Consult

Simple navigation system, that integrates the native functionalities.

  • consult-buffer it is multi-sourced search
  • consult-outline search through the headings
    • consult-org-heading
  • consult-line narrowing lines
  • consult-imenu search through flattened imenu. It lists the identifiers in prog-mode.
  • consult-grep
    • #TEXT#FILTER TEXT the TEXT is searched if the file includes FILTER TEXT.

5.12.2. Embark

The minibuffer action within Consult

  • C-. in minibuffer
    • k kill buffer

5.12.3. helm

Incremental narrowing for basically everything.

Prefix C-x c

  • M-x (helm-M-x) the fancy M-x. It is rebound to M-x
  • / (helm-find) find the entire file system with find
  • f (helm-multi-files) search files and buffers at the same time
  • a (helm-apropos) find any command, function, variable, or face
  • i (helm-imenu) menu: search outlines in org
  • l (helm-locate) use locate command to find files.
  • m (helm-man-woman) search through man pages.
  • o (helm-outline) show the outline
  • C-x C-f (helm-find-files)
  • C-x C-b (helm-buffers-list)
  • C-c f (helm-recentf) the recentf-open is remapped to helm-mode-recentf-open in helm-mode
  • C-c g (helm-google-suggest) search on Google

See Helm | Emacs incremental completion and selection narrowing framework

5.12.4. Counsel

Interface similar to Consult that uses Ivy

The old system that does not integrate with the system functions.

5.12.5. Swiper

The search functionality with preview similar to Consult, using Ivy completion.

5.12.6. Casual

It uses transient to show the menu(tmenu).

casual-calc is opened with <C-o>

5.12.7. which-key

Show the list of available keybindings

5.12.8. Hydra

5.12.9. Treemacs

  • treemacs-mode added to aw-ignored-buffers by default.
    • Set aw-ignore-on to nil to disable this behavior.
  • Set treemacs-hide-dot-git-director to nil in order to see .git.
  • P peek mode that previews the documents.
  • d delete a file, c copy a file, m move a file, R rename a file, Q kill buffer
  • o open
    • c and close treemacs, o no split, h, =v in splitted window, x external application
    • a a with ace window selection, a h, a v with ace windoe split
  • c create
    • d directory, f file
  • M-h move up or collapse, M-l same as RET
  • M-m bulk operation

Treemacs has workspaces which can contain multiple projects. Project can be a plain directory or a version controlled directory.

  • M-L, M-H change the project root directory.
  • C-c C-w Workspace Prefix
    • a create, d remove, s switch, e edit the ~/.emacs.d/.cache/treemacs-persist directly.
    • f set fallback workspace (the default)
  • C-c C-p Project Prefix
    • a add, d remove, r rename
  • Related: dired-subtree and dired-sidebar, dirtree, neotree, sidebar. Among which dired-sidebar seems promising.

5.12.10. dired   builtin

Directory Editing

C-x d, M-x dired Open a directory with Dired

Dired is extensible with additional packages

Dired Guess

  • dired-guess-shell-alist-user contains the list of suggestions based on the filename

Git

  • dired-git show git branch information and execute git commands

Icons

  • nerd-icons-dired
  • all-the-icons-dired
  • treemacs-icons-dired

Interface

  • dirvish overhaul of the entire interface
5.12.10.1. Local Keybindings
  • v view
    • Open with View Major mode if no other major mode for view is available.
    • q to exit
  • C do copy, D do delete, R do rename/move
  • d mark to delete
  • x execute flagged delete
  • i add subdirectory into current buffer
    • $, M-$ toggle hidden (of all)
    • C-M-u, C-M-d Tree up or down
    • C-M-n, C-M-p Next or previous subdirectory
  • m, u mark and unmark
  • T do touch, O do chown, M do chmod, G do chgrp, N do man, I do info, S do symlink, H do hardlink, Z do compress
  • X do shell command
  • C-x C-f to create a new file, make-directory to create a new directory.
  • g revert(reload) buffer
  • C-x C-q immediate edit
  • ^ > < Parent directory, Sibling directory
  • w copy filename to kill ring
  • W browse url of dired file
    • It opens a new server editing buffer for text files, which is like a externally opened file but in the same frame.
    • C-x # to mark it done and switch to next server editing buffer.
  • J goto file
  • & async shell command on the file at point, X shell command on the file
  • C-t thumbnail
    • . display thumbnail in other window
    • C-t toggle inline thumbnail
    • a append thumbnail to the thumbnail buffer
    • d display thumbnails of file at the cursor, or marked files
    • i display image in other window
    • j jump to thumbnail buffer
    • x display image externally
  • C-t tag
    • The tags are stored in ~/.emacs.d/image-dired/.image-dired_db
      • t tag files
      • r delete tag
      • f mark tagged file
  • * mark
    • m mark, u unmark, ! ? unmark all
    • * executable, / directory, @ symlink, s subdir files
    • % mark with regexp
    • * C-n, * C-p or M-{, M-} previous or next marked file
  • % regexp
    • C copy
    • R, r rename
    • S symlink
    • Y resymlink
    • H hardlink
    • d flag, g flag files containing regexp
    • & flag garbage files
    • m mark
    • l, u downcase, upcase
5.12.10.2. Configuration
  • ls-lisp-use-insert-directory-program use external ls instead of ls-lisp, the builtin ls emulation written in Lisp, if this is t
    • This does not apply to dired-sidebar for some reason.
    • insert-directory-program the external program to be used
    • dired-listing-switches controls the options passed to the program, including ls-lisp
  • ls-lisp-dirs-first
    • list directory first when using ls-lisp
  • dired-use-ls-dired append --dired option

5.12.11. wdired   builtin

Rename file directly in the dired buffer

5.12.12. dired-sidebar

  • dired-sidebar-toggle-sidebar
  • TAB (dired-sidebar-subtree-toggle)
  • RET (dired-sidebar-find-file) open the file in the last window
  • C-o (dired-sidebar-find-file-alt) opens the file in the window selected by ace-window
  • - (dired-sidebar-up-directory)

5.12.13. popper

  • Manage window by classifying them into regular, popup windows

5.12.14. keycast

Provide keycast-mode-line-mode, keycast-tab-bar-mode, keycast-header-line-mode which shows the keypresses.

5.12.15. diminish

Hide the mode indicator for a minor mode

5.13. Workspace

5.13.1. project   builtin

Emacs builtin It recognizes version controlled folders and EDE projects.

5.13.2. Projectile

Project is a folder containing specific file.

  • VCS marker
  • pom.xml, Gemfile
  • It can be extended

5.13.3. Perspective

There are similar packages

  • persp-mode
  • workgroups2
  • activities

Buffer manager

  • bufler
  • tabspaces

5.14. Music

5.14.1. spotify

It controls the local Spotify app through D-Bus

5.14.2. smudge

Control Spotify using App API. It provides more complete functionalities.

Prefix C-c .

  • M-p play/pause
  • M-b, M-f previous and next track
  • M-s, M-r shuffle and repeat control
  • p playlist
    • f featured, m my, s search, c create
  • t track
    • r recent, s search
  • v volume
    • u, d, m up and down and mute
  • d device
  • Buffer
    • M-RET play now
    • k add to the queue
    • g reload
  • global-smudge-remote-mode enables the mode line

See GitHub - danielfm/smudge: Control the Spotify app from within Emacs.

5.15. Frame

5.15.1. windmove   builtin

  • S-<arrow> change focus to different window

5.15.2. ace-window

  • M-o (ace-window)
    • m swap, M move (the buffer is rotated), x delete, j select new buffer for, n previous window
    • v vertical split, b horizontal split, o maximize
    • ? help
  • aw-dispatch-when-more-than variable prevents the ace window when less than 2 windows by default.
  • ace-window-display-mode display the window number in the mode line.

5.15.3. transpose-frame

;; `transpose-frame'  ...  Swap x-direction and y-direction
;;
;;        +------------+------------+      +----------------+--------+     
;;        |            |     B      |      |        A       |        |     
;;        |     A      +------------+      |                |        |     
;;        |            |     C      |  =>  +--------+-------+   D    |     
;;        +------------+------------+      |   B    |   C   |        |     
;;        |            D            |      |        |       |        |     
;;        +-------------------------+      +--------+-------+--------+     
;;     
;; `flip-frame'  ...  Flip vertically     
;;     
;;        +------------+------------+      +------------+------------+     
;;        |            |     B      |      |            D            |     
;;        |     A      +------------+      +------------+------------+     
;;        |            |     C      |  =>  |            |     C      |     
;;        +------------+------------+      |     A      +------------+     
;;        |            D            |      |            |     B      |     
;;        +-------------------------+      +------------+------------+     
;;     
;; `flop-frame'  ...  Flop horizontally     
;;     
;;        +------------+------------+      +------------+------------+     
;;        |            |     B      |      |     B      |            |     
;;        |     A      +------------+      +------------+     A      |     
;;        |            |     C      |  =>  |     C      |            |     
;;        +------------+------------+      +------------+------------+     
;;        |            D            |      |            D            |     
;;        +-------------------------+      +-------------------------+     
;;     
;; `rotate-frame'  ...  Rotate 180 degrees     
;;     
;;        +------------+------------+      +-------------------------+     
;;        |            |     B      |      |            D            |     
;;        |     A      +------------+      +------------+------------+     
;;        |            |     C      |  =>  |     C      |            |     
;;        +------------+------------+      +------------+     A      |     
;;        |            D            |      |     B      |            |     
;;        +-------------------------+      +------------+------------+     
;;     
;; `rotate-frame-clockwise'  ...  Rotate 90 degrees clockwise     
;;     
;;        +------------+------------+      +-------+-----------------+     
;;        |            |     B      |      |       |        A        |     
;;        |     A      +------------+      |       |                 |     
;;        |            |     C      |  =>  |   D   +--------+--------+     
;;        +------------+------------+      |       |   B    |   C    |     
;;        |            D            |      |       |        |        |     
;;        +-------------------------+      +-------+--------+--------+     
;;     
;; `rotate-frame-anticlockwise'  ...  Rotate 90 degrees anti-clockwise     
;;     
;;        +------------+------------+      +--------+--------+-------+     
;;        |            |     B      |      |   B    |   C    |       |     
;;        |     A      +------------+      |        |        |       |     
;;        |            |     C      |  =>  +--------+--------+   D   |     
;;        +------------+------------+      |        A        |       |     
;;        |            D            |      |                 |       |     
;;        +-------------------------+      +-----------------+-------+     
;;

5.16. Network

5.16.1. TRAMP   builtin

Transparent Remote Access, Multiple Protocol

Edit remote files transparently.

  • Use /ssh:HOST:PATH in the find-file (C-x C-f).
    • If the regular ssh stalls, /sshx:HOST:PATH might work
  • These filepaths can be used within the shell as well.
  • See TRAMP 2.7.1 User Manual

5.16.2. Mail

5.16.2.2. org-mime
  • org-mime-htmlize formats the Org mail into HTML.
5.16.2.3. gnus

Feature rich email, Unet, and RSS client

The method to generate the feed is specified in gnus-select-method. Additional sources can be added in gnus-secondary-select-methods.

5.16.2.3.1. Configurations

A group that look up a server can be set by

(gnus-select-method
 '(nnimap "personal"
            (nnimap-address "imap.gmail.com")
            (nnimap-server-port 993)
            (nnimap-stream tls)
            (nnimap-user "harryj.kim1122@gmail.com")))

gnus look up the password in the authinfo file (usually ~/.authinfo). A entry whose machine matches the group name (in this case personal) is used.

gnus is primarily focused on reading news articles. It assumes that every server is a news server, and stores the articles locally. There is no remote deletion, only the local file is deleted.

  • nnimap-expiry-* options deals with ho those deleted articles are treated.
  • gnus-search-* options specify how to search through the server. For an IMAP server, the default gnus-search-engine is gnus-search-imap. Before Emacs 28, it was the search system was called nnir.

In order to connect gmail account, app passwords has to be generated by your Google account. Search for App passwords in the search bar of Google account page.

Save those 16-character password in ~/.authinfo file. When you try to request via IMAP, the password will be used automatically.

The articles (mails) are displayed in a specified format. The default is %U%R%z%I%(%[%4L: %-23,23f%]%) %s\n, where

5.16.2.3.2. Keybindings
  • DEL or S-SPC previous page, < beginning, > end SPC next page, N and P next/previous article, n and p next/previous unread article
  • g show article, h go to article buffer, s search within the article
  • TAB open a mail
  • d, D mark as read and move forward/backward
  • o save article, C-o save article mail
  • ! tick forward, @ mark article
  • k kill, C-k kill same subject
  • c catchup and exit
  • r reply, f followup, m mail in new buffer
  • | shell command on article buffer
  • t toggle the full mail header
  • Group Mode
    • c catchup current
    • g get new news
  • Article Mode
    • C-d next keyword, TAB next link
    • s or h go to summary buffer
  • ^ Server Mode
    • u toggle subscription
    • l return to group buffer
5.16.2.4. Others
  • rmail
  • mu4e easy to use email client
  • mutt dated client
  • notmuch minimal client
    • Either offlineimap or mbsync is required to fetch emails.
  • ebdb stores and provides the contact information through autocompletion.

5.17. External

5.17.1. anki-editor

  • anki-editor-mode the commands are available when this mode is enabled.
    • anki-editor-push-notes to sync all the notes

5.17.2. org-anki

  • org-anki it is does almost the same thing as anki-editor

5.18. gtag

Use GNU global for indexing.

Other tag system includes ctags, etags

6. Configuration

  • Uses Lisp for the config file.
  • ~/.emacs, ~/.emacs.d/init.el, ~/.config/emacs/init.el

6.1. Compilation

  • The compilation options and available features for Emacs are given in
    • system-configuration-options and system-configuration-features

6.2. Custom   builtin

  • 'Easy Customization Interface' within the editor.
  • Variables and setting can be customized through this interface, and saved to the ~/.emacs
  • They are mostly accessible via M-x customize-*
  • Basic motions are possible: n, p, q

6.3. use-package

Init files are run before any of the package loads. add-hook is used to run commands after the packages load, with (add-hook 'HOOK_TIME #'HOOK_COMMAND).

  • after_init_hook
  • prog-mode-hook
  • image-mode-hook

Use package simply overrides the Customization, without modifying it.

use-package macro can configure the package.

  • :ensure install the package form the repository if not installed.
  • :preface run before anything else. This is for defining functions and variables.
  • :if conditional statement
  • :load-path custom load path for the package. Not usually used.
  • :after load after. :all, :any can be used alongside.
  • :defer t
  • :ensure t
  • :hook (((MODE*) . HOOK)*)
  • :bind ((KEY . FUN)*)
  • :bind-keymap the prefix for the keymap
  • :mode (REGEXP . MODE) add it to the auto-mode-alist
  • :init run now
  • :config run when the package loads
  • :custom (CUSTOM_VAR VAL "optional documentation")* customize package custom variables
  • :requires does not load the package unless the requirement is fulfilled.
  • Keywords — use-package for more
  • use-package-autoload-keymap bind a keymap

6.4. Initialization

6.4.1. Early Init

  • By default ~/.emacs.d/early-init.el is the early init file, and it runs before any of the packages load and the window is set up.
  • (setenv "VAR" "VALUE") set the environment variable
  • (setq native-comp-deferred-compilation nil) prevent native compilation

6.4.2. Init

  • ~/.emacs is used traditionally, but ~/.config/emacs/init.el and ~/.emacs.d/init.el can be used.
  • initial-scratch-message
  • inhibit-startup-screen
  • initial-buffer-choice sets the file as a startup buffer
  • emacs-startup-hook or window-setup-hook can also be hooked to any function
  • There's package called dashboard that modifies the startup screen into displaying recent files, org agendas, bookmarks and more.
  • default-frame-alist sets the properties for any frames.
    • The implicit default might not be applied to initial-buffer-choice. This option can be used in that case to set the properties explicitly.
  • See Startup Summary (GNU Emacs Lisp Reference Manual)

6.5. Theme

  • the emacs default themes are stored in /usr/share/emacs/NN.N/etc/themes/
  • The default directory for user themes is ~/.emacs.d/
  • Theme can be selected from customize-themes, or load-theme using lisp.
  • Emacs Themes Lookup

6.6. Input Method

Emacs has its own multilingual support. It translates the Latin characters into specified language.

  • default-input-method it specify the input method used when C-\ (toggle-input-method) is called.
    • korean-hangul, japanese
    • latin-prefix
    • german-postfix
      • It allows sz ß, ae ä, ue ü, oe ö.
    • compose
      • X like compose functionality!
      • C-x 8 works similarly, though much more limited

See Input Methods (GNU Emacs Manual)

  • set-input-method select a new input method
  • C-x \ (activate-transient-input-method) insert a single character
  • C-h C-\ (describe-input-method)

leim library for emacs input method: 2.3.1 Anthy

  • mozc Japanese input method. Requires emacs-mozc installed on the system

6.7. Keybinding

  • define-key the low level function
    • (define-key KEYMAP KEY nil) to unset
    • define-key works more reliably on initialization
  • global-set-key, local-set-key legacy interactive key definition
    • It expects the KEY to be a key description (kbd "...") or [...]
    • global-unset-key, local-unset-key
  • keymap-set, keymap-global-set, keymap-local-set keymap definition
    • It expects the KEY to pass key-valid-p test
    • keymap-unset, keymap-global-unset, keymap-local-set
  • bind-key the external function a bind-key package

Nested Keybinding (defvar-keymap NAME-map :doc DOC [KEY FUNCTION]+) sets a keymap which can be temporarily bound to a key by (keymap-set KEYMAP KEY KEYMAP). Note that the second KEYMAP should NOT be quoted.

6.8. Font

  • (set-fontset-font FONTSET CHARACTERS FONT-SPEC &optional FRAME ADD)
    • It does not work on server startup. It should be hooks to a server-after-make-frame-hook
    • Manipulate a fontset, with FONTSET being t meaning the fontset-default.
    • CHARACTERS specify on which set of characters the fonts is applied.
      • script-representative-chars and char-script-table contains the symbols for known scripts.
    • FONT-SPEC specifies which font to use for the given set of characters.
    • ADD can be either nil, 'prepend or 'append in terms of the precedence list
  • set-frame-font and set-face-attribute can also be used.
  • (font-spec SPECS)
    • :name, :family, :size, and others can be specified
  • (font . FONTNAME) is also seen
  • C-x = show the character at point in the minibuffer.
  • C-u C-x = show details about the character and font being used at point.

See Font Selection (GNU Emacs Lisp Reference Manual), Fonts (GNU Emacs Manual), Modifying Fontsets (GNU Emacs Manual)

7. Emacs Lisp

See Elisp

8. CLI

  • Command Line Interface
  • emacs
    • --debug-init run debug on init files
    • -t, --terminal use TUI
    • -f, --funcall execute Lisp function
    • -l, --load Load Lisp code file
    • --eval, --execute Evaluate Lisp expression
    • -batch, --batch run noninteractively within the terminal
    • -q do not load the init file .emacs or .emacs.d/init.el
    • --load FILE
    • --init-directory PATH change the user-emacs-directory and package-user-dir
    • --daemon run as a server
  • emacsclient
    • -t terminal session
    • --alternative= use specified Eamcs server, when no server is specified and no server running new server is created.
    • --create-frame

9. Security

9.1. EasyPG

  • epg

The interface for GPG.

It has wrapper called EasyPG Assistant (epa), which is used for .authinfo.gpg. These packages come with Emacs builtin.

For local encryption, symmetric encryption with AES (or other algorithm defined by cipher-algo in GPG) is performed on the file with a key created from the user-provided passphrase by S2K (string-to-key) algorithm in GPG.

10. Distributions

10.1. Emacs Prelude

Enhanced Emacs with ace-window, magit, avy, crux, and other packages preinstalled.

10.2. Doom Emacs

One can choose whether to use Evil or not. It uses <space> in Evil mode and C-c if not.

Various components are available as packages.

  • doom-modeline
  • doom-thems

10.3. Spacemacs

It uses <space> as the leader key, and use mnemonic keybindings.

11. Help

  • C-h ... for helps
    • ?, C-h show options
    • C-q quick help for basic macros
    • b current key bindings
      • k c key (briefly)
    • m current mode
    • a commands for <M-x>
    • d documentation
    • f, v, o function, variables, both
      • kill-ring is also a variable
    • r Emacs manual
      • F K for command or key sequence
      • i all installed manual, info
      • R specific manual
    • P Package description
  • M-x shortdoc show the summery for a topic
  • C-h can be entered in the middle of prefix. It shows the available keybindings.

The default value for the help message the text at point.

12. History

Editor descended from all the way to the 1970s

  • Theming mechanism was added in version 24

13. Reference

Author: Jeemin Kim

Created: 2026-07-12 Sun 14:28