C++ Operators Macro

This simple macro will complete C++ operators for you. If you, for example, are going to type the "for" operator, just type "f" or "fo" or "for", hit the shortcut key for this macro and you will have:


for( )
{

} // for

The same macro works for "if", "switch", "while" and "do ... while". Of course, style always the same, and, may be, not your :), but it's easy to edit macro to match your favorite style.

This macro was written and tested under Visual Studio v6.0. To install it you just need to add it text to your current macro file. There are a lot of ways to do it. If you open menu \\Tools\Macro DevStudio will show you a name of a current macro file, that you can edit using any editor, or you can just push button "Edit" :).

Hope, you'll enjoy it macro. If you find any bugs or just a way to improve it (I have 1 day experience with VBS language :)), please, let me know.

Downloads

Download source - 2 Kb


Comments

  • Way to add "if-else"

    Posted by Legacy on 04/24/2001 12:00am

    Originally posted by: Hristo Bojkov

    There is an easy way to add if-else to this macro.  I am
    
    writing this for beginners, like my colegues.

    I decide to short-cut if-else statement to "ie" or "ife".
    If you wish to change them there is no problem. Just change
    the quoted text in case clauses with the text you want.

    When the macro recognized this shortcuts the execution is
    slide different than the "if" only.


    After:
    ' operator if
    Case "i" MySaveOperator = "if"
    Case "if" MySaveOperator = "if"

    Add following lines:
    ' operator if-else
    Case "ie" MySaveOperator = "ife"
    Case "ife" MySaveOperator = "ife"

    Next replace:
    If MySaveOperator = "for" Then
    ActiveDocument.Selection = MySaveOperator + "( ; ; )"
    Else
    ActiveDocument.Selection = MySaveOperator + "( )"
    End If
    Suffics =" // " + MySaveOperator

    With following lines:
    If MySaveOperator = "for" Then
    ActiveDocument.Selection = MySaveOperator + "( ; ; )"
    Suffics =" // " + MySaveOperator
    Else
    If MySaveOperator = "ife" Then
    ActiveDocument.Selection = "if( )"
    Suffics =" // if"
    Else
    ActiveDocument.Selection = MySaveOperator + "( )"
    Suffics =" // " + MySaveOperator
    End If
    End If

    And finally insert following lines:
    If MySaveOperator = "ife" Then
    MyOperator = ActiveDocument.Selection.Text
    ActiveDocument.Selection = MyOperator + "}else { // comment"
    End If

    Before following lines:
    ActiveDocument.Selection.NewLine
    If MySaveOperator = "do" Then
    ActiveDocument.Selection.StartOfLine dsFirstText
    Else
    ActiveDocument.Selection.MoveTo opLine, opColumn
    End If
    ActiveDocument.Selection.FindText "("
    ActiveDocument.Selection.CharRight ,2

    After writing this to the macro body you just need to
    write "ie" or "ife" and press the button to execute the
    macro. Of course write them without quotation marks.

    Reply
  • Abort if there's no match

    Posted by Legacy on 02/24/2000 12:00am

    Originally posted by: Clinton Morell

    After this section:
    
    ___________________________________________________________

    Case "switc" MySaveOperator = "switch"
    Case "switch" MySaveOperator = "switch"
    ' operator do
    Case "d" MySaveOperator = "do"
    Case "do" MySaveOperator = "do"
    ___________________________________________________________

    Add this line:
    Case Else Exit Sub


    That way, the code will stop if it doesn't match one of the
    predefined codewords and you won't get a bunch of
    meaningless punctation marks if you made a mistake.

    Reply
  • visual studio macro's

    Posted by Legacy on 01/27/2000 12:00am

    Originally posted by: R. Aerts

    hello,

    is it possible to change the way visual studio makes
    functions ? (add member function)
    i want it to look like this :

    void CClass::Funtionname ()
    {
    } // FunctionName

    or how visual studio formats a selection ? (edit->advance>format selection)
    i want to change the standard formatting of for example
    if statements...

    Gerards,
    R. Aerts

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

Top White Papers and Webcasts

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

  • Not all enterprise applications are created equal. Sophisticated applications need developer support but other more basic apps do not. With the right tools, everyone is a potential app developer with ideas and a perspective to share. Trends such as low-code development and model driven development are fundamentally changing how and who creates applications. Is your organization ready? Read this report and learn: The seven personas of enterprise app delivery How application ownership is spreading to the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds