Emacs Built-in Features: Advanced 'Batteries Included' Guide
Emacs contains a vast array of built-in utilities that often go unnoticed due to discoverability issues. For users on Emacs 28.1+, leveraging these "batteries included" features allows for powerful workflows in navigation, diffing, and text manipulation without the need for third-party packages.
Enhanced Navigation and File Handling
Interactive Wildcards in find-file and dired
Users can use wildcards interactively with find-file (C-x C-f) and dired to open multiple files or filter directory listings. For example, using a wildcard like *foo*.txt in find-file opens all matching files simultaneously. In Dired, a wildcard such as */*_region_* can produce a custom listing of specific files across sub-directories, which can then be marked and deleted in bulk.
Buffer-wide Path Discovery with ffap-menu
While M-x ffap opens a file at the current point, M-x ffap-menu scans the entire buffer for all strings that look like file paths or URLs. This provides a completing-read interface, allowing users to filter and open any path found within the current document.
Dictionary Tooltips
Enabling M-x dictionary-tooltip-mode (along with tooltip-mode) displays word meanings in tooltips upon hovering. This feature can utilize local dictionaries or Wiktionary to look up contemporary jargon and lingo.
Advanced Diffing and Comparison Tools
Lightweight Comparison with compare-windows
M-x compare-windows is a context-agnostic tool that compares the text of two windows starting from their respective cursor positions. It stops and reports the first mismatch it encounters. Unlike Ediff, it does not care about the provenance of the text, making it useful for comparing two different sections of the same buffer or even comparing directory contents and file attributes in Dired.
Directory Comparison in Dired
M-x dired-compare-directories allows for file-level comparison between two directories. It marks files whose names differ, but it also supports custom matching predicates based on file attributes, such as marking files with the same name but different sizes ((/= size1 size2)) or the most recently modified version ((> mtime2 mtime1)).
Live Change Highlighting
M-x highlight-changes-mode emphasizes changes made to a file. While the base mode tracks changes from the moment it is enabled, it can be automated via hooks to highlight only unsaved changes:
(defun highlight-changes-mode-turn-off ()
(and highlight-changes-mode (highlight-changes-mode -1)))
(defun highlight-changes-auto ()
(when (buffer-file-name)
(highlight-changes-mode-turn-on)
(add-hook 'after-save-hook #'highlight-changes-mode-turn-on nil t)
(add-hook 'before-save-hook #'highlight-changes-mode-turn-off nil t)))
(add-hook 'text-mode-hook #'highlight-changes-auto)
Specialized Text Manipulation and Editing
Modern Duplication Commands
Recent Emacs versions have added commands that mirror common editing patterns found in other editors:
copy-from-above-command: Copies text from the first non-blank line above the cursor.duplicate-dwim: Copies the current line or active region below the current position.
Macro Creation from History
M-x kmacro-edit-lossage allows users to create a keyboard macro from their recent keystroke history (the "lossage"). This solves the "foresight problem" by letting users record a sequence of actions and then convert that sequence into a repeatable macro after the fact.
Word Syntax Customization
subword-mode treats components of CamelCase symbols as individual words, while superword-mode treats snake_case symbols as a single word. Furthermore, users can modify the syntax table of a major mode to change how characters are treated; for example, making the colon (:) part of a word in Lisp-data-mode to improve backward-kill-word behavior:
(add-hook 'lisp-data-mode-hook
(lambda () (modify-syntax-entry ?: "w")))
Window and Frame Management
Synchronized Scrolling with scroll-all-mode
M-x scroll-all-mode scrolls all windows in the current frame simultaneously. This is particularly useful when comparing two versions of a file side-by-side without entering a formal Ediff session.
Visual Margin Control with ruler-mode
M-x ruler-mode provides a visual interface for adjusting buffer margins and the fill-column. Users can use S-<mouse-1> and S-<mouse-3> to set left and right margins and drag <mouse-2> to adjust the fill-column on the fly.
Frame Recovery
M-x undelete-frame-mode enables the ability to restore recently closed frames. Once enabled, M-x undelete-frame can restore up to the last 16 deleted frames, preserving the workspace layout.
Utility and Help Systems
The apropos Family
Beyond the standard apropos, Emacs includes specialized lookup commands such as apropos-variable, apropos-function, and customize-apropos. The latter creates a customization buffer containing all options and faces matching a search term.
Direct Source Access
M-x find-function-on-key allows a user to jump directly from a keybinding to the source code of the function it invokes, bypassing the need to first describe the key and then jump to the source.
Buffer Locking
M-x emacs-lock-mode prevents a buffer from being killed or Emacs from exiting until the lock is manually disengaged. This is useful for protecting non-file-visiting buffers containing critical temporary data.
Community Perspectives on Discoverability and Stability
While these built-in features are powerful, the Emacs community remains divided on the "vanilla" experience versus curated distributions. Some users argue that the discoverability problem is the primary hurdle for new users, while others suggest that stability is the greater issue:
"My problem with emacs batteries has always been stability between different combinations of packages... any additional package added can bork some random, seemingly unrelated package."
Conversely, proponents of the vanilla approach argue that starting with a minimal configuration encourages the necessary learning process to avoid rewriting built-in functionality:
"Both Emacs and Neovim reward rtfm and working up from a vanilla configuration to your own custom one. The distribution style packages for these editors make the user skip all that initial learning and discovery."