Jump to Next/Previous Function Definition

I prefer to browse my code manually rather than using MSVC's Wizard Bar. These simple macros move the cursor up and down one function at a time in a cpp file. This is accomplished by searching for a newline character followed by an open brace ('{'). Simple as they may be, they help me get the cursor where I want it quickly and easily. I map these functions to Ctrl-Page Up and Ctrl-Page Down.

Note: They do not work with functions that have the open brace on the function definition line.


Sub GotoFunctionHeaderUp()
'DESCRIPTION: Moves cursor to the previous function definition.
	ActiveDocument.Selection.FindText "^{", dsMatchBackward + dsMatchRegExp
	ActiveDocument.Selection.LineUp
	ActiveDocument.Selection.StartOfLine
End Sub

Sub GotoFunctionHeaderDown()
'DESCRIPTION: Moves cursor to the previous function definition.
	ActiveDocument.Selection.LineDown dsMove, 2
	ActiveDocument.Selection.FindText "^{", dsMatchRegExp
	ActiveDocument.Selection.LineUp
	ActiveDocument.Selection.StartOfLine
End Sub

Josi Manuel Muilledes suggests using DevStudio commands WBGotoNext and WBGotoPrevious from WizardBar category.

Updated on: October 15, 1998.

IT Offers

Comments

  • Thanks

    Posted by jackaliger on 04/15/2007 09:32am

    Thanks

    Reply
  • ThanX~~~

    Posted by Legacy on 04/15/2002 12:00am

    Originally posted by: tomcruse

    nice~~~ ThanX~~~

    Reply
  • Thank you! Nice work!

    Posted by Legacy on 12/05/2001 12:00am

    Originally posted by: B P

    Thank you for this neat and useful macro.

    Reply
  • Good work, i was sooo looking for something like this to help with what i am doing

    Posted by Legacy on 10/18/2000 12:00am

    Originally posted by: Jimbo

    Can u plz tell me what command i can use to strore the current procedure name as a string....
    if i use that function to get to the start of it, how do i then "select" that line?
    (i wanna read in all the parameters of a function, so i can determine if they are inputs or outputs, and then generate a function header, to save me making a comment header my self for every function)
    thank you.
    -Jim

    Reply
  • Great macros

    Posted by Legacy on 09/20/2000 12:00am

    Originally posted by: Peter W. Binsted

    Thank you very much! These work great, I've been trying to get these forever :)

    Reply
  • I like it

    Posted by Legacy on 08/10/2000 12:00am

    Originally posted by: Jorge L. Diez

    How do I make the start of function the top line.

    Reply
  • comment on comment from Jos� Manuel Mu�lledes

    Posted by Legacy on 10/15/1998 12:00am

    Originally posted by: Gert Rijs

    The WBGotoNext/Previous commands only work in a file from the
    active project (annoying if you have several projects in one workspace).
    Keith's macro's will work with any open cpp file.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Go Deeper

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds