SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: at5dapa1 on October 12, 2006, 01:04:24 PM

Title: surround selection on pressing {
Post by: at5dapa1 on October 12, 2006, 01:04:24 PM
Hi,
if I have a selected text and pres {, I want to automatically surround the selection with braces, like Visual Assist does. I have SE11.02 with CodeWright emulation. I have Finnish keyboard, so in order to get "{", I have to press "AltGr+7".

This is a small macro:

Code: [Select]
_command my_surround_with_braces() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
    _macro('R',1);
    _str seltype;
    seltype = _select_type();
    if((seltype == "CHAR") || (seltype == "LINE") || (seltype == "BLOCK"))
    {
        //say("selection");
        surround_with('braces');
    }
    else
    {
        //say("NO selection!");
        keyin("{");
    }
}

I bind it to {. Now if I press {, it will remove the selection and replace with {.  ???
If I set as binding Ctrl+MButtonDn, or just run the macro from the ListMacro menu, it works. How to solve this?

Thanks,
Daniel

PS: I want to do the same, for surrounding with comments, I want to assign as shortcut /, and if there's any selection then it will be automatically commented, else just will type /.

Title: Re: surround selection on pressing {
Post by: Graeme on October 18, 2006, 12:11:43 PM

It looks like it's not possible to override the binding of { to c-begin.  The option in "file extension setup" via the options button to not "insert braces immediately" didn't work for me either.

Since you have to use ALT-7 to get {, maybe you could just bind your macro to some other key like ALT B perhaps?

Graeme
Title: Re: surround selection on pressing {
Post by: at5dapa1 on October 19, 2006, 06:19:03 AM
Thanks Graeme,
good idea Alt+B (from "Brace")  ;)

With Alt+B is working, but seems that for "{" the macro is not called at all, even into the Bind Command to Key dialog, it still shows me that my macro is binded to "{".

Title: Re: surround selection on pressing {
Post by: Graeme on October 19, 2006, 11:49:26 AM

Yep, same on my system.  Ideally the key binding dialog should give an error message for keys that can't be overridden instead of accepting them, and a list of them added to slick help file in the key binding dialog section  :)

BTW - somehow the name of your function in the keybinding dialog is spelt wrong - you seem to have sprround instead of surround.  I hope ALT+B isn't too inconvenient for you.

Graeme
Title: Re: surround selection on pressing {
Post by: suevian on October 19, 2006, 12:34:55 PM
On my 11.0.2 SHIFT + { is bound to command c_begin.

I modified c_begin a little bit and it works.

Open file c.e and merge with the following:

(Note that I've removed one of the name_info arguments, that's what made it work, but honestly I have no idea what will be the effect of this removal, maybe this is just the place to ask?)

Code: [Select]
_command void c_begin() name_info(','VSARG2_CMDLINE)
{
    typeless expand, be_style, indent_fl;

    //surround with braces if selection
    if (!_isnull_selection ())
    {
        surround_with('braces');
        return;
    }

    parse name_info(_edit_window().p_index) with . expand . . be_style indent_fl .;
    int cfg = 0;
    if (!command_state() && p_col>1) {
        left();cfg=_clex_find(0,'g');right();
    }
    if ( command_state() || cfg==CFG_STRING || _in_comment() ||
        c_expand_begin(expand,p_SyntaxIndent,be_style,indent_fl) ) {
        call_root_key('{');
    } else if (_argument=='') {
        _undo('S');
    }

}

Title: Re: surround selection on pressing {
Post by: suevian on October 19, 2006, 12:39:13 PM
I just noticed you're using "AltGr+7" not SHIFT + {, sorry.

Anyway, maybe you can accomodate the above for your CodeRight emulation and "AltGr+7" way of typing { if this does not work.

Title: Re: surround selection on pressing {
Post by: at5dapa1 on October 19, 2006, 01:07:43 PM
Thanks to all!

... BTW - somehow the name of your function in the keybinding dialog is spelt wrong - you seem to have sprround instead of surround.  ...
Graeme

 :o Graeme you are good! I have to wipe my glasses!  :D
Title: Re: surround selection on pressing {
Post by: hs2 on October 19, 2006, 05:00:44 PM
I think instead of removing a name_info attr. you should add one (VSARG2_MARK).
This is req.d by surround_with().
Code: [Select]
_command void c_begin() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_CMDLINE|VSARG2_MARK)

HS2
Title: Re: surround selection on pressing {
Post by: Clark on October 19, 2006, 05:56:27 PM
Thanks hs2.  You definitely want VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL|VSARG2_CMDLINE.  These flags indicate that the command requires an editor control but also can be executed when the command line has focus.  the VSARG2_MARK flag indicates the no default selection processing code should be executed before the command gets control.
Title: Re: surround selection on pressing {
Post by: hs2 on October 19, 2006, 06:37:35 PM
Oh man .. this is the 1st explanation of the mystic name_info's I've seen (well - I didn't read the whole help) !
And just in 1 sentence which I could also understand ;)
I know some other guys were/are just guessing like me, but intuitively did it right somehow.

Thanks Clark !

HS2