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).

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 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.

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. Several variables affect how the hiding is done:

hide-ifdef-env
        An association list of defined and undefined symbols for the
        current project. Initially, the global value of hide-ifdef-env
        is used. This variable was a buffer-local variable, which limits
        hideif to parse only one C/C++ file at a time. 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-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-lines
        Set to non-nil to not show #if, #ifdef, #ifndef, #else, and
        #endif lines when hiding.

hide-ifdef-initially
        Indicates whether hide-ifdefs should be called when Hide-Ifdef mode
        is activated.

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 @ 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

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 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.
Several variables affect how the hiding is done:

`hide-ifdef-env'
        An association list of defined and undefined symbols for the
        current project.  Initially, the global value of `hide-ifdef-env'
        is used.  This variable was a buffer-local variable, which limits
        hideif to parse only one C/C++ file at a time.  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-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-lines'
        Set to non-nil to not show #if, #ifdef, #ifndef, #else, and
        #endif lines when hiding.

`hide-ifdef-initially'
        Indicates whether `hide-ifdefs' should be called when Hide-Ifdef mode
        is activated.

`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))))