Function: hs-indentation-mode

hs-indentation-mode is an autoloaded, interactive and byte-compiled function defined in hideshow.el.gz.

Signature

(hs-indentation-mode &optional ARG)

Documentation

Toggle indentation-based hiding/showing.

This is a minor mode. If called interactively, toggle the Hs-Indentation mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable hs-indentation-mode(var)/hs-indentation-mode(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/hideshow.el.gz
;;;###autoload
(define-minor-mode hs-indentation-mode
  "Toggle indentation-based hiding/showing."
  :group 'hideshow
  (if hs-indentation-mode
      (progn
        (setq hs-indentation--store-vars
              (buffer-local-set-state
               hs-forward-sexp-function
               (lambda (_)
                 (let ((size (current-indentation)) end)
                   (save-match-data
                     (save-excursion
                       (forward-line 1) ; Start from next line
                       (while (and (not (eobp))
                                   (re-search-forward hs-block-start-regexp nil t)
                                   (> (current-indentation) size))
                         (setq end (point))
                         (forward-line 1))))
                   (when end (goto-char end) (end-of-line))))
               hs-block-start-regexp (rx (0+ blank) (1+ nonl))
               hs-block-end-regexp nil
               hs-adjust-block-end-function
               ;; Adjust line to the "end of the block" (Usually this is
               ;; the next line after the position by
               ;; `hs-forward-sexp-function' with the same indentation
               ;; level as the block start)
               (if hs-indentation-respect-end-block
                   (lambda (beg)
                     (save-excursion
                       (when (and (not (eobp))
                                  (forward-line 1)
                                  (not (looking-at-p (rx (0+ blank) eol)))
                                  (= (current-indentation)
                                     (save-excursion
                                       (goto-char beg)
                                       (current-indentation)))
                                  (progn (back-to-indentation)
                                         (not (hs-hideable-block-p))))
                         (point))))
                 hs-adjust-block-end-function)
               ;; Set the other variables to their default values
               hs-looking-at-block-start-predicate #'hs-looking-at-block-start-p--default
               hs-find-next-block-function #'hs-find-next-block-fn--default
               hs-find-block-beginning-function #'hs-find-block-beg-fn--default
               hs-c-start-regexp (string-trim-right (regexp-quote comment-start))))
        ;; Refresh indicators (if needed)
        (when (and hs-show-indicators hs-minor-mode)
          (hs-minor-mode -1)
          (hs-minor-mode +1)))
    (buffer-local-restore-state hs-indentation--store-vars)
    (when (and hs-show-indicators hs-minor-mode)
      (hs-minor-mode -1)
      (hs-minor-mode +1))))