Pauli's software ->Vedit resources -> C Tools 03. 08. 2011  

C-Tools

Collection of Vedit macros and other resources for C programming.

This package contains useful resources for a C programmer. From a special user menu, you can easily run the macros included. In addition, there is an enhanced template editing macro, and keyboard configuration file for C. See below for the descriptions of each file.
For easy download, all the macros and other files are packed in the file ctools24.zip. Click the link below to download the package.

Download Download ctools24.zip   -   V2.4   -   03.08.2011   -   24.0 K   -   Vedit 6.1

------

Vedit 6.2: This package has been tested with Vedit 6.15. Most macros can be used with Vedit 6.2, too. Some of the macros are obsolete on V6.2 since the equivalent macro is included as standard (cfunc2.vdm, c_indent.vdm). In Vedit 6.2, some of the items in User menu have been moved to Tools menu.

Old versions: Most of the functions should work with older Vedit versions, too. However, if you have an older version and you encounter some compatibility problems, you can donwload the old version of C-Tools here:

Download Download ctools10.zip   -   V1.0   -   14.05.2001   -   16.5 K   -   Vedit 5.1.

======

Descriptions of the files in CTOOLS24.ZIP:

======

Documentation

c_tools.txt - Description of the keyboard commands and menu functions, as well as documentation for the macro search_inc.vdm.

cfunc.chm - Help file for cfunc2.vdm. Can be called from the macro by clicking on [Help] button, or by double-clicking on the file name on Windows Explorer.

search_inc2.chm - Help file for search_inc2.vdm.

------

User Menu for C

C_User.mnu is a user menu adjusted for C programming. Replaces the standard User menu. Use this menu as it is, or copy the lines of interest to your own User Menu.
From this menu, you can easily call the macros below and perform other functions useful for C programming. Tip: use the macro preset.vdm to load this menu and to name it "C-User".

  The items in the menu are:

*) These macros can be found at other parts of my site. Click the link to see description.
1)  Standard vedit function.
2)  Requires ctags.vdm v2.2 or later (Vedit 6.2).

C user menu

C_USER.MNU   -   V2.2   -   Vedit: 5.0

C Keyboard file

C.KEY is Keyboard definition for C programming. Based on Vedit NORMAL.KEY configuration, but adds some useful keyboard macros, and uses the C_user.mnu above. You can use this keyboard file as it is, or just copy those keyboard macros you want to and add them in your own keyboard file.

Some of the new features include:

Alt-* Quick C comment
Alt-1 Comment-out a line and move to next line
Alt-2 Un-comment a line and move to next line
Alt-3 Highlight C block {...{...}...}
Alt-4 Highlight text inside parentheses (...)
Alt-5 Comment-out block using #if 0
Ctrl-7 Insert pair of curly braces { }
Alt-7 Insert lines with curly braces
Ctrl-8 Insert pair of parenthesis ( )
Alt-8 Insert pair of square braces [ ]
Alt-; Go to end of line and insert a semicolon
Numpad 5 Quick C++ comment
Numpad + Search again / search block, forward
Numpad - Search again / search block, backward
Numpad Enter     Go to end of line and insert newline
Numpad * Visual text register insert (calls t_reg.vdm)
F11 Visual bookmarks (calls markers.vdm)
(see the menu) Hotkeys for calling C-user menu functions

C.KEY   -   V1.2   -   Vedit 6.1

-----
Template editing
-----

C Template Editing macro

C123.VTM is enhanced version of the C.VTM template macro that comes with Vedit. The template macro expands C keywords while you type, inserts parentheses and creates indent for flow control commands. This version has the following enhancements:

You can change the indenting style by selecting "C macro setup" in the C-User menu (this calls the macro C_setup.vdm).

Click here for full list of keywords expanded by the template macros.
Click here for template edit example on how keyword "for" is expanded.

(This macro replaces the three template macros C1.VTM, C2.VTM and C3.VTM in some earlier versions of my C-Tools package.)

C123.VTM   -   V2.2   -   08. 02. 2004   -   Vedit 6.02

Macros

Matching #if

c_ifs.vdm finds the matching pair for #if, #else or #endif. If the cursor is on a line that contains #if, the matching #else or #endif is searched. If the cursor is on a line that contains #else, the matching #endif is searched. If the cursor is on a line that contains #endif, the matching #if is searched.

Handles nested #if blocks. Now supports makefile, too (ifeq,ifdef,ifndef).

C_IFS.VDM   -   V1.5   -   07. 09. 2010 -   Vedit 5.00

Show active #if's

Show_Ifs.vdm opens a window that displays all the #if lines that are effective at the current cursor position. This is an easy way to find out if the current line would be included in conditional compilation or not. Press any key to close the window.

SHOW_IFS.VDM   -   V1.3   -   18. 10. 2010   -   Vedit 6.00

Show switch/case

Show_switch.vdm displays the context of current cursor location. The macro opens a window that displays all the switch, case, if, while etc. lines and the function definition within which the current cursor location is. (Originally, this macro only displayed switch...case lines, but I later expanded it to be more generic.)

Press Space or Esc to close the window, or cursor up/down to select a line and then Enter to go to that line.

SHOW_SWITCH.VDM   -   V1.1   -   17. 12. 2008   -   Vedit 6.00 NEW

Check parentheses in C source

C_paren.vdm checks that all parentheses ()[]{} in C source file have a matching pair. (Works quite well on Vedit macros, too.) In addition, checks strings ("), C comments (/*...*/) and #if...#endif pairs. Parentheses inside strings or C or C++ comments are ignored. If an error is found, cursor is moved to the error location. You can then correct the error, or continue checking from current cursor location. Can be called from Wildfilew.vdm to check multiple files.

(Note: for checking parentheses in text files, see chk_paren.vdm) in Misc Macros section.

C_PAREN.VDM   -   V3.2   -   6. 11. 2007   -   Vedit 5.00

C function auto complete

C_autoc.vdm completes any function name in your program. Put this function in the User-menu and configure e.g. Ctrl-TAB key to this menu function. Now you can just type first few characters of your function name, then press Ctrl-TAB and it is completed like magic. Parenthesis are included, too. If your function has more than 1 parameter, commas are included automatically to remind you about the parameters.

If you have more than one function that matches with the characters you typed, the status line shows message such as "Match 1 of 4". You can then press Ctrl-TAB again for next match and so on. (Use Undo key to display previous match.)

This function uses the TAGS database created with the Ctags.vdm macro that comes with Vedit.

C_AUTOC.VDM   -   V1.2   -   15. 02. 2007   -   Vedit 5.20

C Function Select

cfunc2.vdm is an enhanced version of the cfunc.vdm macro that comes with Vedit. The macro opens a window which displays a list of all the C functions in the file. You can use cursor keys to select a function, then press Enter to go to the location of the function definition in the file.

Some of the enhanced features:

šIf the file contains large number of functions, it may be difficult to locate the function you are searching. On cfunc2.vdm, you can type search string on status line at any time. The functions that do not contain the search string will change color and the cursor moves to first matching line. You can then either type more characters to narrow the search, or move cursor down/up to pick any of the matching functions (non-matcing lines are skipped). Press Backspace to clear the search.

CFUNC2.VDM   -   V2.5   -   15. 12. 2010   -   Vedit 6.1

Re-indent

C_indent.vdm performs smart indent for C programs. May be used for editing Vedit macros, too.

Special entry points are available by calling a label. Call label CURRENT to only indent current line without moving to next line. Call label ADJUST_BLOCK to adjust the indent of the whole block without changing relative indent within the block.

C_INDENT.VDM   -   V1.7   -   31. 12. 2010   -   Vedit 6.1

C Macro Setup

Selecting indent mode

C_setup.vdm allows you to configure the operation of some C-related macros, using dialog boxes. This macro replaces my old Ind_mode.vdm macro (which configured the indent mode only). You can configure the following functions:

First, you select which one of the above settings you want to setup. A new dialog box opens, depending on your selection. For cfunc2.vdm, the macro calls the internal setup function of cfunc2.vdm. The other settings are done by C_setup.vdm itself.

The currently selected settings are read from the macro being configured and used as defaults in the dialog box. After you have selected your choices and click OK, C_setup.vdm stores the new values by modifying the configuration option in the macro code.

C_SETUP.VDM   -   V2.0   -   10. 04. 2007   -   Vedit 6.0 (Win)

---

Go to file

GotoFile.vdm opens another file based on the contents of current file. It can be used with Wildfile search results, Lint output and diff output, and for ctags lookup.

This macro is called when you select "Lookup in Ctags" on the C-User menu, or if you press Ctrl-F12. On the standard User menu which comes with Vedit, that menu option calls directly the macro utags.vdm. Using GotoFile.vdm allows this function to be expanded to some additional uses.

In Wildfile search results display (search.tmp), move cursor to a line that contains the search result you are interested in, and press Ctrl-F12. The searched file is opened and the cursor is moved to the specified line. This is a quick way to go to the location where searched string was found. The same method can be used with diff (or cvs/pvcs diff) output file (*.dif). In this case GotoFile.vdm calls dif_gto.vdm (below).

If you call this macro in any other file, utags.vdm is called.

GOTOFILE.VDM   -   V1.3   -   15. 02. 2010   -   Vedit 6.10

GotoFile support for diff output

dif_gto.vdm - Go to line referred in diff output or PVCS difference output file.
When the output of diff file compare utility (or PVCS difference) is viewed on the current buffer, you can move cursor to a line of interest and call this macro. The destination file is opened and the cursor is moved to location referenced on the line.

This function is called (via GotoFile.vdm) when you select option "Lookup in Ctags" on the User menu, and the current file has an extension .dif. On Vedit 6.20 or later, this macro can be called from double-click event by setting Vedit string value DBL_CLICK_MACRO.

DIF_GTO.VDM   -   V1.0   -   10. 11. 2003   -   Vedit 5.0

Open include file

Search_inc.vdm - Search and open include file pointed by cursor.
Put cursor on the line containing include statement and call this macro (Alt-F12). The include file is opened immediatelly.

The file is searched within include directories listed in a file include.lst. If the filename is enclosed in quotes " ", the file is first searched from the source file's directory. If the filename is enclosed in arrow braces < >, it is only searched from the directories listed in the include.lst.

If you list the directories in the same order as you do for your compiler, the macro uses same search order as your compiler would use. Thus, if you have multiple include files with same name, the correct one is automatically opened.

If a block is highlighted, it is used as filename even if it is not enclosed in quotes or arrow braces. If file is not found, a dialog opens allowing you to edit the filename or browse for the file.

For more detailed description of this macro, see the file c_tools.txt included in this package.

Note: This macro is obsolete since the same functionality is available in search_inc2.vdm below. However, it is still included here since it is simpler and thus may be used for starting point for your own macros.

SEARCH_INC.VDM   -   V1.3   -   05. 12. 2006   -   Vedit 6.1

Search in include files

Search_inc2 is an expanded and enhanced version of search_inc.vdm macro above.

SEARCH_INC2.VDM   -   V2.1   -   28. 10. 2010   -   Vedit 6.1 NEW