Borland Online And The Cobb Group Present:


March, 1995 - Vol. 2 No. 3

The Borland C++ 4.0 IDE - Selecting columns in source files

If you've ever tried to read someone else's C or C++ source files, you've probably noticed that no two programmers format their source code the same way. However, most of us try to indent nested blocks of code in some kind of consistent manner.

In order to assist you in formatting your source files, a number of programming text editors­­Borland's Brief editor, for example­­provide a feature called column marking. Column marking allows you to select vertical regions of text that are narrower than the editor's maximum line length. In this article, we'll show how you can use the column-marking capability of the editor that's built into the Borland C++ 4.0 Integrated Development Environment (IDE).

Column as you see 'em

When Borland introduced the version 4.0 C++ compiler, it added emulation of the Brief text editor to the IDE. Since column marking has been available in the Brief editor for some time, enabling Brief emulation is the most obvious way to mark columns from the IDE.

Even though it isn't documented, column marking is also available when you're using the standard keyboard mapping file. To enable the column-marking mode, you press [Ctrl][o], release those keys, and then press [c]. The editor will stay in the column-marking mode until you double-click on some text in an editor window. (This changes the selection mode back to the default.)

Vertical mark-it

To try this out, launch the Borland C++ 4.0 IDE. When the IDE's main window appears, choose New from the File menu. When the new editor window appears, enter the function body that appears in Figure A.


Figure A - You can use the IDE's column-marking feature to change the indention of this function's statements.

 void bunnyFooFoo()
{
        int chances(3);
        char prey[] = "field mice";
        while(chances > 0)
        {
        scoop(prey);
        headBop(prey);
        --chances;
        }
        goonTransform();
} 

Once you've entered this code, press [Ctrl][o], and then press [c]. Now, click at the beginning of the first line inside the body of the bunnyFooFoo() function, drag the mouse to the last line inside the body of the function, then drag the mouse four spaces to the right. Release the mouse button.

As you drag the mouse, the IDE will highlight the rectangular region between the first mouse click and the pointer's current position, as shown in Figure B. To delete this region (and therefore unindent these lines by four spaces), choose Clear from the Edit menu.


Figure B - When you enable the column-marking mode, you can select a vertical region of text.

Next, position the mouse pointer at the beginning of the line that contains

scoop(prey);

Click at this point, and then drag the mouse pointer down two lines and to the right two spaces.

Choose Copy from the File menu to copy these spaces to the Clipboard. To indent the lines that appear in the while() expression's block, click at the beginning of the scoop() function's line again, and choose Paste from the Edit menu. When the editor inserts the new spaces into these lines, the while() expression's block will have the proper indention, as shown in Figure C.


Figure C - When you paste a column-marked region into a file, the editor will insert those lines below and to the right of the cursor.

Return to the Borland C++ Developer's Journal index

Subscribe to the Borland C++ Developer's Journal


Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.