Function: hide-ifdef-mode

hide-ifdef-mode is an autoloaded, interactive and byte-compiled function defined in hideif.el.gz.

Signature

(hide-ifdef-mode &optional ARG)

Documentation

Toggle features to hide/show #ifdef blocks (Hide-Ifdef mode).

Hide-Ifdef mode is a buffer-local minor mode for use with C and C-like major modes. When enabled, code within #ifdef constructs that the C preprocessor would eliminate may be hidden from view.

Use C-c @ h (hide-ifdefs) to hide ifdefs and C-c @ h (hide-ifdefs) to show them.
Use M-x hif-show-all (hif-show-all) to show all ifdefs.

Several variables affect how the hiding is done:

hide-ifdef-env
        An association list of defined and undefined symbols for the
        current project. Use C-c @ d (hide-ifdef-define) and C-c @ u (hide-ifdef-undef) to update the value of
        this list with defined or undefined symbols.
        We've extended hideif to support parsing a C/C++ project
        containing multiple C/C++ source files opened simultaneously in
        different buffers. Therefore hide-ifdef-env can no longer be
        buffer local but must be global.

hide-ifdef-initially
        Customize this to a non-nil value to cause ifdefs be hidden as
        soon as hide-ifdef-mode(var)/hide-ifdef-mode(fun) is turned on.

hide-ifdef-lines
        Customize to non-nil to hide the #if, #ifdef, #ifndef, #else,
        and #endif lines when hiding ifdefs.

hide-ifdef-define-alist
        An association list of defined symbol lists.
        Use hide-ifdef-set-define-alist to save the current hide-ifdef-env
        and hide-ifdef-use-define-alist to set the current hide-ifdef-env
        from one of the lists in hide-ifdef-define-alist.

hide-ifdef-read-only
        Set to non-nil if you want to make buffers read only while hiding.
        After show-ifdefs, read-only status is restored to previous value.

C-c @ C hif-clear-all-ifdef-defined
C-c @ C-d hide-ifdef-block
C-c @ C-q hide-ifdef-toggle-read-only
C-c @ C-s show-ifdef-block
C-c @ C-w hide-ifdef-toggle-shadowing
C-c @ C-x C-q hide-ifdef-toggle-outside-read-only
C-c @ D hide-ifdef-set-define-alist
C-c @ U hide-ifdef-use-define-alist
C-c @ d hide-ifdef-define
C-c @ e hif-evaluate-macro
C-c @ h hide-ifdefs
C-c @ s show-ifdefs
C-c @ u hide-ifdef-undef

This is a minor mode. If called interactively, toggle the Hide-Ifdef 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 hide-ifdef-mode(var)/hide-ifdef-mode(fun).

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

View in manual

Probably introduced at or before Emacs version 22.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/hideif.el.gz
;;;###autoload
(define-minor-mode hide-ifdef-mode
  "Toggle features to hide/show #ifdef blocks (Hide-Ifdef mode).

\\<hide-ifdef-mode-map>Hide-Ifdef mode is a buffer-local minor mode for use with C and
C-like major modes.  When enabled, code within #ifdef constructs
that the C preprocessor would eliminate may be hidden from view.

Use \\[hide-ifdefs] to hide ifdefs and \\[hide-ifdefs] to show them.
Use  \\[hif-show-all] to show all ifdefs.

Several variables affect how the hiding is done:

`hide-ifdef-env'
        An association list of defined and undefined symbols for the
        current project.  Use \\[hide-ifdef-define] and \\[hide-ifdef-undef] to update the value of
        this list with defined or undefined symbols.
        We've extended hideif to support parsing a C/C++ project
        containing multiple C/C++ source files opened simultaneously in
        different buffers.  Therefore `hide-ifdef-env' can no longer be
        buffer local but must be global.

`hide-ifdef-initially'
        Customize this to a non-nil value to cause ifdefs be hidden as
        soon as `hide-ifdef-mode' is turned on.

`hide-ifdef-lines'
        Customize to non-nil to hide the #if, #ifdef, #ifndef, #else,
        and #endif lines when hiding ifdefs.

`hide-ifdef-define-alist'
        An association list of defined symbol lists.
        Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env'
        and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env'
        from one of the lists in `hide-ifdef-define-alist'.

`hide-ifdef-read-only'
        Set to non-nil if you want to make buffers read only while hiding.
        After `show-ifdefs', read-only status is restored to previous value.

\\{hide-ifdef-mode-map}"
  :group 'hide-ifdef :lighter " Ifdef"
  (if hide-ifdef-mode
      (progn
        ;; inherit global values

        ;; `hide-ifdef-env' is now a global variable.
        ;; We can still simulate the behavior of older hideif versions (i.e.
        ;; `hide-ifdef-env' being buffer local) by clearing this variable
        ;; (C-c @ C) every time before hiding current buffer.
;;      (setq-local hide-ifdef-env
;;           (default-value 'hide-ifdef-env))
        (setq hide-ifdef-env (default-value 'hide-ifdef-env))
        ;; Some C/C++ headers might have other ways to prevent reinclusion and
        ;; thus would like `hide-ifdef-expand-reinclusion-guard' to be nil.
        (setq-local hide-ifdef-expand-reinclusion-guard
                    (default-value 'hide-ifdef-expand-reinclusion-guard))
        (setq-local hide-ifdef-hiding
                    (default-value 'hide-ifdef-hiding))
        (setq-local hif-outside-read-only buffer-read-only)
        (setq-local line-move-ignore-invisible t)
        (add-hook 'change-major-mode-hook
                  (lambda () (hide-ifdef-mode -1)) nil t)

        (add-to-invisibility-spec '(hide-ifdef . t))

        (if hide-ifdef-initially
            (hide-ifdefs)
          (show-ifdefs)))
    ;; else end hide-ifdef-mode
    (kill-local-variable 'line-move-ignore-invisible)
    (remove-from-invisibility-spec '(hide-ifdef . t))
    (when hide-ifdef-hiding
      (show-ifdefs))))