28.7 Hideshow minor mode

Hideshow mode is a buffer-local minor mode that allows you to selectively display portions of a program, which are referred to as blocks. Type M-x hs-minor-mode to toggle this minor mode (see Minor Modes).

When you use Hideshow mode to hide a block, the block disappears from the screen, to be replaced by an ellipsis (three periods in a row). Just what constitutes a block depends on the major mode. In C mode and related modes, blocks are delimited by braces, while in Lisp mode they are delimited by parentheses. Multi-line comments also count as blocks.

Hideshow mode provides the following commands (defined in hs-prefix-map):

C-c @ C-h
C-c @ C-d

Hide the current block (hs-hide-block).

C-c @ C-s

Show the current block (hs-show-block).

C-c @ C-c
C-c @ C-e
S-mouse-2

Either hide or show the current block (hs-toggle-hiding).

C-c @ C-M-h
C-c @ C-t

Hide all top-level blocks (hs-hide-all).

C-c @ C-M-s
C-c @ C-a

Show all blocks in the buffer (hs-show-all).

C-u n C-c @ C-l

Hide all blocks n levels below this block (hs-hide-level).

C-c @ TAB

Cycle the visibility state of the current block (hs-cycle).

C-c @ <backtab>

Either hide or show all the blocks in the current buffer. (hs-toggle-all).

These variables can be used to customize Hideshow mode:

hs-hide-comments-when-hiding-all

If non-nil, hs-hide-all, hs-cycle and hs-hide-level hide comments too.

hs-hide-block-behavior

This variable controls how hs-hide-block and hs-toggle-hiding should hide a block. The possible values can be ’after-bol’, hide the innermost block to which the current line belongs; or ’after-cursor’, hide the block after cursor position.

hs-display-lines-hidden

If non-nil, display the number of hidden lines next to the ellipsis.

hs-show-indicators

This variable controls whether Hideshow mode should display indicators of hidden and shown blocks. The indicators also allow toggling the hide/show state of each block. If the value is non-nil, it enables the indicators. The default is nil, which disables the indicators.

hs-indicator-type

This variable controls where to show the indicators, if they are enabled. You can show them on the fringe (see Window Fringes) or in the window’s margin. The default is to use the fringe if it’s available, otherwise to use the margin.

hs-indicator-maximum-buffer-size

This variable limits the display of hideshow indicators to buffers that are not too large. (Larger buffers might adversely affect redisplay performance.) By default, buffers larger than 2MB have the indicators disabled; the value of nil will activate the indicators regardless of the buffer size.

hs-cycle-filter

This variable controls where on the line with hideable blocks typing the TAB key will cycle the visibility of the blocks. Depending on its non-nil value, TAB can be active on different parts of such lines. Anywhere else on the line TAB has its default key binding. The value nil means TAB cannot cycle the visibility of the blocks anywhere on the heading line.

hs-isearch-open

This variable specifies the conditions under which incremental search should unhide a hidden block when matching text occurs within the block. Its value should be either code (unhide only code blocks), comment (unhide only comments), t (unhide both code blocks and comments), or nil (unhide neither code blocks nor comments). The default value is code.