auto-hide
is an Emacs package that automatically hides function bodies in various programming languages using tree-sitter, enhancing code readability. It was written in response to https://matklad.github.io/2024/10/14/missing-ide-feature.html, so you can look there for screenshots that give a rough idea of what it does.
It is a light wrapper around the built-in Hideshow package. It supports Rust, C++, Javascript and Python “out of the box”.
Emacs 29.1 or later with tree-sitter support.
Install auto-hide
by downloading the source and using M-x package-install-file
, or through your preferred package manager.
For example, using elpaca, I install and configure it as follows:
(use-package auto-hide
:ensure (:host github :repo "ultronozm/auto-hide.el"
:depth nil)
:config
(global-auto-hide-mode))
Customize auto-hide-language-config
to add support for additional languages or modify existing configurations. To customize which major modes use auto-hide, adjust the auto-hide-modes
variable.
After installing the package, you can enable it globally with:
(global-auto-hide-mode)
This activates the Hideshow package in the supported buffers and provides the following keybindings:
Keybinding | Command | Functionality |
---|---|---|
C-c @ t | auto-hide-hide-all | Hide all function bodies in the current buffer |
C-c @ s | auto-hide-show-at-point | Show the function body at point |
C-c @ d | auto-hide-hide-at-point | Hide the function body at point |
C-c @ e | auto-hide-toggle-at-point | Toggle visibility of the function body at point |
These shadow some related bindings in Hideshow, which contains other useful bindings, e.g.:
Keybinding | Command | Functionality |
---|---|---|
C-c @ C-a | hs-show-all | Show all |
Auto-hide integrates with xref-find-definitions
, automatically showing function bodies when jumping to definitions (typically via M-.
). Pressing M-.
repeatedly on the name of a function will toggle visibility of the function body. You can disable this feature by setting auto-hide-xref-integration
to nil
.