Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 OT (Maybe): Macros in VS.NET 2003 are slooooooooow
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

LarryLeonard
Tomato Guru

USA
1041 Posts

Posted - Mar 25 2004 :  10:11:38 AM  Show Profile
I'm 99% sure this has nothing to do with VAX, and 99.9% sure that it's because I've done something stupid, but I'm wondering if anyone else is seeing this.

I had a macro I wrote for VC6 that reformats comments. Nothing fancy or complicated: it just makes each line as long as it can be, up to 80 chars. Pretty simple, and in VC6, it runs virtually instantaneously.

So, I "ported" it to the wonderfully overblown VS.NET macro editor, and, once I finally corrected all the trivial syntax mutations, it runs very slowly. How slowly? It's so slow, I could do it faster by hand. It's so slow, it looks like what they show in bad movies - you know, the cursor moves... one... character... at... a... time...

I checked UseNet, and didn't see any howling about this, which makes me think (a) I've done something stupid that's causing the slowness, (b) we have collectively decided that the .NET IDE is beyond hope, and stopped posting complaints, or (c) it has something to do with VAX (even when disabled).

Before I uninstall VAX to test further, I just wanted to check if anyone else has seen this. TIA.

SvenC
Tomato Guru

Germany
339 Posts

Posted - Mar 25 2004 :  10:14:22 AM  Show Profile
If you paste you macro into this thread I will give it a try...
Go to Top of Page

LarryLeonard
Tomato Guru

USA
1041 Posts

Posted - Mar 25 2004 :  10:22:32 AM  Show Profile
Thanks! (Be warned, I am a lousy macro writer...)


Option Strict Off
Option Explicit Off

Imports EnvDTE
Imports System.Diagnostics


Public Module MyModule

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'DESCRIPTION: Splits C++ style comments over several lines.

    Sub ResplitComments()

        ' The line the user placed us on must start with a comment.
        If ResplitComments_IsComment() = True Then

            ' Scroll up until we come to a non-comment line (or we hit top of file).
            Do

                If ActiveDocument.Selection.CurrentLine > 1 Then
                    ActiveDocument.Selection.LineUp()

                    If ResplitComments_IsComment() = False Then
                        Exit Do
                    End If
                Else
                    Exit Do
                End If

            Loop

            ' We're either on (a) the line above the first comment line, or (b) line
            ' one, which happens to be a comment.  Handle either case, and move down
            ' a line to get to the first comment line.
            If ActiveDocument.Selection.CurrentLine > 1 Or ResplitComments_IsComment() = False Then
                ActiveDocument.Selection.LineDown()
            End If

            ' At this point, we're at the first comment line, which is indented
            ' by some whitespace.  We need to know exactly what that whitespace is,
            ' so that we can start each comment line with it, so that the comment
            ' lines are indented the same.
            ActiveDocument.Selection.StartOfLine()
            ActiveDocument.Selection.WordRight(True)
            sIndenting = ActiveDocument.Selection.Text

            ' If there isn't any leading whitespace we have to be sure not to put
            ' the slashes in there!  Also, there is a special case for a single
            ' leading space (weirdness in how 'WordRight' behaves with a single space).
            If ActiveDocument.Selection.Text = "// " Then
                sIndenting = ""
            End If

            If ActiveDocument.Selection.Text = " // " Then
                sIndenting = " "
            End If

            ' Now we need to know the actual column the slashes start at, so that
            ' we can tell when we've backed up too far.
            ActiveDocument.Selection.StartOfLine()
            ActiveDocument.Selection.FindText("//")
            nIndenting = ActiveDocument.Selection.CurrentColumn

            ' At this point, we're on the first comment line.  Process each line in
            ' succession ('DoCurrentLine' returns false only if it fails to split).
            nFirstLine = ActiveDocument.Selection.CurrentLine

            Do While True = ResplitComments_DoCurrentLine(sIndenting, nIndenting)

                ' If this line has more than 80 chars on it, or the next line is a
                ' comment, then we aren't done yet.
                ActiveDocument.Selection.EndOfLine()

                If ActiveDocument.Selection.CurrentColumn <= 80 Then

                    If ResplitComments_IsNextComment() = False Then
                        Exit Do
                    End If

                End If

            Loop

            ' Done. Scroll up so we can see the whole comment.
            nLastLine = ActiveDocument.Selection.CurrentLine
            ActiveDocument.Selection.GotoLine(nFirstLine)
            ActiveDocument.Selection.GotoLine(nLastLine)
            ActiveDocument.Selection.EndOfLine()
        Else
            ' If the first two non-whitespace chars on this line aren't //, then the user
            ' has placed us on a invalid line for this macro.
            MsgBox("You must place the cursor anywhere inside a set of C++ style comments!")
            ActiveDocument.Selection.StartOfLine()
        End If

    End Sub


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ResplitComments_DoCurrentLine

    Function ResplitComments_DoCurrentLine(ByVal sIndenting, ByVal nIndenting)

        ResplitComments_DoCurrentLine = True

        ' Append the next line to this line (deleting its leading whitespace
        ' and comments markers, and inserting a space), if it's a comment.
        bNextLineIsComment = ResplitComments_IsNextComment()

        If bNextLineIsComment Then
            ActiveDocument.Selection.EndOfLine()
            ActiveDocument.Selection.Delete()
            ActiveDocument.Selection.Text = " "

            Do
                ActiveDocument.Selection.CharRight(True)

                If ActiveDocument.Selection.Text = " " Or ActiveDocument.Selection.Text = "	" Or ActiveDocument.Selection.Text = "/" Then
                    ActiveDocument.Selection.Delete()
                Else
                    Exit Do
                End If
            Loop
        End If

        ' Move to the start of this line and move to the right one char at a time,
        ' until we go too far - then back up to the first whitespace.
        ActiveDocument.Selection.StartOfLine()

        Do
            ' Select the next character on this line, and see that it's not a CR.
            ActiveDocument.Selection.CharRight(True)

            If 0 < Len(ActiveDocument.Selection.Text) Then

                If 13 <> Asc(ActiveDocument.Selection.Text) Then

                    ' Not a CR, so move to the right of it.
                    ActiveDocument.Selection.CharRight()

                    If ActiveDocument.Selection.CurrentColumn > 81 Then

                        ' We've gone too far.  Back up until we hit the first whitespace.
                        Do
                            ActiveDocument.Selection.CharLeft(True)

                            If ActiveDocument.Selection.Text = " " Or ActiveDocument.Selection.Text = "	" Then

                                '??
                                '??ActiveDocument.Selection.CharRight()
                                '??ActiveDocument.Selection.DeleteWhitespace()
                                '??

                                ActiveDocument.Selection.Text = Chr(13) + sIndenting + "// "
                                Exit Function
                            Else

                                ' Be sure we haven't backed up as far as we can go
                                ' and *still* can't find any whitespace - we'll just
                                ' give up.
                                If nIndenting + 1 = ActiveDocument.Selection.CurrentColumn Then
                                    MsgBox("No whitespace to break this line on - aborting!")
                                    ActiveDocument.Selection.StartOfLine()
                                    ResplitComments_DoCurrentLine = False
                                    Exit Function
                                Else
                                    ActiveDocument.Selection.CharLeft()
                                End If
                            End If
                        Loop
                    End If
                Else
                    Exit Do
                End If
            Else
                Exit Do
            End If
        Loop

    End Function


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Does the current line start with a C++ style comment?

    Function ResplitComments_IsComment()

        ResplitComments_IsComment = False

        ' Go to start of line and move right until you run out of whitespace.
        ActiveDocument.Selection.StartOfLine()

        Do
            ActiveDocument.Selection.CharRight(True)

            If ActiveDocument.Selection.Text <> " " And ActiveDocument.Selection.Text <> "	" Then
                Exit Do
            End If

            ActiveDocument.Selection.CharRight()
        Loop

        ' Of course, if you hit a CR, or you're on an empty line, you're done
        ' looking - don't go to the next line.
        If 0 < Len(ActiveDocument.Selection.Text) Then

            If 13 <> Asc(ActiveDocument.Selection.Text) Then

                ' Check that the first two non-whitespace chars on this line are //.
                ActiveDocument.Selection.CharRight(True)

                If ActiveDocument.Selection.Text = "//" Then
                    ResplitComments_IsComment = True
                End If
            Else
                ActiveDocument.Selection.CharLeft()
            End If
        Else
            ActiveDocument.Selection.CharLeft()
        End If

    End Function


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Is the *next* line (if there is one) a comment?

    Function ResplitComments_IsNextComment()

        ResplitComments_IsNextComment = False

        ' See if we're already on the last line in the file.
        nCurrentLine = ActiveDocument.Selection.CurrentLine
        ActiveDocument.Selection.LineDown()
        nNextLine = ActiveDocument.Selection.CurrentLine

        ' If there is a next line, is it a comment?
        'MsgBox("nCurrentLine: " + CStr(nCurrentLine) + " - nNextLine: "+ CStr(nNextLine))

        If nCurrentLine <> nNextLine Then
            ResplitComments_IsNextComment = ResplitComments_IsComment()
            ActiveDocument.Selection.LineUp()
        End If

    End Function

End Module
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Mar 26 2004 :  09:32:28 AM  Show Profile
VAX 1221 definetly has something to do with this. using VS .NET 2003 i am converting some C code from UNIX to C++ for windows, and i was considering the code:


    int nType = 0;          // is there data for this column?
    int nSampleOrigin = 0;  // is there data for this column?
    int nProcedure = 0;     // is there data for this column?
    int nAmount = 0;        // is there data for this column?
    int nCollected = 0;     // is there data for this column?
    int nReceived = 0;      // is there data for this column?
    int nSiteCode = 0;      // is there data for this column?
    int nLabCode = 0;       // is there data for this column?


for each line i wanted to change the type from int to bool, the first letter of the variable names from 'n' to 'b' and the initial value from 0 to false.

so i told VS to record a temporary macro, to simply hold and then play back the set sequence of key presses that will do this, and then move me onto the next line.

VS was very slow to record this macro, although that may simply be my machine. when i can to run this macro (with VAX enabled) it was very slow! i expected this macro to run in a fraction of a second, since the equiventent macro in VIM 6 would execute almost instantaneously.

instead i was able to sit here watching the cursor move around, executing the macro. disabling VAX and then re-running the macro resulted in the macro running a lot faster, at least 50% faster, but still far slower than i would have expected

for reference, i have saved this macro, which produced:

Option Strict Off
Option Explicit Off
Imports EnvDTE
Imports System.Diagnostics

Public Module RecordingModule


	Sub convertIntToBool()
	DTE.ActiveDocument.Selection.CharRight(True, 3)
	DTE.ActiveDocument.Selection.Text = "bl"
	DTE.ActiveDocument.Selection.DeleteLeft
	DTE.ActiveDocument.Selection.Text = "ool"
	DTE.ActiveDocument.Selection.Delete(2)
	DTE.ActiveDocument.Selection.Text = " "
	DTE.ActiveDocument.Selection.Delete
	DTE.ActiveDocument.Selection.Text = "b"
	DTE.ActiveDocument.Selection.WordRight(False, 2)
	DTE.ActiveDocument.Selection.Delete
	DTE.ActiveDocument.Selection.Text = "false"
	DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText)
	DTE.ActiveDocument.Selection.LineDown
	End Sub
End Module


you may notice i hade and corrected a typo while recording this. for some reason most macro's i record contain at least one typo i have to correct

normal editing is fine with VAX enabled, so this speed effect is specific to macros.

zen is the art of being at one with the two'ness
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Mar 26 2004 :  09:36:34 AM  Show Profile
*grrr*
the saved macro didnt work as expected when i played it, so treat it with a degree of caution.

edit:
further, the speed problem isnt reproducable here now i have turned VAX back on. i had to re record the macro, but did this with VAX disabled. i will keep an eye out for this, since i use macros a lot in VIM.

zen is the art of being at one with the two'ness

Edited by - feline on Mar 26 2004 09:39:10 AM
Go to Top of Page

LarryLeonard
Tomato Guru

USA
1041 Posts

Posted - Mar 26 2004 :  09:45:24 AM  Show Profile
One thing I didn't mention in my original post is that I understand that (for now, anyway), we must disable VAX to record or play macros (see: http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=1813). The unbearable slowdown I'm talking about happens with VAX disabled...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Mar 26 2004 :  11:17:55 AM  Show Profile
i have now managed to record and play a temporary macro in VS .NET 2003 WITH VAX enabled.

it is possible that the first set of problems were caused by my workstation giving way under the weight of programs i am running *frustrated* i am not running that much, but VS seems to be very resource hungry.

zen is the art of being at one with the two'ness
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Mar 31 2004 :  07:08:07 AM  Show Profile
following some more experimenting, recording a temporary macro, and playing it back the *first* time is staggeringly slow. playing the same temporary macro again very quickly seems to run at a much better speed.

Larry, is this as bad if you run the macro twice on two different comments in quick succession?

zen is the art of being at one with the two'ness
Go to Top of Page

LarryLeonard
Tomato Guru

USA
1041 Posts

Posted - Mar 31 2004 :  10:26:54 AM  Show Profile
Yup, it's just as bad... I posted this question on UseNet ( http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&safe=images&selm=27270a53.0403260840.9d2af21%40posting.google.com ), and got no response, so it must just be my machine...

God I hate computers...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Mar 31 2004 :  11:13:58 AM  Show Profile
what i am currently doing is slowly driving me around the bend, i could do with a change of pace. i presume that a comment made up of a series of short lines will be a valid test case. i will have a go at reproducing this for you.

since i am not yet a VS macro expert, will it be happy with a comment like:

// this is my
// test comment to see how this is
// going to work on this machine, since if it
// happens here as well that is info


also, do i select the comment then run the macro? or just position my cursor in the comment before running it?

zen is the art of being at one with the two'ness
Go to Top of Page

LarryLeonard
Tomato Guru

USA
1041 Posts

Posted - Mar 31 2004 :  11:20:26 AM  Show Profile
Yes, that's exactly the kind of comment I'm trying to "clean up". Just position your cursor anywhere in the comment before running it. Thanks!
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Mar 31 2004 :  11:55:08 AM  Show Profile
*puzzled expression*

running VS .NET 2003, i have opened the Macro Explorer, and under MyMacros i have created a new thing called "commentCompress". under this thing i have created a macro, which is now called "ResplitComments".

then i went into edit ResplitComments, and i pasted the entire macro from this tread. when i right click on ResplitComments and select run, with my cursor in the middle of the comment from this thread, nothing happens.

i suspect i havent plugged this macro into VS correctly. but if so, then what did i do wrong?

at the bottom of this macro i have edited it to say:

Public Module commentCompress

    Sub ResplitComments()

    End Sub
End Module


however this doesnt seem to be working

zen is the art of being at one with the two'ness
Go to Top of Page

LarryLeonard
Tomato Guru

USA
1041 Posts

Posted - Mar 31 2004 :  12:00:57 PM  Show Profile
Yeah, I remember flailing around with names of modules and things to get it to work. Wish I could remember exactly what I did. All I remember is that the way things are named does *not* work the way you would think it does... shocking, I know. Maybe a reboot is in order...

The .NET IDE sucks so hard, I think WT should consider just creating a new IDE from scratch. The worst anyone could do would be to come up with something half-assed thats full of bugs and almost unusable, and that's what we have now, so at least we wouldn't be any worse off. I'm sure WT could do much better...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Apr 01 2004 :  04:59:46 AM  Show Profile
initially i dont know how to get VS to recognise and run this macro

still, i am a serious macro user in VIM, so it is only a matter of time until i teach myself how macro's work in VS. given how much like VB they look this might be quite a long time, but it is bound to happen. i will have another go at reproducing this when i have worked out how to run the macro.

as for the IDE, you are so right!

zen is the art of being at one with the two'ness
Go to Top of Page

support
Whole Tomato Software

5566 Posts

Posted - Apr 01 2004 :  6:55:58 PM  Show Profile
Build 1225 increases speed of recording and playback of macros when VA X is loaded.

Whole Tomato Software, Inc.

Edited by - support on Apr 05 2004 10:51:28 PM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000