Emacs 31 Release Preview: Tree-sitter, Markdown-ts, and Core Enhancements

Emacs 31 focuses on reducing the need for external configuration by absorbing common community patterns into the core editor. The primary takeaways are the automation of Tree-sitter setups, the introduction of a native Markdown Tree-sitter mode, and a series of window management and version control refinements that eliminate the need for many common custom Lisp hacks.

Simplified Tree-sitter Integration

Emacs 31 drastically reduces the manual effort required to set up *-ts-mode variants. Previously, users had to manually populate treesit-language-source-alist and call treesit-install-language-grammar while ensuring their local toolchain was correctly configured.

Key improvements include:

  • Automated Installation: Setting treesit-enabled-modes to t automatically switches compatible major modes to their Tree-sitter variants. The treesit-auto-install-grammar variable now allows Emacs to offer to fetch and build missing grammars automatically.
  • Built-in Sources: Grammar sources for languages such as Rust, TypeScript, TSX, TOML, YAML, and Dockerfile are now defined within the mode code itself, removing the need for manual source definitions in user configurations.

Architecture Warning: Auto-installed grammars are not segregated by architecture. If a configuration directory is shared across different architectures (e.g., x86_64 and arm64), the binary built on one machine will not load on the other.

Experimental markdown-ts-mode

Emacs 31 introduces markdown-ts-mode, an experimental Tree-sitter based mode for Markdown. While it is not yet wired to auto-mode-alist and must be loaded manually via M-x load-library, it provides several advanced features:

  • Org-like Navigation: Keybindings for navigating headings and folding sections are designed to feel familiar to Org-mode users.
  • Dynamic Code Block Highlighting: Fenced code blocks are fontified using the actual major mode for the specified language (e.g.,an elisp block uses true Emacs Lisp font-locking) rather than simple monospace text.
  • Inline Image Rendering: Image links are rendered directly in the buffer, allowing documents to be read as formatted files rather than raw text.
  • Code Block Editing: Users can edit fenced blocks using the target language's mode.

Additionally, Eglot can now use markdown-ts-view-mode to render LSP documentation hovers in formatted Markdown instead of plain text.

Editable Xref Buffers

One of the most significant workflow improvements is the introduction of xref-edit-mode. Previously, Xref buffers only supported regex-based replacement via xref-query-replace-in-results.

With xref-edit-mode, users can now edit Xref results inline. By pressing e in an *xref* buffer, the editor enters an edit mode where changes can be made across multiple matches; these changes are then confirmed and written to the files using C-c C-c.

Window Layout and UI Enhancements

Emacs 31 introduces several tools for rearranging the editor interface without the need to manually kill and split windows:

  • Layout Gymnastics: New commands allow users to Transpose (swap horizontal and vertical arrangements), Rotate (spin the layout), and Flip (mirror the layout left-to-right or top-to-bottom).
  • Side-Window Speedbar: The speedbar-window command now allows the Speedbar to live in a proper side window rather than a separate floating frame, making it more compatible with tiling window managers.
  • Eldoc at Point: When enabled, eldoc now shows help text for the element currently under the cursor without requiring manual invocation.

Completion and Version Control Improvements

Minibuffer and Completion

  • Eager Updates: completion-eager-update and completion-eager-display refresh the completion UI in real-time as the user types.
  • Navigation: minibuffer-visible-completions set to 'up-down enables arrow-key navigation through visible candidates.
  • Icomplete Enhancements: Icomplete now supports vertical in-buffer behavior and prefix indicators.

Version Control (VC)

  • Automatic Hiding: vc-dir-auto-hide-up-to-date automatically hides files that are up-to-date during a vc-dir refresh.
  • History Rewriting: vc-allow-rewriting-published-history provides native support for workflows involving force-pushing or tools like Jujutsu.

Quality-of-Life Fixes and Small Knobs

  • kill-region-dwim: Setting this to 'emacs-word allows C-w to kill a word backwards when no region is active, preventing the "mark is not active" error.
  • view-lossage-auto-refresh: Enables a live view of the last keystrokes in the lossage buffer (C-h l).
  • ielm-history-file-name: Allows IELM scratch sessions to persist across restarts.
  • native-comp-async-on-battery-power: Can be set to nil to prevent background native compilation from draining battery or triggering fans on laptops.
  • tty-tip-mode: Adds tooltip support for Emacs running in the terminal (-nw).
  • Terminal Fixes: A long-standing bug in term and ansi-term that caused lines to be swallowed or garbled in curses-based programs (like htop or nethack) has been resolved.
  • Modus Themes: The release includes several new Modus themes, including versions optimized for Deuteranopia and Tritanopia.

Community Perspective

Discussion among users suggests that the integration of Tree-sitter has revitalized interest in the project. Some users note that the hyper-configurable nature of Emacs, combined with modern LLMs, has lowered the entry barrier for new users who can now use AI agents to help maintain their init.el configurations.

Sources