Author Topic: Add Surround With ... Option  (Read 764 times)

Offline Arthur

  • Hero Member
  • *****
  • Posts: 624
  • Karma: +1/-0
  • He who is ashamed of asking is afraid of learning.
    • View Profile
    • My Blog
Add Surround With ... Option
« on: May 15, 2009, 03:11:23 pm »
I am missing this feature found in some IDEs: "Surround With..."
To elaborate, it is an option allowing you wrapping a marked region/selection (e.g. some code blocks) or a sentence or a single word, into say a Try-Catch-Finally block (an if-else statement, while-end, etc. perhaps the templates can be used there).

Is that a big deal to have this implemented?

PS: And to my taste it should be under my Right-Click -> More menu, or any better suggestions?

Offline JJK

  • Full Member
  • ***
  • Posts: 151
  • Karma: +2/-0
    • View Profile
Re: Add Surround With ... Option
« Reply #1 on: May 15, 2009, 03:29:10 pm »
Hello Arthur,

it seems to me that Surrounding exists already.
You can see it by searching "surround".
But perhaps it is not as elaborate as you'd like.

Offline Arthur

  • Hero Member
  • *****
  • Posts: 624
  • Karma: +1/-0
  • He who is ashamed of asking is afraid of learning.
    • View Profile
    • My Blog
Re: Add Surround With ... Option
« Reply #2 on: May 15, 2009, 03:42:51 pm »
Hi JJK,

I did searched as you suggested, and came up upon something mentioned "Surround" twice.

The only promising item was "Surround by template" in Text Editor - Code Templates.

However, I still have no idea how do I actually supposed to use it :-\

Offline Arthur

  • Hero Member
  • *****
  • Posts: 624
  • Karma: +1/-0
  • He who is ashamed of asking is afraid of learning.
    • View Profile
    • My Blog
Re: Add Surround With ... Option
« Reply #3 on: May 15, 2009, 03:46:05 pm »
Oh, and may be add another buzz-word functionality called "Refactor" to include the "Surround With..." in there?

Plus obviously some thing more, perhaps based on a new poll?

Reason is I am in the midst of a refactoring effort and missing a few features.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: Add Surround With ... Option
« Reply #4 on: May 15, 2009, 03:53:03 pm »
Hello Arthur,

first chech this link, it would give you some information.

Then, to have this feature working you need to have any template for your syntax with %SelectedText% or %SelectedLine% tag inside (was renamed from %SurroundedText%).
If you have such template, you would get automatically possibilty to use it for surrounding:
  • menu Format -> Surround by template
  • select text and press Ctrl+Space
  • context menu -> sumbenu Format
  • Format context menu = right click keeping Ctrl

for example you can check C++ syntax.

Best regards,
Alex.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: Add Surround With ... Option
« Reply #5 on: May 15, 2009, 03:54:36 pm »
Refactoring requires a real understanding of the language. And this is not possible in generic way, by maybe with syntax dependent script it would be possible.

Offline Arthur

  • Hero Member
  • *****
  • Posts: 624
  • Karma: +1/-0
  • He who is ashamed of asking is afraid of learning.
    • View Profile
    • My Blog
Re: Add Surround With ... Option
« Reply #6 on: May 15, 2009, 04:06:42 pm »
Then, to have this feature working you need to have any template for your syntax with %SelectedText% or %SelectedLine% tag inside (was renamed from %SurroundedText%).
If you have such template...

neither post mentions the file name where to place the new tags into, is this the sql_user.xml?

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: Add Surround With ... Option
« Reply #7 on: May 15, 2009, 04:13:45 pm »
Normally you need to do it in UI:
Tools->Options->Syntax Settings->(your syntax fex T/SQL)->Code Templates.

Then add for new template (or change one of existing) to have something like this:
Code: [Select]
Begin Try
    %SelectedText%
End Try

Offline Arthur

  • Hero Member
  • *****
  • Posts: 624
  • Karma: +1/-0
  • He who is ashamed of asking is afraid of learning.
    • View Profile
    • My Blog
Re: Add Surround With ... Option
« Reply #8 on: May 15, 2009, 04:32:16 pm »
Thank you Alex, I have just tried it, works mostly like a charm, except for only one small thing:
it tries to apply formatting [IMHO], but looks like just to the first subsequent line of code.
Example:

Begin Tran
     SELECT TOP 3000 * [AZ] here's the shift only
FROM my_table
WHERE ...
Commit Tran

I would like it to shift the rest of them or none at all. Ideally it should be a custom setting to do so or not.
Otherwise, today I need to navigate up and move the 2nd line of code left and it will be painful.

PS: Why Begin gets displayed in red color I am not sure.
« Last Edit: May 15, 2009, 04:36:50 pm by Arthur »

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: Add Surround With ... Option
« Reply #9 on: May 15, 2009, 05:45:00 pm »
Begin is red, because corresponding End s not found.
What is this Tran, is it is standard constuct? If yes, you need to update scopes for PL/SQL with it (or send me doc I would update installed schema).   

The reason why it is indented, that HE tries to format selection (also depends on Options->Formatting->Format on every Paste flag, try without it).
So or your code is invalid or scope is not known by HE. If some keywords are formatted and some not, then probablz some of them also not in keywords list.

Best regards,
Alex.

Offline Arthur

  • Hero Member
  • *****
  • Posts: 624
  • Karma: +1/-0
  • He who is ashamed of asking is afraid of learning.
    • View Profile
    • My Blog
Re: Add Surround With ... Option
« Reply #10 on: May 15, 2009, 06:44:03 pm »
Begin Tran is a short form of Begin Transaction - a legitimate keyword [standard consrtuct if you wish] in T-SQL. Also Begin Tran - Commit Tran is a pair same as Begin Tran-Rollback Tran is.
So it is a yes.
I think if you could update the schema it would be better.

Quote
Options->Formatting->Format on after every Paste flag
works as I needed, no more shifting of the first word. Hence, my suggestion, keep it on by default please.
And hey, I have just found out what this option is for :D!

Thank you Alex

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: Add Surround With ... Option
« Reply #11 on: May 16, 2009, 12:32:01 am »
Quote
Also Begin Tran - Commit Tran is a pair same as Begin Tran-Rollback Tran is.
Schema updated - would be in with new beta.

Quote
Hence, my suggestion, keep it on by default please.
It is not working correctly for all syntaxes (formatting does not work correctly), this is why it off by default. I would swtich it on onlz when woukl be sure that result at least in 90% correct ;)

 

Related Topics

  Subject / Started by Replies Last post
6 Replies
1002 Views
Last post May 22, 2011, 04:30:14 pm
by Stefan
2 Replies
341 Views
Last post July 27, 2009, 01:38:15 pm
by alex
0 Replies
834 Views
Last post November 06, 2009, 11:06:13 am
by alex
2 Replies
272 Views
Last post September 03, 2010, 11:29:07 am
by photon
2 Replies
166 Views
Last post June 10, 2011, 11:21:55 pm
by swbrains