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

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds