Even more batteries included with Emacs
Even More Batteries Included with Emacs
Emacs suffers from a significant discoverability problem. To combat this, we are attempting to uncover its hidden gems, one demonstration at a time.
Since my previous update, I have stumbled upon several more surprising and productive utilities. It is time, therefore, for another "batteries included" report.
Note: This is the third installment in a series dedicated to highlighting the useful, yet obscure, features built directly into Emacs. (See Parts 1 & 2 for more).
Defining "Lesser-Known"
The term "lesser-known" is inherently subjective. For the purpose of this article, I define it using a rough mathematical threshold:
While some features from previous posts have since entered the mainstream, my goal remains to find the outliers.
A Word of Advice for Beginners
If you are new to the ecosystem, you will find more value in mastering the core concepts and using widely supported packages first. Once you hit that "aha!" moment—similar to wondering why suitcases didn't have wheels until 1990—you'll be ready for this list.
Rule of Thumb: If you haven't yet discovered undo-in-region, there is still plenty of "low-hanging fruit" for you to find. Please return to this guide once you've exhausted those basics!
Even for veterans, Emacs is so vast that everyone tends to use a different niche subset of features. There is likely something here that will surprise even the most seasoned user.
The Ground Rules
To keep this list focused, I've applied the following constraints:
- Stock Emacs only: No external packages.
- Low barrier to entry: No steep learning curves.
-
No "Easter Eggs": NoM-x doctor,tetris,snake,dunnet,zone,butterfly, ordissociated-press. -
No common utilities: NoFlymake,doc-view,outline-minor-mode,gnus, oreww. - Non-obvious: Nothing that a generic Google search or an automatic Emacs prompt reveals immediately.
Translation Guide: Emacs Jargon
For those still learning the language, here is a quick reference table:
| Emacs Term | Modern Equivalent | Description |
|---|---|---|
M-x | Alt + x | Execute a command |
C-x | Ctrl + x | Prefix key |
| Frame | Window | The actual OS window |
| Window | Split/Pane | A division within a frame |
| Buffer | Text Chunk | The data being edited |
| Point | Cursor | The current position in a buffer |
| Active Region | Selection | Highlighted text |
| Region | Selection | Text range (not necessarily highlighted) |
| Face | Styling | Font, color, and display attributes |
1. Instant Dictionary Lookups
By enabling M-x dictionary-tooltip-mode, you can view the definition of a word simply by hovering your cursor over it.
- Requirement:
tooltip-modemust be active (which is the default). - Priority: Emacs checks local dictionaries first.
- Scope: It can handle modern slang and jargon, typically by querying Wiktionary.
2. Wildcards in find-file and dired
Two of the most common commands—find-file (C-x C-f) and dired—possess a hidden superpower: wildcard support.
find-file: Use a pattern like*foo*.txtto open multiple matching files simultaneously.dired: Use a wildcard in the directory path to filter the resulting file list.
Workflow Example: Cleaning TeX Artifacts
Step-by-Step Execution:
- Run Dired with
*/*_region_*to find temporary AucTeX files in sub-directories. - Mark all matches using
dired-toggle-marks(bound tot) and delete them. - Use
find-filewith a wildcard to open all.texfiles across sub-directories. - Verify the open buffers (using
consult-bufferandcorfufor completion).
While modern setups might use consult-find exported via embark-export, the built-in wildcard method works immediately without any configuration.
3. Listing URIs with ffap-menu
You likely know M-x ffap (find-file-at-point), which opens a file if the cursor is on a path. However, ffap-menu is a more powerful sibling. It scans the entire buffer for any string resembling a URL or file path and presents them in a list.
Because it uses a completing-read interface, you can:
- Filter the list.
- Export the results to a buffer.
- Use Embark to perform bulk actions on the discovered links.
Addendum: Handling Propertized Links
Standard ffap-menu fails to see "propertized" links (links embedded as metadata, common in EWW). To solve this, I developed a custom function to capture both plain-text and propertized URLs.
The Process:
- Open a Wikipedia page in
EWW. - Execute
my/search-occur-browse-url. - Synchronously scroll through the link list and the page content.
The Implementation:
(defun my/search-occur-browse-url (optional use-generic-p)
"Point browser at a URL in the buffer using completion.
The web browser used depends on `browse-url-browser-function`.
Also see `my/search-occur-url`."
(interactive "P")
(let ((match nil)
(match-data nil)
(context (lambda (beg optional shrp)
(let* ((before (string-replace "\n" ""
(buffer-substring-no-properties
beg (max (1- beg) (point-min)))))))