Add Surround With ... Option

Started by Arthur, May 15, 2009, 04:11:23 PM

Previous topic - Next topic

Arthur

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?

JJK

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.

Arthur

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 :-\

Arthur

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.

alex

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.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

alex

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.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Arthur

Quote from: alex on May 15, 2009, 04:53:03 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?

alex

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:

Begin Try
    %SelectedText%
End Try
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Arthur

#8
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.

alex

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.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Arthur

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.

QuoteOptions->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

alex

QuoteAlso Begin Tran - Commit Tran is a pair same as Begin Tran-Rollback Tran is.
Schema updated - would be in with new beta.

QuoteHence, 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 ;)
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]