Indenting Starting on the Indent String

Syntax highlighting, code folding, brace matching, code indenting, and function list

Indenting Starting on the Indent String

Postby GhotiHed » Mon May 21, 2007 11:10 pm

I'm currently using Ultra-Edit 32 v12.10a to write C++ code, and I have the following lines in my wordfile.txt file:

Code: Select all
/Indent Strings = "{"
/Unindent Strings = "}"


This provides me with automatically indented code that looks like the following:

Code: Select all
void blahblahdeblah()
{
    if (blahblahagainblah)
    {
        asdfasdf();
    }
    haveacow();
}


This is all well and good, but I've just been handed a project where I need to have the braces indented to match the enclosing code. This means the previous code should appear as follows:

Code: Select all
void blahblahdeblah()
    {
    if (blahblahagainblah)
        {
        asdfasdf();
        }
    haveacow();
    }


I've been looking all over the place, including this forum, for information on how to do this, and the closest I can get is to use the external Artistic Style application to range over my code and redo it. I'd much rather have this done as I go.

Is there something I can set to have the indention level done starting with the indent string, rather than the line after it? Thanks.

Me
User avatar
GhotiHed
Newbie
 
Posts: 1
Joined: Sun May 20, 2007 11:00 pm

Re: Indenting Starting on the Indent String

Postby pietzcker » Tue May 22, 2007 5:22 am

One way that I can think of:

If you remove the braces from the (un)indent strings list and instead use "if" "void" "while" etc. etc. as indent strings, then you'll get the indentation this way. You'll have to "outdent" manually, though.

Any other ideas?
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: Indenting Starting on the Indent String

Postby roland » Tue May 22, 2007 8:48 pm

I am trying, but I can't help myself... Troll alert:

Maybe that GNU style should just be banned?
User avatar
roland
Basic User
Basic User
 
Posts: 30
Joined: Sun Aug 15, 2004 11:00 pm

Re: Indenting Starting on the Indent String

Postby Mofi » Wed May 23, 2007 6:25 am

A possible solution for GNU indenting style is to turn of auto-indent partly for C/C++ with empty indent and unindent strings in the syntax highlighting wordfile and write 2 macros in an automatically loaded macro file with hot keys assigned to the keys used to normally insert a { or }.

The macro can than make the indent and unindent job on pressing of key { or }. Something like that for inserting a { (with real tabs for indenting):

InsertMode
ColumnModeOff
HexOff
IfExtIs "c"
"tab{
"
ExitMacro
EndIf
IfExtIs "cpp"
"tab{
"
ExitMacro
EndIf
"{"

Note: tab must be a real tab character.

And something like that for inserting a } :

InsertMode
ColumnModeOff
HexOff
IfExtIs "c"
IfColNumGt 1
Key LEFT ARROW
IfCharIs 9
Delete
Else
Key RIGHT ARROW
EndIf
EndIf
"}
"
ExitMacro
EndIf
IfExtIs "cpp"
IfColNumGt 1
Key LEFT ARROW
IfCharIs 9
Delete
Else
Key RIGHT ARROW
EndIf
EndIf
"}
"
ExitMacro
EndIf
"}"
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4065
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Syntax Highlighting