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
 Feature Requests
 simple block indentation for Visual Studio 2003
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

steinsomers
Ketchup Master

Belgium
65 Posts

Posted - Nov 04 2005 :  07:36:59 AM  Show Profile
A most welcome feature would be for VAX to emulate the block indentation found in Visual Studio 6 and many other editors. I.e. if you select lines and press Tab, it shifts all text by the same amount to the right. For instance, indenting the body of this function:

void f() {
    /*
     * Blah blah
     */
    g(awfulllylongexpression,
      blob);
}
yields:

void f() {
        /*
         * Blah blah
         */
        g(awfulllylongexpression,
          blob);
}


Visual Studio 2003 ruins it by aligning each line individually to a tab stop, yielding:

void f() {
        /*
        * Blah blah
        */
        g(awfulllylongexpression,
        blob);
}


I've come up with a workaround of settings the indent size to 1 and these macro's tied to the Tab and Shift-Tab key. It allows the tab key to be used for completion in VAX, but it's not quite up to par with some 15 year old editors.
Option Strict Off
Option Explicit On 
Imports EnvDTE
Imports System.Diagnostics
Public Module Keyboard
    Sub indent4()
        Dim selection As EnvDTE.TextSelection
        selection = DTE.ActiveDocument.Selection
        If selection.IsEmpty Then
            DTE.ExecuteCommand("Edit.InsertTab")
        Else
            DTE.UndoContext.Open("indent4")
            selection.Indent(4)
            DTE.UndoContext.Close()
        End If
    End Sub
    Sub unindent4()
        DTE.UndoContext.Open("unindent4")
        DTE.ActiveDocument.Selection.Unindent(4)
        DTE.UndoContext.Close()
    End Sub
End Module

feline
Whole Tomato Software

United Kingdom
15905 Posts

Posted - Nov 04 2005 :  2:27:15 PM  Show Profile
the problem here is that this could be the thin end of the wedge. VA has a "format on paste" option, but all this option does is to call the IDE's format function on the newly pasted code.

here you are asking VA to "argue" with the IDE's formatting code instead of just calling it. people have asked before now for VA to format the code how they want it. i myself have asked for this

the basic problem here is the vast number of options on "proper" formatting. a full blown code formatting program has a staggering number of options, to allow people to fine tune it how they want. given this complexity Support have always said VA will not do this.

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

steinsomers
Ketchup Master

Belgium
65 Posts

Posted - Nov 04 2005 :  3:15:49 PM  Show Profile
I'm very happy VAX allows easily turning off format-after-paste, because there's indeed no way for VS or VAX to get formatting right.
The problem I mention is about keeping the existing formatting.

In the mean time, I digged quite a bit deeper into the macro/Visual Basic/whatever they call it. This works pretty good and doesn't require you to set Indent size to 1 - it does itself, temporarily. The problem with it is that it needs to ensure the file is of type C/C++ and I can't find a proper way to do that.
Option Strict Off
Option Explicit On 
Imports EnvDTE
Imports System.Diagnostics
Public Module Keyboard
    Private Function needFix() As Boolean
        Dim fileName As String
        fileName = DTE.ActiveDocument.Name
        Return Not DTE.ActiveDocument.Selection.IsEmpty And (fileName.EndsWith(".h") Or fileName.EndsWith(".c") Or fileName.EndsWith(".cpp") Or fileName.EndsWith(".inl"))
    End Function
    Sub decentIndent()
        If needFix() Then
            Dim indentSizeProp As EnvDTE.Property
            Dim indentSize As Integer
            DTE.UndoContext.Open("DecentIndent")
            indentSizeProp = DTE.Properties("TextEditor", "C/C++").Item("IndentSize")
            indentSize = indentSizeProp.Value
            indentSizeProp.Value = 1
            DTE.ActiveDocument.Selection.Indent(indentSize)
            indentSizeProp.Value = indentSize
            DTE.UndoContext.Close()
        Else
            DTE.ExecuteCommand("Edit.InsertTab")
        End If
    End Sub
    Sub decentUnindent()
        If needFix() Then
            Dim indentSizeProp As EnvDTE.Property
            Dim indentSize As Integer
            DTE.UndoContext.Open("DecentIndent")
            indentSizeProp = DTE.Properties("TextEditor", "C/C++").Item("IndentSize")
            indentSize = indentSizeProp.Value
            indentSizeProp.Value = 1
            DTE.ActiveDocument.Selection.Unindent(indentSize)
            indentSizeProp.Value = indentSize
            DTE.UndoContext.Close()
        Else
            DTE.ExecuteCommand("Edit.TabLeft")
        End If
    End Sub
End Module
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
15905 Posts

Posted - Nov 06 2005 :  2:59:28 PM  Show Profile
i have often considered digging into the IDE's macro programming language, but i have yet to find the time. can you grab the current file name, and simply base your actions on the file extension?

i know that VA's alt-o feature has been described as something you could implement with a simple macro, comment from here:

http://www.codeproject.com/macro/kingstools.asp

you may find some useful clues / hints in the source code.

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

jpizzi
Tomato Guru

USA
642 Posts

Posted - Nov 07 2005 :  10:31:59 AM  Show Profile
My read of his macro has him checking the extension in the needFix function. He apparently doesn't consider that a "proper way" to do that. Perhaps he is concerned about the reusability of the macro in the general case (people could add some extensions to the list that is identified as C/C++ files and headers - can't they?). Not to mention the already existing extensions .cxx, .c++, and .hxx, just to name a few.

Joe Pizzi
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
15905 Posts

Posted - Nov 07 2005 :  2:48:52 PM  Show Profile
*oops* that is what comes of not reading the macro before posting

with regard to a "proper" way of detecting the file type, VA its self relies on the file extension to work out the file type. this is why there are registry keys holding known extensions.

i have relied on the content of a data file to help me guess its format before now, but that is not really going to work with C++ code, since there is no obvious and really simple test. or at least none that i am thinking of.

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

steinsomers
Ketchup Master

Belgium
65 Posts

Posted - Nov 08 2005 :  04:32:45 AM  Show Profile
The "proper" file type is the one applied by the Visual Studio editor. The maco has to query and change the IndentSize property for the precise file type ("C/C++").

Note that at one point while developing the maco random characters were popping up in the file whenever undoing stuff, without there being an unbalance in the UndoContext statements. Clearly this macro language is pretty unstable so don't start rewriting VAX in it...
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
© 2019 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000