Emacs Reference
Kip Landergren
(Updated: )
My cheat sheet for emacs covering macOS installation, common keyboard shortcuts, and usage of dired, web-mode, and magit.
Contents#
- Installation
- Configuration
- General
- Documentation Lookup
- Common Operations
-
Internal Packages
- autorevert.el
- bookmark.el
- cc-mode
- compile.el
- Dired
- Eglot (eglot.el)
- emacs-news-mode
- eww.el
- files.el
- Flymake
- Flyspell (flyspell.el)
- ibuffer
- ido
- Ispell (ispell.el)
- man
- package.el
- project.el
- Rectangles
- regexp
- replace.el
- shell.el
- sort.el
- transient
- Themes
- Tree-sitter
- use-package
- window.el
-
External Packages
- apheleia
- Cond-Let
- Consult
- command-log-mode
- csv-mode
- Embark
- envrc
- geiser-guile
- Ghostel
- gptel
- helm
- js-mode
- lsp-mode
- magit (magit.el)
- markdown-mode
- multiple-cursors.el
- orderless
- Org
- prettier-js
- projectile (projectile.el)
- scheme-mode
- sqlformat
- vertico
- vterm
- web-mode
- wgrep
- yasnippet
- xref
- Custom Behavior
- Emacs Lisp (elisp)
- Frequently Asked Questions (FAQs)
- Terminology
- Resources
Installation#
For macOS, using d12frosted/homebrew-emacs-plus:
$ brew tap d12frosted/emacs-plus
$ brew install emacs-plus@30 --with-native-comp
And follow the instructions after install to create an alias.
Previously, I have downloaded the appropriate build from Emacs For Mac OS X: Releases, Pretests & Nightlies. Builds are also available from jimeh/emacs-builds.
Configuration#
Organization Within use-package Declarations#
For a major mode major and minor mode minor:
(use-package minor ...)should contain:- configuration for its behavior in all modes
(use-package major ...)should contain:- configuration for
major’s behavior - configuration for
minor’s behavior inmajor
- configuration for
Think carefully before using :hook to add functions to other modes / packages.
Especially do not fall into the trap of:
(use-package bar
:defer t)
(use-package foo
;; adds `bar-mode` to `foo-mode-hook`
:hook (foo-mode . bar-mode))
As :hook will, as I understand it, ensure an autoload is set up for bar-mode thinking it is provided by foo.
The correct use of :hook, and valid alternative, but not organizationally aligned with how I think, is:
(use-package bar
;; adds `bar-mode` to `foo-mode-hook`, but
;; is within the `bar` declaration, which
;; for me is confusing
:hook foo-mode)
(use-package foo
:defer t)
Instead, my preference is:
- if not autoloaded, declare the function within
:commands - use
add-hookwithin the other package’s:configdeclaration (or wherever appropriate)- additionally, using
add-hookalso allows you to control whether to modify the hook’s buffer-local or global value
- additionally, using
An example preferred configuration:
(use-package bar
;; only necessary if not autoloaded
:commands bar-mode)
(use-package foo
:defer t
:config
(add-hook ‘foo-mode-hook #'bar-mode))
EmacsLisp Preferences#
- turn on / off modes with explicit
(foo-mode +1)or(foo-mode -1) - wrap any
:initor:configin(progn ...)to allow easier invocation - prefer named functions over lambdas in hooks; this allows for easier debugging and reevaluation when its contents change
Globally Enabled Minor Modes#
Prefer:
(use-package minor
:demand t
:config
(progn
(minor-mode +1)))
over:
(use-package minor
:init
(minor-mode))
Because 1) I can understand this code without knowing how autoload works and 2) the former reads more how I think:
:demandto explicitly load the package:configto invoke it once loading is completed
Vs. the latter:
:initto execute code before the package is loaded- hope that
autoloadonminor-modeis configured correctly - invoke
minor-mode, forcing an immediate load (possibly of the entire package?)
I do not yet know Emacs Lisp well enough to determine how autoload affects package loading. Possibly the entire package is loaded? or just the autoloaded function implementation?
For example, radian-software/apheleia’s User guide indicates that:
The autoloading has been configured so that this will not cause Apheleia to be loaded until you save a file.
Which is contrary to my understanding that the entire package would be loaded once an autoloaded function is invoked. Therefore, for now, I am willing to trade the performance hit of :demand for the understanding of configuration behavior.
General#
This document’s key chords are represented in emacs’ short-form style where a modifier key starts and a normal key follows. When a normal key is capitalized it implies using ⇧ Shift.
Modifier key / abbreviations legend:
| C- | ⌃ Control + |
| M- | ⌥ Option + |
| s- | ⌘ Command + |
| S- | ⇧ Shift + |
| <DOWN> | ↓ |
| <UP> | ↑ |
| <LEFT> | ← |
| <RIGHT> | → |
| <PageDown> | ⇟ Page Down |
| <PageUp> | ⇞ Page Up |
| <DEL> | ⌫ Backspace |
| <ESC> | ⎋ Esc |
| <RET> | ↵ Return |
| <SPC> | SPACE |
| <TAB> | ↹ Tab |
Default Prefix Keys#
| C-c |
| C-h |
| C-x |
| C-x <RET> |
| C-x @ |
| C-x a |
| C-x n |
| C-x r |
| C-x t |
| C-x v |
| C-x 4 |
| C-x 5 |
| C-x 6 |
| <ESC> |
| M-g |
Commands#
| C-f | forward one character | |
| C-b | backward one character | |
| M-f | forward one word | |
| M-b | backward one word | |
| M-e | forward one sentence | |
| M-a | backward one sentence | |
| C-x ] | forward-page |
|
| C-x [ | backward-page |
|
| C-e | move to end of line | |
| C-a | move to beginning of line | |
| M-m | back-to-indentation |
|
| C-_ | undo | |
| C-d | delete one character | |
| M-d | delete one word | |
| C-x o | other-window |
|
| C-x ^ | enlarge-window |
make taller |
| C-x { | shrink-window-horizontally |
make narrower |
| C-x } | enlarge-window-horizontally |
make wider |
| C-x 0 | delete-window |
|
| C-x 1 | delete-other-windows |
|
| C-x + | balance-windows |
distribute width and height to fit |
| C-l | scroll window so that current line is at middle, top, or bottom | |
| M-r | position cursor according to recenter-positions |
|
| C-k | kill-line |
from point to end of line |
| C-S-<DEL> | kill-whole-line |
|
| C-y | yank |
aka paste |
| M-y | yank-pop |
to select different killed text from kill ring |
| C-y M-y (M-y ... M-y) | successive calls to yank-pop replaces the yanked text with previous entries from the kill ring |
|
| M-g g | goto line | |
| C-c C-w | web-mode-whitespaces-show |
toggle whitespace (web-mode only!) |
| s-=, and then follow prompts | adjust text scale (zoom in / zoom out / zoom text / increase font size) | |
| M-; | comment / uncomment | |
| M-x load-file | load file (use to reload configuration) | |
| M-: | eval-expression |
evaluate elisp expression |
| C-x C-e | eval-last-sexp |
evaluate sexp before point |
| M-| | execute shell command | |
| C-g | quit; toggle undo / redo | |
| C-h l | view-lossage |
display last lossage-size characters typed |
| C-n | next-line |
move down one screen line |
| C-p | previous-line |
move up one screen line |
| C-v | scroll forward; page down | |
| M-v | scroll backward; page up | |
| C-<SPC> | set-mark-command |
set mark and activate region |
| C-u C-<SPC> | move to previous mark (jump back to previous position) | |
| C-x C-x | exchange-point-and-mark |
|
| C-q C-j | newline (useful in minibuffer) | |
| C-x x r | rename-buffer |
|
| C-x x u | rename-uniquely |
often appends digit |
| s-+ | zoom in / increase font size | |
| s-- | zoom out / increase font size | |
| C-x C-v | find alternate file | |
| C-x x t | toggle-truncate-lines |
toggle line wrap / disable line wrap |
| C-u 1 M-x FUNCTION | add the prefix argument 1 to the call to FUNCTION | |
| C-q CHARACTER | quote CHARACTER | |
| C-o | open-line |
insert a blank line after the cursor |
| C-x C-o | delete-blank-lines |
delete all but one of many consecutive blank lines |
| C-x n n | narrow-to-region |
|
| C-x n w | widen |
|
| s-u | revert-buffer |
|
| C-x z | repeat |
|
| C-x <TAB> | indent-rigidly |
indent all lines starting in the region; shift region; shift indent |
Debugging#
| M-x toggle-debug-on-quit | useful if something hangs: C-g will enter the debugger and you can inspect what is going on at the time (a misbehaving LSP server, perhaps?) |
Documentation Lookup#
When in doubt, read the manual:
| C-h r | info-emacs-manual |
displays the Emacs manual in Info |
Commands#
Prefer C-h o (describe-symbol) as you may be wrong about whether it is a function or variable.
Type C-h after any prefix key to view what other keys may be completed.
Manuals
| C-h i | info |
enter Info, the documentation browser; show all installed manuals |
| C-h r | info-emacs-manual |
displays the Emacs manual in Info |
| C-h R | (info-display-manual MANUAL) |
displays an Info buffer displaying MANUAL |
| M-x man | runs the man program, prompting for a topic to search for |
General
| C-h k | describe-key |
displays documentation for the function invoked by the key presses (defaults to current buffer) |
| C-h o | describe-symbol |
displays documentation for the passed symbol |
| C-h f | describe-function |
displays documentation for the passed function |
| C-h v | describe-variable |
displays documentation for the passed variable |
| C-h e | view-echo-area-messages |
displays the *Messages* buffer |
| C-h a PATTERN | apropos-command |
shows commands that match PATTERN |
| C-h m | describe-mode |
displays documentation of current major and minor modes |
| C-h b | describe-bindings |
displays a buffer showing a list of all defined keys, and their definitions |
| C-h t | help-with-tutorial |
|
| C-h C-f | view-emacs-FAQ |
|
| C-h n | view-emacs-news |
|
| C-h w COMMAND | where-is |
show which keys run COMMAND |
| C-h P | describe-package |
displays documentation for the passed package |
| C-h . | display-local-help |
|
| M-x describe-keymap KEYMAP | describes the key bindings in KEYMAP | |
| M-x describe-char | describes the char at point | |
| M-x describe-text-properties | describes the text properties at point |
help-mode#
| C-c C-b | help-go-back |
|
| C-c C-f | help-go-forward |
|
| <SPC> | scroll-down-command |
navigate to next node if at bottom (regardless of level) |
| <DEL> | scroll-up-command |
navigate to previous node if at top (regardless of level) |
| <TAB> | forward-button |
move cursor to next cross reference or menu item |
info-mode#
Think of Info as a hypertext system with:
- a branching hierarchy of parent and sub nodes
- linear (depth-first) navigation
- non-linear navigation:
- up to ancestor
- down via menus
- across siblings
- across any two nodes via cross references
General#
| q | quit |
| ? | (Info-summary); show Info Help |
| h | invoke the Info tutorial |
| C-h R info | open the Info manual |
Scrolling Nodes#
| <SPC> | scroll down; navigate to next node if at bottom (regardless of level) | |
| <DEL> | scroll up; navigate to previous node if at top (regardless of level) | |
| <PageDown> | scroll down; does not navigate to next node | |
| <PageUp> | scroll up; does not navigate to previous node | |
| e | scroll to end | |
| b | scroll to beginning | |
| C-l | recenter-top-bottom |
|
| <TAB> | move cursor to next cross reference or menu item |
Navigating Node Trees#
Linearly#
| ] | Info-forward-node |
next node (regardless of level) |
| [ | Info-backward-node |
previous node (regardless of level) |
Vertically#
| u | up (ascend one level) | |
| m | pick menu item (selective descent) | |
| 1...9 | navigate to the ith menu item | |
| t | Info-top-node |
top of manual |
| > | Info-final-node |
final node of manual |
| d | directory |
Horizontally#
| n | next node (at level) |
| p | previous node (at level) |
Laterally#
| f | follow a cross reference |
| i | pick index item |
| g | go to node by name |
Temporally#
| l | last node in history (i.e. browser back button) |
| r | revisit node in history (i.e. browser forward button) |
| L | view history |
Finding Information#
| I | search virtual index item | |
| s | search | |
| C-s | isearch-forward |
searches across nodes if invoked multiple times |
| C-r | isearch-backward |
searches across nodes if invoked multiple times |
| M-x info-apropos | search indices of all known Info files |
Working Within Emacs#
| M-n | clone-buffer |
create a new independent Info buffer |
| C-u m | create a new independent Info buffer from menu selection | |
| C-u g | create a new independent Info buffer from go-to-node selection | |
| C-u C-h R | show a pick list of open manuals by their names |
Common Operations#
Finding Documentation When You Know the Manual#
I want to find information on magit-clone within the magit manual:
| C-h R magit | |
| I | Info-virtual-index |
| magit-clone | |
| <RET> |
Finding Documentation When You Don’t Know the Manual#
I want to find information on clone but I’m not sure where:
| M-x info-apropos |
| clone |
| <RET> |
Switching Between Many Open Info Buffers#
Handy when you have many *info*, *info<2>*, etc buffers:
| C-u C-h R | shows a pick list of open manuals by their names |
Frequently Asked Questions (FAQs)#
Why are some asterisks in menu items colored differently than their peers?#
These are the 3rd, 6th, and 9th items of a menu list and allow for visual distinction for easy access via their corresponding numeric keys.
From 2.4 ‘1’–‘9’ choose a menu subtopic by its number of the Info manual:
If your display supports multiple fonts, colors or underlining, and you are using Emacs’s Info mode to read Info files, the third, sixth and ninth menu items have a ‘*’ that stands out, either in color or in some other attribute, such as underline; this makes it easy to see at a glance which number to use for an item.
How was this Info file authored?#
Info files are often generated from source .texinfo files via makeinfo.
How do I find the corresponding Info file for the node I am visiting?#
| M-: Info-current-file | evaluate variable Info-current-file |
Common Operations#
n Column Layout#
| C-x 3 | split vertically (repeat n - 1 times) | |
| C-x + | balance-windows |
distribute width and height to fit |
Frame Management#
On Mac OS, a new frame (note: not a “new window” in emacs parlance) will be created using native windowing.
| C-x 5 2 | create new frame |
| C-x 5 0 | delete selected frame |
Figuring Out What Went Wrong#
Sometimes mistyped key combinations result in unexpected behavior. To help figure out what went wrong, consider:
- C-h l, or
view-lossage, which shows the last 300 characters typed list-command-history, which shows every command involving the minibuffer- an add-on like
command-log-mode
ansi-term#
ansi-term runs in character mode by default, making the buffer read-only. Switching to line mode allows copy and pasting to work more naturally.
| C-c C-j | enter line mode | |
| C-c C-k | enter character mode | |
| C-x x r | rename-buffer |
Reload init.el and apply changes to open buffers#
| make modifications to init.el | |
| M-x load-file | reload file |
| M-x ibuffer | open ibuffer |
| / f | (optional) filter buffers by filename regexp |
| m with cursor on [ Default ] | (optional) mark all filtered buffers |
| V | revert all buffers (ensure saved!) |
Remove Carriage Returns (^M)#
file-coding-system| open buffer | ||
| C-x <RET> f | set-buffer-file-coding-system |
|
| select utf-8-unix or other appropriate value | ||
| save buffer |
This emacs.stackexchange.com answer explaining line endings is very helpful.
edit file as root#
Prepend /sudo:: before a path, like when finding a file.
Record Keyboard Macro#
| C-x ( | start recording |
| perform the keystrokes / operations | |
| C-x ) | end recording |
| M-0 C-x e | repeat macro until an error |
| C-x C-k n | name the macro / save the macro |
| C-u 3 M-x NAME | repeatedly execute macro NAME 3 times |
| open init.el and run: M-x insert-kbd-macro | save the macro for the future |
| C-x C-k e | edit macro kbd-edit-macro |
Notes:
- macros are not scoped to a specific buffer—they perform keystrokes just as you would
- error “terminated by a command ringing the bell” likely means a command went wrong during the running of the macro
Byte Recompile#
| find . -name "*.elc" -type f -delete | delete all compiled elisp files |
| M-: | eval |
(byte-recompile-directory package-user-dir 0 'force) |
byte recompile all packages |
Scroll#
| M-r (repeat as needed) | position point cycling through recenter-positions |
| C-l (repeat as needed) | scroll window |
Counting Words#
count-words |
also counts lines, sentences, words, and characters | |
| M-= | count-words-region |
also counts lines, sentences, words, and characters |
Internal Packages#
autorevert.el#
auto-revert-mode |
function | Toggle reverting buffer when the file changes |
auto-revert-verbose |
variable | controls messages when a buffer is reverted |
Frequently Asked Questions (FAQs)#
How do I get emacs to follow a file?#
Toggle auto-revert-mode.
bookmark.el#
Named locations with optional annotations describing the bookmarks.
| C-x r m <RET> | set bookmark at point | |
| C-x r m BOOKMARK <RET> | set bookmark named BOOKMARK at point | |
| C-x r b BOOKMARK | jump to BOOKMARK | |
| C-x r l | list-bookmarks |
bookmark-bmenu-mode#
Marking#
Like dired, but marking is for displaying bookmarks, not all operations.
| m | mark (to be displayed) |
| u | unmark |
| M | Mark all (to be displayed) |
| U | Unmark all |
| d | mark for deletion |
| D | mark all to be Deleted |
Editing#
| x | eXpunge; delete marked bookmarks |
| <RET> | select in place of bookmark menu buffer |
| r | rename |
Display#
| t | toggle displaying filenames |
cc-mode#
| C-h R ccmode | open the info manual on cc-mode |
|
| C-c C-w | subword-mode |
Subwords#
example:
| nomenclature | subwords |
|---|---|
| GtkWindow | Gtk and Window |
equivalent commands:
forward-word |
c-forward-subword |
backward-word |
c-backward-subword |
Frequently Asked Questions (FAQs)#
Why is cc-mode displayed as C/*l in the mode line?#
It is a reference to the enabled minor modes and state of CC Mode:
| C | c-mode, for the C programming language |
| /* | block comment style |
| l | electric mode |
Reference:
| // | line comment style |
| /* | block comment style |
| l | electric mode |
| a | auto-newline mode |
| h | hungry delete mode |
| w | subword mode |
Examples:
| C//l | C mode, line comment style, electric mode |
| C/*lahw | C mode, block comment style, all other modes enabled |
Refer to section “4.5 Minor Modes” of the ccmode Info manual for more.
compile.el#
Commands#
| M-x compile | compile the program including the current buffer |
Variables#
compile-command |
Dired#
Summary#
dired is a mode for editing directory listings. It takes the output of the system’s GNU ls command (or, if not available, emulation through ls-lisp.el) and presents it in a read-only buffer for interaction.
Commands#
General#
| C-x d | open dired |
|
| C-h m | describe mode; help | |
| ? | summary | |
| ( | dired-hide-details-mode |
a minor mode which is toggled on invocation |
| g | revert-buffer |
?? get ?? (assumed due to similarity with Gnus); refresh |
| s | dired-sort-toggle-or-edit |
sort |
Marking#
| m | mark | |
| u | unmark | |
| U | Unmark all | |
| d | mark for deletion | |
| t | toggle marks | |
| % m | dired-mark-files-regexp |
mark by pattern; filter |
Visiting#
| a | dired-find-alternate-file |
alternate file |
| f | dired-find-file |
find file |
| F | dired-do-find-marked-files |
Find marked files |
Operations#
| C | Copy | |
| R | Rename | |
| D | Delete | |
| S | Symlink | |
| x | dired-do-flagged-delete |
eXpunge |
| Q | dired-do-find-regexp-and-replace |
|
| M | dired-do-chmod |
accepts input like +x or 644; make executable |
| w | dired-copy-filename-as-kill |
copy names of marked files into the kill ring |
Common Operations#
Bulk Edit Directoy#
| C-x d | dired |
enter dired |
| C-x C-q | dired-toggle-read-only |
enter editing mode |
| perform edits | ||
| C-c C-c | apply changes | |
| C-c <ESC> | or cancel |
Find and Replace Text Across Files#
| C-x d | enter dired |
| m | mark files to search |
| Q | run find and replace on marked files |
| entire regexp and replacement | |
| ? | choose whether to replace / exit / do something else |
Copy Filenames#
| m | mark files whose names to copy | |
| w | dired-copy-filename-as-kill |
copied filenames are separated by a space |
Resources#
- GNU Emacs Manual, Dired (single page)
- Dired Reference Card (PDF)
Eglot (eglot.el)#
Variables#
eglot-server-programs |
alist of (MAJOR-MODE . CONTACT) where CONTACT specifies how to connect to a language server |
eglot-autoshutdown |
when non-nil, will automatically shut down |
eglot-workspace-configuration |
Hooks#
eglot-connect-hook |
run after Eglot connects to a language server for the first time |
eglot-managed-mode-hook |
run by Eglot after it started/stopped managing a buffer; useful for use with flymake-related functionality |
Functions#
eglot-code-action-extract |
|
eglot-code-action-inline |
|
eglot-code-action-organize-imports |
|
eglot-code-action-quickfix |
execute quickfix code actions |
eglot-code-action-rewrite |
|
eglot-code-actions |
find LSP code actions |
eglot-ensure |
|
eglot-find-implementation |
find implementation of SYM |
eglot-format |
|
eglot-inlay-hints-mode |
|
eglot-rename |
|
eglot-show-workspace-configuration |
|
eglot-shutdown |
|
eglot-signal-didChangeConfiguration |
Common Operations#
Iterating on LSP Workspace Configuration#
| edit .dir-locals.el per 5.1 Project-specific configuration | |
| M-x eglot-show-workspace-configuration | inspect the configuration |
| not what you wanted? go back to the beginning. otherwise continue. | |
| M-x eglot-signal-didChangeConfiguration | notify the language server of the new configuration |
Getting completions.completeFuncCalls=true to Work With typescript-language-server#
Create a .dir-locals.el at the root of your project:
((tsx-ts-mode
. ((eglot-workspace-configuration
. (:completions
(:completeFunctionCalls t))))))
It seems like typescript-language-server appears to not want completions.completeFuncCalls to be scoped to typescript-language-server. I do not know if this is expected behavior or a bug.
Getting usePlaceHolders to Work With gopls in go-ts-mode#
Create a .dir-locals.el at the root of your project:
;; intentionally use `go-mode` rather than `go-ts-mode` because otherwise
;; eglot fails to find the workspace configuration
((go-mode
. ((eglot-workspace-configuration
. (:gopls (:usePlaceholders t))))))
Getting flymake-eslint to Work With eglot#
The key is to use the helpful eglot-managed-mode-hook so that Eglot has a chance to make its changes to flymake before any others.
(defun kl/ts-eglot-managed-mode-hook ()
(if (eglot-managed-p)
(flymake-eslint-enable)))
(add-hook 'eglot-managed-mode-hook #'kl/ts-eglot-managed-mode-hook)
Frequently Asked Questions (FAQs)#
Does Eglot support more than one LSP server per major mode?#
Not to my knowledge. You are able to define alternative LSP servers via eglot-alternatives but not connect to multiple concurrently.
emacs-news-mode#
| C-c C-b | outline-backward-same-level |
| C-c C-f | outline-forward-same-level |
eww.el#
| M-I | eww-toggle-images |
toggle whether images are displayed |
files.el#
| C-x C-v | find-alternate-file |
Frequently Asked Questions (FAQs)#
How do I reload a buffer to pick up changes I made in my init.el file?#
Use find-alternate-file and specify the same filename.
Flymake#
flymake-show-buffer-diagnostics |
show a list of Flymake diagnostics for current buffer |
flymake-show-project-diagnostics |
Frequently Asked Questions (FAQs)#
How can I copy the Flymake diagnostic message from the minibuffer?#
- M-x flymake-show-buffer-diagnostics
Flyspell (flyspell.el)#
| C-, | flyspell-goto-next-error |
| C-c $ | flyspell-correct-word-before-point |
ibuffer#
Mode for listing, sorting, filtering, and managing open buffers:
| M-x ibuffer | enter ibuffer |
| ? | display help |
| m | mark buffer at point |
| u | unmark buffer at point |
| V | revert all marked buffers |
| U | unmark all marked buffers |
| / C-h | show filter help |
| / f | filter buffers by filename regexp |
| / / | remove all filtering currently in effect (remove all filters) |
ido#
Frequently Asked Questions (FAQs)#
How do I use ido to open multiple files at once?#
I have not found a way to do so using just ido. Here is what I have found to work, using helm and helm-projectile:
| M-x helm-projectile | |
| M-a | select all |
| <RET> | open all |
Ispell (ispell.el)#
ispell-buffer |
spell check the buffer |
man#
Frequently Asked Questions (FAQs)#
Why aren’t nix’s man pages found in emacs?#
First check if they were even installed correctly.
On macOS I noticed:
% man -k nix
makewhatis: /Users/klandergren/.nix-profile/share/man: Not a directory
makewhatis: /Users/klandergren/.nix-profile/share/man: Not a directory
Which turned out to be because it is not following symlinks.
So then some .zshenv wrangling:
nix_user_man=$(readlink "$HOME/.nix-profile/share/man" 2>/dev/null)
nix_default_man=$(readlink /nix/var/nix/profiles/default/share/man 2>/dev/null)
export MANPATH="${nix_user_man}:${nix_default_man}:$(manpath 2>/dev/null)"
unset nix_user_man nix_default_man
Then check $MANPATH:
(getenv "MANPATH")
Which in my case I needed to inject (excerpt from my init file—add where appropriate to yours):
;; Pull MANPATH from a login zsh so `M-x man` finds nix man pages.
;; emacs-plus snapshots PATH at install time and MANPATH is not pulled
;; dynamically. also: macOS's manpath derivation doesn't follow nix's
;; symlinks.
(defun kl/sync-manpath-from-shell ()
"Set MANPATH from a login zsh, so Emacs sees the same man pages as the terminal."
(let ((shell-manpath
(ignore-errors
(string-trim
(shell-command-to-string
"/bin/zsh -lc 'echo -n $MANPATH'")))))
(when (and shell-manpath (not (string-empty-p shell-manpath)))
(setenv "MANPATH" shell-manpath))))
(kl/sync-manpath-from-shell)
and now M-x man returns nix-* man pages.
package.el#
For use with MELPA or others.
Functions#
list-packages |
display a list of packages (package-list-packages is an alias) |
|
| C-h P | describe-package |
display documentation of PACKAGE |
package-refresh-contents |
download descriptions of all latest versions of pacakges |
Commands#
| x | two behaviors: package under point not installed: install it; already installed: delete it |
| i | mark package for installation |
| d | mark package for deletion |
| / / | package-menu-clear-filter |
| / s | package-menu-filter-status |
| / u | package-menu-filter-upgradable |
| <RET> on PACKAGE | describe-package |
Frequently Asked Questions (FAQs)#
How to view which package requires a package marked as dependency?#
| M-x describe-package | display documentation for PACKAGE |
| PACKAGE | enter PACKAGE name |
| view Required by: |
project.el#
Commands#
| C-x p k | project-kill-buffers |
kill the buffers belonging to the current project; close all project buffers |
| C-x p b | project-switch-to-buffer |
switch to project buffer |
| C-x p C-b | project-list-buffers |
display a *Buffer List* of project buffers |
| C-x p D | project-dired |
start dired in current project root |
project-forget-project |
remove directory PROJECT-ROOT from the project list |
Rectangles#
Commands#
There is symmetry with normal operations, just with a C-x r prefix key.
| C-x <SPC> | rectangle-mark-mode |
|
| C-t | string-rectangle |
|
| C-x r k | kill-rectangle |
|
| C-x r M-w | copy-rectangle-as-kill |
|
| C-x r d | delete-rectangle |
|
| C-x r y | yank-rectangle |
|
| C-x r o | open-rectangle |
think of this as “opening up” a rectangle of blank space where you want it |
| C-x r c | clear-rectangle |
|
| C-x C-x | rectangle-exchange-point-and-mark |
Common Operations#
Move#
Think of it this way:
- create a rectangle in mark mode where you want blank space to be
- “open up” the area (by shifting current contents to the rightmost edge of the rectangle)
| C-x <SPC> | rectangle-mark-mode |
|
| C-n / C-p | move mark to create rectangle height | |
| C-f / C-b | move mark to create rectangle width | |
| C-x r o | open-rectangle |
Insert Text Via Rectangle#
| C-x <SPC> | rectangle-mark-mode |
|
| C-n / C-p | move mark to create rectangle | |
| C-t | string-rectangle |
|
| enter desired text |
Copy and Paste Rectangle Text#
| C-x <SPC> | rectangle-mark-mode |
|
| C-n / C-p | move mark to create rectangle | |
| C-x r M-w | copy-rectangle-as-kill |
|
| move mark to desired location | ||
| C-x r y | yank-rectangle |
regexp#
Consider toggling whitespace-mode to better see which whitespace characters are present.
Commands#
| C-M-s | isearch-forward-regexp |
replace-regexp |
|
flush-lines |
|
keep-lines |
Reference#
^ |
beginning of line |
$ |
end of line |
. |
every character except the newline |
[SET] |
the set of characters within the brackets |
[^SET] |
exclude the set of characters within the brackets |
| |
either |
\\(GROUP\\) |
match GROUP |
\1 |
refer to matched group 1 |
\2 |
refer to matched group 2 |
\N |
refer to matched group N |
\& |
?? refer to all matches ?? |
\,(FUNCTION) |
run elisp FUNCTION on group |
postfix operators (greedy by default; made non-greedy by additional ?)
? |
match previous zero or one time |
+ |
match previous one or more times |
* |
match previous zero or any times |
Cookbook#
^[[:space:]]*^J |
replace blank lines |
[a-z] |
all lower case alphabetical letters |
[A-Za-z] |
all upper or lower case alphabetical letters |
[0-9] |
the digits 0 through 9 |
Frequently Asked Questions (FAQs)#
Regexp or Regex?#
From the Emacs manual:
A “regular expression” (or “regexp” for short) ...
Preferred personal usage:
“regexp” when working in the context of emacs, JavaScript, or ruby; “regex” everywhere else
replace.el#
replace-regexp |
Frequently Asked Questions (FAQs)#
How do I scroll through my match history?#
Preferred:
| M-p | comint-previous-input |
| M-n | comint-next-input |
Alternative:
| <UP> | previous-line-or-history-element |
| <DOWN> | next-line-or-history-element |
shell.el#
I now use Ghostel.
| M-x shell | run an inferior shell in BUFFER (defaults to *shell*) | |
| C-u M-x shell | run an inferior shell, prompting for BUFFER | |
| M-p | comint-previous-input |
|
| M-n | comint-next-input |
|
| M-r | comint-history-isearch-backward-regexp |
equivalent of zsh ⌃ Control + r to search command history |
| C-c C-u | comint-kill-input |
|
| C-c C-c | comint-interrupt-subjob |
roughly equivalent behavior to ⌃ Control + c in a terminal |
sort.el#
Frequently Asked Questions (FAQs)#
How do I sort by the nth field?#
| select region | |
| C-u NUMBER M-x sort-fields | invoke sort-fields with a prefix argument followed by the NUMBER corresponding to that column |
transient#
Implements keyboard-driven menus (including those in Magit). Successor to Magit-Popup.
This is a built-in package that is also distributed as a separate package so that it can be used by others.
Cookbook#
C-h R transient |
display the Transient manual |
Frequently Asked Questions (FAQs)#
How do I copy text from a transient popup?#
Tested with version 20260926.1400.
Via mouse:
| drag and select text with the mouse | |
| C-g | dismiss the transient popup |
| middle click to paste |
Via keyboard, add:
(keymap-set transient-map
"C-c C-w"
#'transient-copy-menu-text)
| C-c C-w | transient-copy-menu-text |
|
| C-g | exit popup | |
| C-y | yank like normal |
Resources#
- magit/transient GitHub repository
- magit/transient/wiki GitHub wiki
- positron-solutions/transient-showcase GitHub repository
Themes#
Frequently Asked Questions (FAQs)#
How do I tell what the current theme is?#
| C-h o | describe-symbol |
| custom-enabled-themes <RET> |
Tree-sitter#
Variables#
treesit-language-source-alist |
configuration for downloading and installing tree-sitter language grammars |
Functions#
treesit-install-language-grammar |
build and install treesit grammar for LANG, based on values in treesit-language-source-alist |
treesit-available-p |
return non-nil if tree-sitter support is built-in and available |
treesit-language-available-p |
return non-nil if LANG exists and is loadable |
(treesit-library-abi-version &optional MIN-COMPATIBLE) |
return the language ABI version |
(treesit-language-abi-version &optional LANGUAGE) |
return the tree-sitter grammar ABI version for LANGUAGE |
Example configuration#
As of Emacs 31.1 I no longer use this configuration and use the default grammars defined by Emacs.
(use-package treesit
:defer t
;; nb: this is in :init and not :custom because treesit.el uses defvar, and
;; we want to be able to install treesit grammars before anything is
;; loaded. idk reasoning behind defcustom vs defvar
:init
(setq treesit-language-source-alist
'((css . ("https://github.com/tree-sitter/tree-sitter-css" "v0.23.2"))
(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.23.2" "typescript/src"))
(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.23.2" "tsx/src"))
(go . ("https://github.com/tree-sitter/tree-sitter-go" "v0.23.4"))
(gomod . ("https://github.com/camdencheek/tree-sitter-go-mod" "v1.1.0"))
(javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.1"))
(c . ("https://github.com/tree-sitter/tree-sitter-c" "v0.23.6"))
(cpp . ("https://github.com/tree-sitter/tree-sitter-cpp" "v0.22.3")))))
Frequently Asked Questions (FAQs)#
How do I know which grammar version to install?#
version-mismatch?As of Emacs 31.1 I have defaulted to using the grammars defined by Emacs.
If you have installed a grammar of an incompatible version, removed it, and attempted to install a compatible version you may still get errors. I don’t know exactly why but suspect emacs is keeping some reference to the .dylib even when a new one is installed. I was able to work around by removing the incompatible .dylib, quitting and reopening emacs, and installing the correct grammar.
Mismatched versions may result in warnings like:
⛔ Warning (treesit): Cannot activate tree-sitter, because language grammar for c is unavailable (version-mismatch): 15
To resolve, install a grammar with the same ABI version as the treesit library:
| M-: | eval-expression |
| (treesit-library-abi-version) | should return an integer, like 14 |
| (treesit-language-abi-version 'LANG) | hopefully returns the same version for LANG |
If you have access to the source code of the grammar check src/parser.c and look for LANGUAGE_VERSION, e.g.:
#define LANGUAGE_VERSION 14
Some more info in this reddit thread.
use-package#
Using :mode Effectively#
- regexps match against absolute paths
examples:
"\\\\.env" |
matches .env anywhere in the absolute path |
"/go\\\\.mod\\\\'" |
matches only an absolute path that ends in /go.mod |
"/nginx/sites/.*\\\\'" |
matches paths ending with /nginx/sites/ followed by any filename |
selected regexps:
\\\\' |
match the empty string |
\\\\. |
match a literal dot |
/ |
match the directory separator |
Gotchas#
:modeis forauto-mode-alist, which is for major modes; minor mode configuration should be handled elsewhere- a mistake in
:modemay end up with an erroneous entry inauto-mode-alist; to mitigate:- evaluate
(assoc "\\.my-regexp" auto-mode-alist)to confirm the error - remove the erroneous association:
(setq auto-mode-alist (rassq-delete-all 'my-erroneous-mode auto-mode-alist)) - evaluate the
use-packagedeclaration
- evaluate
Alternatively, you can remove the offending key (("\\.c" . c-ts-mode) in this example) via:
(setq auto-mode-alist
(delete '("\\.c" . c-ts-mode) auto-mode-alist))
window.el#
(setq display-buffer-alist '(
("\\*Help\\*"
(display-buffer-reuse-window
display-buffer-in-side-window)
(side . right)
(slot . -1)
(window-parameters . ((no-other-window . t)
(no-delete-other-windows . t))))
("\\*eldoc.*\\*"
(display-buffer-reuse-window
display-buffer-in-side-window)
(side . right)
(slot . 1)
(window-height . .5))
("\\*info\\*"
(display-buffer-reuse-window
display-buffer-in-side-window)
(side . right)
(window-height . .5)
(window-width . 80))
((derived-mode . magit-diff-mode)
(display-buffer-reuse-window
display-buffer-in-side-window)
(side . right)
(slot . 1))
((derived-mode . magit-mode)
(display-buffer-reuse-window
display-buffer-in-side-window)
(side . right))
))
External Packages#
apheleia#
🌷 Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming.
Useful Variables#
apheleia-inhibit-functions |
apheleia-formatters |
Gotchas#
- apheleia checks whether
indent-tabs-modeis enabled to determine whether tabs or spaces should be used - there is no configuration interface for the invoked formatting tool, either:
- set a standard (?? global ??) config file
- set an environment variable that the ?? called formatting tool ?? reads
- change the entry in
apheleia-formatters
An error in a formatting tool’s configuration may end up with the error:
error in process sentinel: could not parse json stream 1, 1, 1
Check the configuration file for typos.
Resources#
- radian-software/apheleia GitHub repo
Cond-Let#
- tarsius/cond-let GitHub repository
- tarsius/cond-let/wiki GitHub wiki
Consult#
Resources#
- minad/consult GitHub repository
command-log-mode#
command-log-mode is an add-on that makes it easy to show command and event history.
Commands#
| C-c o | toggle the log window |
csv-mode#
Commands#
| C-c c-a | csv-align-fields |
align fields to form columns |
Embark#
Frequently Asked Questions (FAQs)#
What does Embark stand for?#
Embark: Emacs Mini-Buffer Actions Rooted in Keymaps
Resources#
- oantolin/embark GitHub repository
envrc#
envrc-reload |
refresh the environment |
geiser-guile#
| C-c C-z | start REPL | |
| M-x geiser-restart-repl | restart REPL | |
| ,q | quit REPL | |
| C-x C-e | geiser-eval-last-sexp |
|
| C-u C-x C-e | evaluate last sexp and insert result at point | |
| C-M-x | geiser-eval-definition |
|
| C-c M-e | geiser-eval-definition-and-go |
|
| C-c C-r | geiser-eval-region |
|
| C-c M-r | geiser-eval-region-and-go |
|
| C-c C-b | geiser-eval-buffer |
|
| C-c M-b | geiser-eval-buffer-and-go |
Helpful links:
Ghostel#
ghostel-project |
Start a new Ghostel terminal in the current project’s root |
gptel#
gptel |
gptel-send |
C-u gptel-send |
helm#
Helpful links
- Recursive grep in directory with helm and/or projectile?
- helm GitHub repo
- helm-projectile GitHub repo
- Exploring large projects with Projectile and Helm Projectile
js-mode#
| M-x js-jsx-enable | enable JSX support |
More JSX info in this StackExchange answer.
lsp-mode#
I now use Eglot.
LSP Mode - LSP support for Emacs
Commands#
| s-l r r | Rename the symbol (and all references to it). | |
| s-l g g | Find definitions of the symbol under point. Jump to definition. | |
| s-l g r | Find references of the symbol under point. | |
| s-l r o | Perform the source.organizeImports code action, if available. |
|
| s-l w r | lsp-workspace-restart |
restart the workspace WORKSPACE and the language server associated with it |
| M-x lsp-describe-session | Describe session; shows project roots | |
| s-l F r | lsp-workspace-folders-remove |
remove folders from workspace |
| M-x lsp-workspace-folders-add | Add folders to workspace |
Troubleshooting#
lsp-mode not reading tsconfig.json#
- check if M-x lsp-describe-session makes sense
- remove folders via M-x lsp-workspace-folders-remove
- close all project files
- reopen file and input I to interactively choose project root
gopls errors#
Try upgrading to the latest gopls:
go install golang.org/x/tools/gopls@latest
Configuration#
GitHub code search results for Go configuration
magit (magit.el)#
Commands#
General#
| C-x g | magit-status |
open magit-popup |
| C-h R magit | open magit manual | |
| C-c M-g | magit-file-dispatch |
giving access to blame |
| C-w | magit-copy-section-value |
magit copy selection under point |
magit-init |
initialize a new repository | |
magit-log-buffer-file |
show commit log for current buffer (note: an active region will scope the log appropriately!) | |
magit-file-untrack |
remove tracked file but don’t delete | |
magit-clone |
||
magit-clone-shallow |
call with prefix argument to specify DEPTH |
Within magit-popup#
| b | magit-branch |
branch |
| f | magit-fetch |
fetch |
| m | magit-merge |
merge |
| F | magit-pull |
pull |
| P | magit-push |
push |
| o | magit-submodule |
submodule |
| y | magit-show-refs |
list branches; list tags |
| <TAB> | magit-section-toggle |
|
| S-<TAB> | magit-section-cycle-global |
|
| M-<TAB> | magit-section-cycle-diffs |
Common Operations#
Configuring a Forked Repository#
This is specific to my forked repository workflow for open source development and learning a codebase.
Configure u for upstream (branch.main.merge and branch.main.remote) to be upstream/main:
| C-x g | magit-status |
|
| b | magit-branch |
|
| u | unsets origin | |
| u | prompts for input: select the equivalent of upstream/main |
Configure p for push (branch.main.pushRemote) to be origin:
| C-x g | magit-status |
|
| b | magit-branch |
|
| p | sets origin |
Set repository defaults (for future feature branches):
| C-x g | magit-status |
|
| b | magit-branch |
|
P to origin |
configure remote.pushDefault for the repository |
Add Remote Origin#
| C-x g | magit-status |
|
| M | magit-remote |
open magit-remote-popup |
| a | select ‘add’ | |
| origin | add name | |
| git@example.com:path/to/repo.git | add repository address |
Configuring Remote#
In branch configuration:
Configure main
d branch.main.description unset
u branch.main.merge refs/heads/main
branch.main.remote origin
r branch.main.rebase [true|merges|interactive|false|default:false]
p branch.main.pushRemote [kips-mbp|origin|remote.pushDefault:origin]
branch.main.remote origin looks like it is missing a key for configuration.
Solution: press u.
Commit Message Editing#
| C-c C-c | Finish editing session and create commit |
| C-c C-k | Cancel editing session and cancel commit |
Tagging#
| C-x g | magit-status |
|
| t | magit-tag |
|
| t r | create a new release tag | |
| P t | push all tags |
Diffing Between Two Commits#
| C-x g | magit-status |
|
| l l | get the sha values you wish to diff (e.g. through inspecting the log) | |
| d | open magit-diff | |
| specify options, like limiting to specific file | ||
| r | specify range (e.g. HEAD..8637c28) |
Restoring file(s) from a commit#
I do not yet know how to restore an entire directory at once—workaround is just to restore each file one by one.
| gather the SHA1 or ref you wish to restore from | ||
| C-x g | magit-status |
|
| X | open magit-reset | |
| f | select a file | |
| enter commit SHA1 or tag, followed by filepath |
Check Out a Specific Tag#
| C-x g | magit-status |
|
| b b | magit-checkout |
|
| enter tag name |
Updating a Fork with Upstream#
Pull (fetch + merge) to get latest without merge commits:
| C-x g | magit-status |
|
| F | magit-pull |
|
| -f | select Fast-forward only | |
| e | select elsewhere | |
| select upstream |
Fetch for more flexible options:
| C-x g | magit-status |
|
| f | magit-fetch |
|
| e | select elsewhere | |
| select upstream | ||
| merge or rebase as you see fit |
List Remotes#
| C-x g | magit-status |
| M | magit-remote |
Killing a Git process#
| M-x magit-process-buffer | or switch to the appropriate magit-process: foo buffer | |
| move point to Git operation | ||
| k | magit-process-kill |
Fetch All Tags#
| C-x g | magit-status |
|
| f | magit-fetch |
|
| -t | fetch all tags | |
| select location as you see fit |
Frequently Asked Questions (FAQs)#
What is the difference between upstream and pushRemote?#
Assuming:
- a local branch topic tracking origin/topic
- topic was branched from origin/main
- topic is planned to be merged into origin/main when work is complete
we use the following terminology:
- upstream is where topic will eventually end up: origin/main
- pushRemote is where in-progress work on topic should go: origin/topic
This is a semantic distinction that helps organize development: if upstream and pushRemote are always the same there is no need to set both. My personal preference is to always configure pushRemote because the keybindings feel more natural.
Read The Two Remotes from the official documentation.
What is a release tag?#
I do not exactly know, but reading the tagging docs indicates that it is a normal tag that magit runs through magit-release-tag-regexp to ensure a consistent numbering scheme.
What is a “spinoff branch”? What is a “spinout branch”?#
| spinoff | create a new branch from the unpushed commits and check it out |
| spinout | create a new branch from the unpushed commits and remain on current |
Review documentation for full explanation:
magit-branch-spinoffmagit-branch-spinout
Resources#
- Official magit documentation
markdown-mode#
Commands#
Navigation#
| C-c C-o | markdown-follow-thing-at-point |
| C-c C-n | markdown-outline-next |
| C-c C-p | markdown-outline-previous |
| C-c C-f | markdown-outline-next-same-level |
| C-c C-b | markdown-outline-previous-same-level |
| C-c C-u | markdown-outline-up |
Tables#
| C-c S-<LEFT> | markdown-table-delete-column |
|
| C-c S-<UP> | markdown-table-delete-row |
|
| C-c S-<RIGHT> | markdown-table-insert-column |
|
| C-c S-<DOWN> | markdown-table-insert-row |
at point, moving current row “down” |
markdown-table-move-column-left |
||
markdown-table-move-column-right |
||
| C-c C-c ^ | markdown-table-sort-lines |
based on column at point |
Formatting#
| C-c - | markdown-insert-hr |
Insert or replace a horizontal rule |
Official markdown-mode Documentation
multiple-cursors.el#
| M-x mc/mark-all-in-region | prompt for a string to match in region |
orderless#
Frequently Asked Questions (FAQs)#
How do I filter by annotation?#
Assuming you have consult, vertico, and marginalia installed...
To filter only dired buffers:
| C-x b | consult-buffer |
|
| &dired | filters only buffers with annotation matching “dired” |
Org#
Resources#
- Official site
- org-mode codebase
- org-mode mailing list
- Questions tagged with
org-modeon Emacs Stack Exchange
Terminology#
- agenda#(term agenda)
- 1.
- appointment#(term appointment)
- 1.
- archive#(term archive)
- 1.
- capture#(term capture)
- 1.
- dispatcher#(term dispatcher)
- 1.
- drawer#(term drawer)
- 1.
- entry#(term entry)
- 1.
- folding#(term folding)
- 1.
hiding specific parts of a document for better visualization; could be to see hierarchical structure or focus a specific working area
Related:
- headline#(term headline)
- 1.
defines the structure of an outline tree; starts with one or more star on the left margin
Related:
- keyword#(term keyword)
- 1.
- Org file#(term Org file)
- 1.
- plain list item#(term plain list item)
- 1.
- prefix argument#(term prefix argument)
- 1.
C-u
- priority cookie#(term priority cookie)
- 1.
indicator of a TODO item’s priority. A, B, and C supported by default
Related:
- property#(term property)
- 1.
- refile#(term refile)
- 1.
moving or copying an item from one location to another; e.g. from one top level headline to another
Related:
- STARTUP#(term STARTUP)
- 1.
- sparse tree#(term sparse tree)
- 1.
- state CHILDREN#(term state CHILDREN)
- 1.
- state CONTENTS#(term state CONTENTS)
- 1.
- state FOLDED#(term state FOLDED)
- 1.
- state OVERVIEW#(term state OVERVIEW)
- 1.
- state SHOW ALL#(term state SHOW ALL)
- 1.
- state SUBTREE#(term state SUBTREE)
- 1.
- tag#(term tag)
- 1.
- timestamp#(term timestamp)
- 1.
specially formatted date and time
- tree#(term tree)
- 1.
- tree node#(term tree node)
- 1.
prettier-js#
I now use apheleia.
Notes#
- displays as Prettier despite being named
prettier-js - is a minor-mode
Commands#
| M-x prettier-js | run prettier on current file |
Resources#
projectile (projectile.el)#
I now use project.el
Commands#
| s-p p | open project |
| s-p q | switch project |
| s-f | find file in project |
| M-x projectile-discover-projects-in-directory | discover projects in directory |
| M-x projectile-discover-projects-in-search-path | discover projects in search path (path specified via config) |
| M-x projectile-cleanup-known-projects | remove known projects that don’t exist anymore |
| M-x projectile-clear-known-projects | clear known projects |
| M-x projectile-invalidate-cache | clear cache |
| M-x projectile-kill-buffers | close all buffers associated with a project |
Problems and Solutions#
| problem | solution |
|---|---|
| deleted / removed file still being found | M-x projectile-invalidate-cache |
| grepped-for string not being found | ensure that all files are tracked by git |
| deleted project still showing up in project switcher | M-x projectile-cleanup-known-projects |
| old / irrelevant / no longer needed project still showing up in the project switcher | option 1: (completely removes all projects and starts again from scratch) M-x projectile-clear-known-projects |
| option 2: M-x projectile-remove-known-project | |
| option 3: (if you are currently visiting a buffer within the project) M-x projectile-remove-current-project-from-known-projects |
Resources#
scheme-mode#
| C-x C-e | evaluate expression |
| C-c C-l | load file |
sqlformat#
I now use apheleia.
Official purcell/sqlformat GitHub repo.
Commands#
| M-x sqlformat-on-save-mode | disable / enable automatic format on save |
vertico#
Frequently Asked Questions (FAQs)#
How do I override completion?#
M-<RET>
vterm#
I now use Ghostel.
| C-u 42 M-x vterm <RET> | switch to *vterm<42>* or create it if it doesn’t exist | |
| C-c C-t | vterm-copy-mode |
toggles the mode to copy text from vterm |
| C-c C-l | vterm-clear-scrollback |
(scrollback is what has been scrolled out of view from the top of the buffer) |
web-mode#
Commands#
| C-c C-e i | insert HTML element |
| C-c C-s | insert snippet |
| C-c C-f | fold or unfold |
| M-; | insert HTML comment |
Resources#
Frequently Asked Questions (FAQs)#
How do I clear tag history?#
| M-: | eval-expression |
(setq web-mode-tag-history nil) |
This may be needed if you mistype a tag name and it keeps showing up in your history.
wgrep#
I am aware that in Emacs 31.1 grep-mode got grep-edit-mode but I still prefer wgrep for:
- the ability to stage and revert your changes
- not opening every matched file in a buffer
- not creating a function named
grep-edit-save-changesthat does not actually save changes
See bug#70820: [PATCH] Editable grep buffers for more information.
Usage#
| enter *grep* buffer | ||
| C-c C-p | wgrep-change-to-wgrep-mode |
|
| make your changes | ||
| C-c C-c | wgrep-finish-edit |
apply and save your changes |
| C-c C-k | wgrep-abort-changes |
discard all changes and exit |
| C-x C-q | wgrep-exit |
Resources#
- mhayashi1120/Emacs-wgrep GitHub repository
yasnippet#
Commands#
| M-x yas-new-snippet | create new snippet | |
| M-x yas-recompile-all | recompile all snippets | |
| M-x yas-reload-all | reload all snippets, clearing any incorrectly created snippets | |
| C-d | yas-skip-and-clear-field |
Selected Authoring Functions#
yas-choose-value (&rest possibilities) |
allows you to choose from a predefined list |
yas-auto-next |
automatically moves to the next input after entry |
Examples#
A snippet file named now that returns a double-quoted and formatted time:
# -*- mode: snippet -*-
# name: now
# key: now
#
# also: I am a comment!
# --
"`(format-time-string "%F @ %R %z")`"
Frequently Asked Questions (FAQs)#
I restarted emacs and snippets no longer reflect the changes I made last session but are present in the snippet file—what gives?#
It is possible yasnippet is reading a stale compiled snippets file. These files exist at the top level of a snippet template directory.
Example:
./snippets/markdown-mode/.yas-compiled-snippets.el
./snippets/conf-mode/.yas-compiled-snippets.el
./snippets/yaml-mode/.yas-compiled-snippets.el
To fix:
| M-x yas-recompile-all |
| M-x yas-reload-all |
How do I skip a field’s default text?#
| C-d | yas-skip-and-clear-field |
Resources#
xref#
Commands#
| M-. | xref-find-definitions |
prefix argument will prompt for identifier name |
| C-M-. | xref-find-apropos |
|
| M-, | xref-go-back |
|
| C-M-, | xref-go-forward |
|
| M-? | xref-find-references |
|
| C-M-i | complete at point |
Custom Behavior#
Specific to my init.el:
escape-html |
HTML escapes the text in region |
unescape-html |
HTML unescapes the text in region |
| M-p | move line of text up / move text up / move line up |
| M-n | move line of text down / move text down / move line down |
| C-c t | toggle typopunct-mode (for curly quotes and apostrophes) |
Emacs Lisp (elisp)#
elisp Formatting#
Times and Dates#
Format strings, for use with format-time-string:
%F |
the ISO 8601 date format: 2006-01-02 |
%R |
synonym for %H:%M (e.g. 15:04) |
Examples:
(format-time-string "%F @ %R %z" (date-to-time "02 Jan 06 15:04 MST") "MST")
"2006-01-02 @ 15:04 -0700"
(format-time-string "%Y-W%W %a %b %d" (date-to-time "02 Jan 06 15:04 MST") "MST")
"2006-W01 Mon Jan 02"
- GNU Emacs Manual 40.8 Parsing and Formatting Times
Frequently Asked Questions (FAQs)#
How do I add emacs to Automation permissions under Privacy & Security?#
Use osascript from within emacs to request the permission:
- M-x shell-command
- osascript -e 'tell application "System Events" to tell appearance preferences to return dark mode'
- allow the permission
- restart emacs
What is the ^L character?#
From the GNU Emacs Manual on Pages:
Within some text files, text is divided into “pages” delimited by the “formfeed character” (ASCII code 12, also denoted as ‘control-L’), which is displayed in Emacs as the escape sequence ‘^L’ (see How Text Is Displayed). Traditionally, when such text files are printed to hardcopy, each formfeed character forces a page break. Most Emacs commands treat it just like any other character, so you can insert it with ‘C-q C-l’, delete it with <DEL>, etc. In addition, Emacs provides commands to move over pages and operate on them.
Why are some buffer names surrounded by asterisks?#
It is a convention to distinguish the buffers that are not associated with any underlying file (e.g. *scratch* or *info*).
The manual advises in “21.1 Creating and Selecting Buffers” to avoid naming buffers that start with a space character because those are treated special for internal purposes.
Where are the website files for Emacs located?#
The files for the project website may be accessed via the CVS repo and path cvs.savannah.gnu.org:/web/emacs.
Instructions are within admin/notes/www in the Emacs Git repository (mirrored at emacs-mirror/emacs).
What is savannah?#
I do not know definitively. savannah.gnu.org appears to be a system with at least the following responsibilities:
- hosting www.gnu.org
- hosting https://git.savannah.gnu.org/git/emacs.git, the Git repository used by Emacs project development
- hosting cvs.savannah.gnu.org, the CVS repository which, under /web/emacs, contains the project website files
I’m getting an error when checking out cvs.savannah.gnu.org on macOS—why?#
If you see:
% cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/web/emacs co emacs
... text removed ...
U savannah__cvs__web_emacs/manual/html_node/auth/The-Unix-password-store.html
U savannah__cvs__web_emacs/manual/html_node/auth/Variable-Index.html
cvs [checkout aborted]: received abort signal
One reason may be the existence of two files whose names collide on case-insensitive file systems:
emacs/manual/html_node/auth/Index.html
emacs/manual/html_node/auth/index.html
The workaround for me was to create a case-sensitive APFS volume via Disk Utility and perform the checkout and work there.
Terminology#
- *Messages* buffer#(term *Messages* buffer)
- 1.
- abbrev#(term abbrev)
- 1.
A word which expands to a specified expansion if you insert it.
Related:
- alist (association list)#(term association list)(term alist)
- 1.
- alternate#(term alternate)
- 1.
As in, “find alternate file”. Originally from when you mistype a filename but want to keep the window.
- binding#(term binding)
- 1.
Mapping a key to a command.
Related:
- buffer#(term buffer)
- bury#(term bury)
- 1.
As in, bury a buffer.
- child frame#(term child frame)
- 1.
- complete key#(term complete key)
- 1.
A key sequence that invokes a command.
Broader:
Related:
- completion#(term completion)(term completion UI)
- 1.
- control characters#(term control characters)
- 1.
Definition todo. such as RET, TAB, DEL, ESC, F1, Home, and LEFT.
Related:
- current buffer#(term current buffer)
- cursor#(term cursor)
- 1.
The blinking block over an area of a single character’s dimensions.
Related:
- defun#(term defun)
- delete#(term delete)(term deleting)(term deletion)
- dispatch menu#(term dispatch menu)
- 1.
menu in the mini buffer that allows further actions
- dwim (do what I mean)#(term dwim)(term do what I mean)
- 1.
- echo area#(term echo area)
- echoing#(term echoing)
- emacsen#(term emacsen)
- 1.
The plural of emacs, referring to the different implementations of the editor.
- error message#(term error message)
- 1.
- face#(term face)
- 1.
How text is displayed.
Related:
- follow-mode#(term follow-mode)
- font lock mode#(term font lock mode)(term font locking)
- 1.
A minor mode which assigns faces to the text in the buffer; the buffer’s major mode tells Font Lock mode which text to fontify (e.g. a programming language mode telling which text are comments or function names).
Also: font locking
Related:
- frame#(term frame)
- 2.
Refers to the macOS window that Emacs is running in.
Narrower:
- graphic character#(term graphic character)
- 1.
A character that can be typed by pressing the associated key.
- help buffer#(term help buffer)
- 1.
- hook#(term hook)
- indirect buffer#(term indirect buffer)
- 1.
A buffer that shares the contents of another base buffer.
Broader:
- inferior process#(term inferior process)
- 1.
- informative message#(term informative message)
- 1.
- input events#(term input events)
- 1.
Keyboard and mouse presses.
Related:
- key#(term key)(term key sequence)(term key chord)
- 1.
A sequence of input events that is meaningful as a unit.
Also: key sequence, key chord
Narrower:
Related:
- keymap#(term keymap)
- 1.
The bindings between keys and commands.
Related:
- kill#(term kill)(term killing)
- kill ring#(term kill ring)
- 1.
Cyclical area that stores killed text; visualizable as blocks of text arranged into a ring, accessible in cyclic order.
Related:
- library#(term library)
- 1.
A collection of Emacs Lisp code in a single file.
Note: Sometimes used interchangeably with “package”.
Compare:
Related:
- major mode#(term major mode)
- 1.
- mark#(term mark)
- 1.
A saved location in the buffer (for the user’s convenience); can be thought of as a second, stationary cursor.
Related:
- mark ring#(term mark ring)
- 1.
- menu bar#(term menu bar)
- 1.
- minibuffer#(term minibuffer)
- 1.
Special-purpose buffer where emacs reads compilicated arguments (file names, buffer names, command names, lisp expressions, etc).
- minor mode#(term minor mode)
- 1.
- mode line#(term mode line)
- modifier keys#(term modifier keys)
- 1.
Keys like Control and Meta that change the bahvior of other keys.
Related:
- narrowing#(term narrowing)
- 1.
Editing a buffer is restricted to only a portion of its text; focusing in on some portion of the buffer, making the rest temporarily inaccessible.
Related:
- node#(term node)
- 1.
- node#(term node)
- 1.
- node header#(term node header)
- 1.
- node title#(term node title)
- 1.
- node topic#(term node topic)
- 1.
- nomenclature#(term nomenclature)
- 1.
A mixed case symbol (e.g. GtkWindow or EmacsFrameClass).
Note: Possibly specific to
cc-mode.Related:
- numeric argument#(term numeric argument)(term prefix argument)
- 1.
Typed before a command.
Also: prefix argument
- package#(term package)
- 1.
A collection containing at least one Emacs Lisp library, zero or more Info manuals, and possibly other components; sometimes used interchangeably with library.
Note: Sometimes used interchangeably with “library”.
Compare:
- package archive#(term package archive)
- 1.
Collections of Emacs Lisp packages.
Compare:
Related:
- point#(term point)
- point#(term point)
- 1.
The location of the cursor.
Related:
- prefix key#(term prefix key)
- 1.
A key sequence that does not itself invoke a command.
Broader:
Related:
- regexp (regular expression)#(term regexp)(term regular expression)
- 1.
- region#(term region)
- 1.
The text between point and the mark.
Related:
- register#(term register)
- root window#(term root window)
- 1.
- scrollbar#(term scrollbar)
- 1.
UI element within the window on graphical displays that allows scrolling of the buffer.
- side window#(term side window)
- 1.
Special windows that are placed on the edges of the frame’s root window.
Broader:
- subword#(term subword)
- 1.
The capitalized part of a nomenclature (e.g. Gtk and Window of GtkWindow).
Note: Possibly specific to
cc-mode.Related:
- TRAMP#(term TRAMP)
- 1.
- tag#(term tag)
- 1.
An identifier within a program.
Note: Sometimes used interchangeably with “xref”.
Compare:
- text decoration#(term text decoration)
- 1.
- the fill prefix#(term the fill prefix)
- 1.
- tool bar#(term tool bar)
- variable#(term variable)
- 1.
A Lisp symbol which has a value.
- visit#(term visit)
- 1.
Read a file and prepare a buffer containing a copy of the file’s contents.
- widening#(term widening)
- 1.
Canceling narrowing, making the entire buffer once again accessible.
Related:
- window#(term window)
- xref#(term xref)
- 1.
The unified interface for dealing with program identifiers.
Note: Sometimes used interchangeably with “tag”.
Compare:
- yank#(term yank)(term yanking)
- 1.
Bringing text from the kill ring back into the buffer.
- 2.
Reinserting text previously killed.
Also: yanking
Note: Sometimes used interchangeably with “pasting”.
Related:
Resources#
- Emacs Releases
- Mailing lists
- Repositories
- GNU Emacs git repository
- emacs-mirror/emacs
- cvs.savannah.gnu.org:/web/emacs for project website files
- GNU Emacs Manual
- 3rd Party GNU Emacs Manual, with dark mode support
- Emacs Stack Exchange