Ifdef Balancer button

The Ifdef balancer allows you to manipulate #if, #ifdef and #ifndef blocks. You may:
Balance #ifdef blocks with a click
Navigate #ifdef using a popup
Place #ifdef blocks around the selection

Balancing

To balance an #ifdef, #ifndef or #if block, Command-double-click on the line containing the #if, #ifdef, #ifndef, #else or #endif preprocessor directive.

Eddie will select the block of text contained in the clicked #ifdef/#endif pair. If the #ifdef has a matching #else, only the portion of text up to the #else gets selected. To select both the #ifdef and #else portions of the #ifdef block, double-click the #ifdef line holding down both Command and Control. You may also double-click holding down the Command-Shift modifiers to select the #ifdef and #else/#endif lines with the ifdef text.
The various modifiers used with Command do the following:

Shift forces the inclusion of the #if/#endif lines.
Control forces the inclusion of the alternate #else block.
When double-clicking #else, Option causes the selection of the alternate portion of the #else clause (below the #else)

Here is a summary of the different combinations:

Double-click

Modifiers

Command

#if, #ifdef, #ifndef

Command

Selects the block of text contained within the #ifdef/#endif pair. If the #ifdef contains an #else clause, only selects the block of text up to the #else clause.

#if, #ifdef, #ifndef, #endif

Command-Control

Selects the block of text contained within the #ifdef/#endif pair. If the #ifdef contains an #else clause, both halves of the #ifdef will be selected

#if, #ifdef, #ifndef

Command-Shift

Selects the block of text contained within the #ifdef/#endif pair and the #ifdef/#endif lines. If the #ifdef contains an #else clause, only selects the block of text in the top #else halve.

#if, #ifdef, #ifndef, #else, #endif

Command-Control-Shift

Selects the block of text contained within the #ifdef/#endif pair, including the #ifdef/#endif lines. If the #ifdef contains an #else clause, both halves of the #ifdef will be selected

#else

Command

Selects the block of text contained within the #ifdef/#else pair (the block above the #else statement).

#else

Command-Option

Selects the block of text contained within the #else/#endif pair (the block below the #else statement).


Note that the Ifdef Balancer also balances Obj-C @interface @end and @implementation @end pairs, using the same Command-double click.

Clicking the #ifdef button or choosing "Balance #ifdef" from the Edit menu (Command-Option-B) causes the enclosing #ifdef block to get balanced, much like brackets would when using the Command-B command. Repeating the command will select the next enclosing #ifdef. In our example we can press Command-Option-B twice to first select the "#if SUPPORT_ATTRIBUTED_STRING" block, then again to grow the selection to the "#ifdef USE_NS_TEXT_INPUT_CLIENT" block.

#ifdef menu

Eddie allows you to jump to the various #ifdef blocks in your code the same way you can navigate functions using the #ifdef menu. In the following example, we are about to navigate to the "#ifdef SUPPORT_ATTRIBUTED_STRING" line:

Placing #ifdefs around selected lines

The Ifdef balancer plugin has an array of commands allowing you to use various flavors of #ifdefs around selected lines. In addition to the handy "Place #if DEBUG around selection" (Command-Control-B) and "Place #if 0 around selection" (Control-0), you may also select any text and save it as an #ifdef symbol. In the following example we are going to place #if SUPPORT_ATTRIBUTED_STRING around the selected lines:

You may remember any number of symbols to use with an #ifdef, using the "Use selection as #ifdef symbol" menu item. This menu item is conveniently also available through the Context menu:

The added symbol will show up in the User #ifdef symbols menu:

The symbol will also become the active User #ifdef symbol, ready for use:


You can change the active User #ifdef symbol either from the menu or you can rotate between all the current symbols using Command-Control-I (forward) and Command-Shift-Control-I (backward). The #ifdef symbol that just became active will flash in the status bar for a split second.

This can come handy when going through your source files and placing various ifdefs in the code -- you can just switch back and forth between the desired symbol, select the text and then use the appropriate shortcut to place an #if, #if !, #ifdef or #ifndef around the selection.

Here is an overview of all the shortcuts. As with any shortcut, you may reconfigure these using SetKey in the UserStartup.

Control-0

Place #if 0 around selection

Command-Control-B

Place #if DEBUG around selection

Command-I

Place #if user defined symbol around selection

Command-Shift-I

Place #if !user defined symbol around selection

Command-Option-I

Place #ifdef user defined symbol around selection

Command-Shift-Option-I

Place #ifndef user defined symbol around selection

Command-Control-I

Switch to the next user defined symbol

Command-Shift-Control-I

Switch to the previous user defined symbol