Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Keyboard shortcuts
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Jan 19 2015 :  02:06:07 AM  Show Profile  Reply with Quote
Is it possible to do "Surround With" with keyboard shortcuts I can see a few in the keyboard config , I want a quick way of surrounding with try--catch

Mike

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Jan 20 2015 :  3:30:57 PM  Show Profile  Reply with Quote
No, unfortunately you cannot do that.
However, the snippet "#ifdef (VA X)" can be triggered by the # key (Shift+3). So if you overwrite it, you will be able to trigger it easily.
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Jan 22 2015 :  12:11:02 AM  Show Profile  Reply with Quote
Thanks , I found a way around it , but maybe one to add to that "long" list of nice goodies

Mike
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19004 Posts

Posted - Jan 22 2015 :  1:38:21 PM  Show Profile  Reply with Quote
Did you try editing the "#ifdef (VA)" snippet? This would allow you to do this, so long as you don't mind trading the #ifdef block for the try / catch block.

You can also map a keyboard shortcut to the command VAssistX.VaSnippetInsert, personally I have mapped Ctrl-#, which makes it quick and simple to select one of the VA snippets you have that use $selected$.

We have to be careful "eating" key presses, since when people select code and start typing, they expect the typing to just work.

zen is the art of being at one with the two'ness
Go to Top of Page

Jeff
Whole Tomato Software

USA
260 Posts

Posted - Jan 23 2015 :  12:32:45 PM  Show Profile  Reply with Quote
You can read more about keyboard access to surround-with snippets in the documentation for Visual Assist. In short, keyboard access opens a menu and accelerators make the final selection.

http://docs.wholetomato.com/default.asp?W257
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Jan 23 2015 :  12:39:27 PM  Show Profile  Reply with Quote
An alternative is to modify your try/catch to use $clipboard$ instead of $selection$ -- it will no longer be a Surround With snippet.

To invoke your new try/catch, select your code as you would with a surround with snippet.
Cut.
Invoke the snippet via its shortcut (typing try).

The cut text gets inserted with the snippet.

If you want to keep the Surround With version of the snippet, you can copy/paste it in the snippet editor and modify the second version.


A different alternative as noted by Jeff:
edit the try/catch snippet title by adding '&' before 'y' in the word try.
make your selection.
invoke surround with try: alt+x,w,y

Edited by - sean on Jan 23 2015 1:12:30 PM
Go to Top of Page

Dusan
Whole Tomato Software

Slovakia
177 Posts

Posted - Jan 23 2015 :  1:07:28 PM  Show Profile  Reply with Quote
We have discussed the issue internally and there raised three new potential features:

1) Allow a new shortcut attribute on snippets such the snippet is invoked only when there is a selection that includes a linebreak. So for example, a press of 't' normally inserts a t or overwrites a sub-line selection with t but if there is a multiline selection, then the snippet associated with 't' is invoked (for example, try/catch)

2) (In addition to 1) List a few most-recently-used snippets at the top of the snippet menu, with numbered accelerators. (Maybe just the last snippet.)

3) Provide new VA command (VaSnippetInsertRecent) that would insert last inserted snippet within current VS session. For example, you use VaSnippetInsert, and choose one snippet to apply. If you want to apply same snippet again, you invoke VaSnippetInsertRecent. If you would want to insert different snippet (or start a new row), you use VaSnippetInsert again which also defines new snippet for next calls of VaSnippetInsertRecent. If there would not be any snippet inserted within current VS session, menu with snippets still will be opened as if you use VaSnippetInsert.

Which of these options would you want to see in VA?

Edited by - Dusan on Jan 23 2015 1:13:58 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19004 Posts

Posted - Jan 23 2015 :  5:34:36 PM  Show Profile  Reply with Quote
Personally I am wary of number 1. Technically I like the idea, but especially in the context of shared snippets, it could cause problems, since I am not sure people would ever expect this to happen.

Number 3 sounds the most useful at first, but personally I often trigger a lot of "small" snippets, t for True, without thinking about it, so the last used snippet is not always going to be snippet I expect it to be.

So I find myself preferring number 2, so long as there are a few numbered accelerators. It is not quite so elegant, but probably easier to work with on a day to day basis, and its useful when you are working with a few common snippets. For example I have a "start block" and "end block" snippet pair that I use a lot. I enter them separately since working out the block in advance, and selecting it, proved to be more work than just triggering them separately.

Just my perspective though, I am certainly interested in other perspectives on this.

zen is the art of being at one with the two'ness
Go to Top of Page

Dusan
Whole Tomato Software

Slovakia
177 Posts

Posted - Jan 24 2015 :  03:21:54 AM  Show Profile  Reply with Quote
quote:
Originally posted by feline

Number 3 sounds the most useful at first, but personally I often trigger a lot of "small" snippets, t for True, without thinking about it, so the last used snippet is not always going to be snippet I expect it to be.



Oops, I did not realize that.

Another possible solution for this issue could be to make an option in VA Snippet Editor to permanently or temporarily assign any snippet to # snippet. In case of permanent assignment, change would be written to .TPL file, in case of temporary assignment only information valid for current IDE session would be set by VA Snippet Editor which will tell VA to insert different snippet when # snippet is used. VA Snippet Editor would also have an option to restore # snippet manually.

Edited by - Dusan on Jan 24 2015 03:22:38 AM
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Jan 24 2015 :  10:30:04 AM  Show Profile  Reply with Quote
How about a generic Keyboard shortcut (say Shift Alt S , that brings up a menu of available "Surrounds", presumable context sensitive (eg #region not in the middle of a method)

The menu could show either an index # to select by keyboard or a shortcut eg "tc" for try catch etc

Maybe a bit of a pinch from R# but ...

Mike
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Jan 24 2015 :  10:30:58 AM  Show Profile  Reply with Quote
Sorry I meant , highlight the text you want to surround and then hit Shift Alt S

Mike
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Jan 24 2015 :  1:10:39 PM  Show Profile  Reply with Quote
VAssistX.VaSnippetInsert (VAssistX | Insert VA Snippet) can be bound to your own keybinding. The contents of the menu that appears when the command is invoked is dynamic in that Surround With snippets are listed if there is a selection; if there is no selection, then the surround with snippets are listed in a sub-menu. However, it is not context sensitive at this time (#region will appear regardless of caret scope/position).

If you assign mnemonics to snippet titles, then you can invoke using the letter you assign in the title. For example, in the "#if 0" snippet, I added & to the 0 -- so after the menu appears, pressing 0 invokes the #if 0 snippet.

Adding your own binding to VAssistX.VaSnippetInsert will save you the press of a letter vs using the VAssistX menu (your binding,0 vs alt+x,w,0).

Edited by - sean on Jan 24 2015 1:24:20 PM
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Jan 25 2015 :  05:48:32 AM  Show Profile  Reply with Quote
Thanks Sean , That's perfect it was what I was asking for originally I just didn't realise it was there.

I see that I can add further $selected$ snippets and they show on the list.

Another (Slightly) hidden gem

Ta

Mike
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000