HideIfDef

In hide-ifdef-mode, code within #ifdef constructs that the C preprocessor would eliminate may be hidden from view.

Activate it using ‘M-x hide-ifdef-mode’.

The hidden code is marked by ellipses (…). Be cautious when editing near ellipses, since the hidden text is still in the buffer, and you can move the point into it and modify text unawares. You can make your buffer read-only while hide-ifdef-hiding by setting ‘hide-ifdef-read-only’ to a non-nil value.

Luke Lee note:

An extensively rewritten version is uploaded. Here I list some of the enhancements:

#define TESTVAL1 0x123
#define TESTVAL2 291 // 0x123

#define CONCAT(x,y) x ## y

#if CONCAT( TESTVAL1=,=TESTVAL2 )
#error correct
#else
#error wrong
#endif

#if CONCAT( TESTVAL1!,=TESTVAL2 )
#error wrong
#else
#error correct
#endif

after hiding, it will become

#define TESTVAL1 0x123
#define TESTVAL2 291 // 0x123

#define CONCAT(x,y) x ## y

#if CONCAT( TESTVAL1=,=TESTVAL2 )
#error correct
#else...
#endif

#if CONCAT( TESTVAL1!,=TESTVAL2 )...
#else
#error correct
#endif
#ifdef __XXX_HEADER_INCLUDED__...
#endif

for the whole .h file. Now with customization option ‘hide-ifdef-expand-re-inclusion-protection’ it will expand the top level if-part if this option is set to ‘t (default).

Tips:

(unless (assoc 'hide-ifdef-env session-globals-include)
  (push '(hide-ifdef-env 100000 t) session-globals-include))
(setf hide-ifdef-exclude-define-regexp-pattern "DOC_.*")

Compatibility note:

The original “semantic” hack no longer work.

Lisp:hideif.el


CategoryHideStuff