SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: Dan112123 on July 03, 2008, 12:36:13 AM

Title: Comment for closing paren
Post by: Dan112123 on July 03, 2008, 12:36:13 AM
Did anybody write a macro that would put a comment at the end paren of a block with the name of the block?

For example for this code:

for ()
{
}

if I run the macro  at the }  I would get

for ()
{
} // for

I really liked that functinality in SourceInsight and kind of miss it.
Title: Re: Comment for closing paren
Post by: Graeme on July 03, 2008, 02:45:18 AM
An editor I sometimes use shows the "start" of the block as a "pseudo comment" on screen at the end of the block for you, without requiring it to be physically in the source file, with the pseudo comment shown in a different colour.

Graeme
Title: Re: Comment for closing paren
Post by: AxeMaster on July 03, 2008, 05:38:31 PM
It's fairly trivial to write an alias to do what you want...  The only problem is that it may over-ride or block some of the more sophisticated built-in alias/expansions.

I did this quickly to validate my thoughts:

Go to Tools, Options, Languages, Application Languages, C/C++, Aliases.

Click 'New' and enter 'for' as the alias name.

In the expansion text box, enter:

for ( %\c; %\c; %\c )
{
%\i%\c
} /* for */


I also created one called 'if' like this:


if ( ( %\c ) )
{
%\i%\c
} /* ...if */
else
{
%\i%\c
} /* ...else */


There may be more sophisticated ways to patch the default aliases/expansions supplied with VS for C/C++, but I'm not that familiar with it yet.  :)
Title: Re: Comment for closing paren
Post by: Dan112123 on July 03, 2008, 07:07:50 PM
It's fairly trivial to write an alias to do what you want...  The only problem is that it may over-ride or block some of the more sophisticated built-in alias/expansions.

Thanks Axe for your answer, but I'm not looking for an alias. I'm looking for a macro that would modify an existing code and add a comment after the code has been written already.
let's say I alreayd have code that looks like this

if ()
{
}

then I put my cursor on the last bracket

run my macro and get this

if ()
{
} // if ()

Does that make sense?
Title: Re: Comment for closing paren
Post by: chrisant on July 03, 2008, 08:32:35 PM
SourceInsight doesn't actually insert the " // if ()" into the file, it just paints it on the screen.

Personally, I do not want that kind of markup saved in the actual source code file.  But I would enjoy seeing one or more mechanisms to paint that type of thing.  Here are some of the recent suggestions for how to show similar information:

Title: Re: Comment for closing paren
Post by: AxeMaster on July 03, 2008, 09:16:12 PM
Ah sorry, I didn't read close enough the first time.  Makes sense.

Is the macro language capable of doing things like "just painting?"  That would be a fun to write a little script like that. :)

Is there a browsable archive of user-submitted macros/programs for VS like they have on the VIM site?

Title: Re: Comment for closing paren
Post by: at5dapa1 on July 13, 2008, 07:38:10 AM
Maybe other way to achieve similar result is if SlickEdit would show the opening brace in the Preview window, when the cursor is on closing brace. Then it would be very easy to see also the if, for, etc.
At the moment SlickEdit is already coloring the opening brace, so maybe frome there someone knows how to trigger Preview window too.
Title: Re: Comment for closing paren
Post by: chrisant on July 13, 2008, 06:41:34 PM
That is interesting, and it might work for some folks.  It misses out on the key advantages of showing the "// if ()" inline, though:

1.  When you see the "// if ()" inline you have an easy visual cue without needing to move your eyes at all (it's not even so much moving the eyes away, it's the moving the eyes back).
2.  Some people have the Preview window normally auto-hidden (like me).

Also, the Preview window would not help show indentation level (the colored lines I mentioned help with that).
Title: Re: Comment for closing paren
Post by: MindprisM on July 14, 2008, 01:45:50 AM
Solution:
http://community.slickedit.com/index.php?topic=3673.0 (http://community.slickedit.com/index.php?topic=3673.0)
Title: Re: Comment for closing paren
Post by: chrisant on July 14, 2008, 04:40:31 AM
It's a partial solution, but involves invoking a macro to modify the source file (which in most multi-person teams is going to be a no-no).  The SourceInsight feature we were discussing does not modify the source files, it merely renders extra tags after closing braces (the tags are only rendered, they are not part of the source file).
Title: Re: Comment for closing paren
Post by: hs2 on July 17, 2008, 01:01:17 AM
One possible short term solution could be to add a non-save line right below/above the ending/starting statement e.g. if the matching statement line is not visible. It might be neccesary to override the buffer props accordingly if adding a non-save line also sets 'p_modify'. This could be hooked into the hilite matching parens functionality. Just an idea...
HS2