Author Topic: how to auto indent existing block when opening new parenthesis?  (Read 8148 times)

un_ave

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
how to auto indent existing block when opening new parenthesis?
« on: October 13, 2010, 06:19:06 PM »
Hi all,
  I used to have this feature enabled on a previous job, but now I have installed the latest version of SlickEdit and can't seem to remember how to do it.
  Say I have an existing piece of code as follows:

if(val == 1)
{
    val = 2;
}

and then I want to put that block inside an outer parenthesis, there was a feature that when I opened the new parenthesis, before the if(val == 1) it would allow me to highlight as much text as I wanted to be inserted (and tabbed) inside of the new parenthesis...instead of me having to tab each individual line, so that it will end up as follows:

if(key == 0)
{
       if(val == 1)
       {
            val = 2;
        }
}

Anybody have an idea how to enable this 'cool' feature?

Thanks!!

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: how to auto indent existing block when opening new parenthesis?
« Reply #1 on: October 13, 2010, 09:38:40 PM »
You can do a block selection of the beginning of the lines you want to indent. Then hit tab, and a tab will be inserted on each line.

Even better, you can use Dynamic Surround. When you type if followed by a space, Syntax Expansion puts in the rest of your if statement. It also draws some blue lines. If you hit down arrow, the blue line will move down one line and pull that line of code into the newly inserted block. When it hits a block, like the one you're trying to include, it pulls the whole block in and indents it.

afflictedd2

  • Guest
Re: how to auto indent existing block when opening new parenthesis?
« Reply #2 on: October 14, 2010, 04:19:36 PM »
I think it is in
Tools > Options > <Your language> > Indent (where you specify how you want your indentation)
and Tools > Options > <Your language> > Adaptive formatting, check the box to enable adaptive formatting

Ted
« Last Edit: October 14, 2010, 04:21:42 PM by afflictedd2 »

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: how to auto indent existing block when opening new parenthesis?
« Reply #3 on: October 15, 2010, 02:43:31 PM »
I don't think Adaptive Formatting addresses his use case. Adaptive Formatting scans a file when it is opened to determine whether the formatting of the file matches your formatting settings. It then offers to use the formatting of the file or your settings. This is useful if you want to edit an existing file and make sure that you keep the formatting consistent.

For example, if your settings are to indent with spaces and you use 3 spaces, but you open a file that is indented with tabs; Adaptive Formatting will detect that and allow you to easily match the existing formatting of the file. Without this feature, you will have to figure that out on your own and change your settings to match or you'll edit the file in a completely inconsistent manner.

un_ave

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: how to auto indent existing block when opening new parenthesis?
« Reply #4 on: October 18, 2010, 06:42:08 PM »
Thanks for the info. Yes, that's what I want to do, where I open up a new parenthesis and then blue highlighted lines appear and I can hit the down-arrow and it will automatically indent it in the newly created block.
I can't seem to find this option in the "Tools->Option->????". I'm running version: 11.0.2. What is the name of this feature? I tried searching for Dynamic Surround and Syntax Expansion, but neither seemed to describe what I wanted to do.

Any other ideas?

Thanks!!

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: how to auto indent existing block when opening new parenthesis?
« Reply #5 on: October 18, 2010, 09:02:13 PM »
Sorry, Dynamic Surround was added in version 12. You missed that by a smidge!

You may have used Surround With before. That was introduced in v9. With that, you select the text you want surrounded, right-click and select "Surround Selection With" and then pick the alias to use, like "if...".