Maintain Shortcuts - CSharpCompleterPlusIn addition to the automatic completion sequences that are inserted by the add-in, CSharpCompleterPlus allows you to add your own code sequences that are automatically inserted upon your typing a shortcut sequence that you design. This feature uses Regular Expressions, that you write to recognize the shortcut code and to pick parameters that your Regex recognizes, for a selected shortcut, plugging the parameters into real code and replacing the shortcut that you typed in the code window. In effect, you creat your own keystroke shortcut language to write any number of lines of code for you. CSharpCompleterPlus passes each new line of code through your shortcuts before it takes its own standard code completion analysis. Therefore, it is possible to override any standard completion activity that is built into CSharpCompleterPlus.
Figure 1 shows the Shortcut Maintenance Dialog. It has two tabs. the first is for adding, updating, and deleting your shortcuts. Shortcuts are automatically transformed into real C# code by the use of Regular Expressions. Therefore, it is very helpful if you have a basic knowledge of Regexes. For without some basic knowledge of Regexes, you can't really create new shortcuts. CSharpCompleterPlus comes with a number of shortcuts built in, and you can learn to use Regexes with the ones that are already there. The second tab is a Regex Tester so that you can test your shortcuts as you create them.
Figure 1 - Shortcut Maintenance

The Shortcuts Maintenance tab, shown in Figure 1, has a number of controls described as follows.
Code Shortcuts ListView
This ListView maintains the list of shortcuts that you create. It includes columns for Shortcut Name, Regex, Replacement Code, example Source to parse, Replacement code, and number of lines to move down. Clicking on a desired row in the ListView will cause the contents of the row to be placed into the Text Box controls for easy editing or entry of a new shortcut.
Code Name
You should give each shortcut a name that is meaningful to you or anyone else that might be using CSharpCompleterPlus. You can share your collection of shortcuts with new users of CSharpCompleterPlus. The shortcuts are maintained in a file called "CSShortcuts.xml" in the install folder for CSharpCompleterPlus.
Source to Parse
In this Text Box, enter a sample of the shortcut code that you want your shortcut to look like. This will be used in the tester once you have created the Regex and Replacement Code.
Regular Expression Pattern
Here you will enter the Regex pattern that will recognize your sample shortcut code. You should take care in testing your Regex, but CSharpCompleterPlus does run both the tester and the code analyzer on separate threads, which will be aborted on a timer, should your Regex "hang". This is done to prevent hanging up the Visual Studio IDE.
Replacement Code
Here you should enter the code that you want CSharpCompleterPlus to replace your shortcut code. This is coded as Regex Replacement syntax so that you can pick up parameters or any and all parts of the shortcut line coded at design time in the code window.
Be sure to type spaces where you want spaces to be placed. For example, when you place a blank line between an opening { and a closing }, you should type the number of spaces that you want to indent on that line before new code is typed. If that is the line where the cursor will autmatically be placed, then the cursor will be placed at the end of the spaces, allowing you to begin typing without having to tab or space to where the line would normally line up.
Move Down Lines
This up-down control value tells CSharpCompleterPlus how many lines to move down into the replacement code after it is inserted into your code window. This allows you to place the cursor where you want it placed for immediate entry of new code after your replacement code is inserted into the code window.
Replace or Insert Option
This option determines whether the replacement code overlays your shortcut line or is inserted after the original line. Most of the time you will use the Replace option. An example of the usage of the Insert option can be seen in the "If NoBraces" shortcut.
Move to Tester
Click this button to move a selected shortcut to the tester and automatically change to the Tester tab of the dialog.
Clear Button
Use this button to clear all of the Text Boxes in order to enter a new shortcut into the dialog.
Update Button
Be sure to click this button to update the ListView if you have made any changes to an existing shortcut. Clicking a different row in the ListView without savng your changes or new shortcut will cause the Text Boxes to be overwritten and you will lose your changes.
Add To List Button
After entering a new shortcut into the text boxes, click the Add button to add the new shortcut to the ListView.
Delete Button
This button will delete the currently selected row without prompting you.
Up And Down Buttons
The order of the shortcuts in the ListView is extremely important for two reasons. First, execution of the shortcuts takes place in the order in which they appear in the ListView. Therefore, you want to have the shortcuts ordered in the sequence that they are most likely to make a "hit". This ensures the best performance of the shortcut mechanism. Secondly, when you have similiar shortcuts, such as the example switch shortcuts with more than one number of cases, the order is most important. The one with two cases must be run before the one with one case, otherwise, the shortcut with one case will consume the first case and ignore the other.
Figure 2 - Shortcut Tester

Having moved from the maintenance tab to the Tester tab, you can test your shortcut by clicking the Run button. The Run button will be disabled while the Regex is being run. The Stop button will be enabled while the Regex is running. Should your Regex seem to hang for an unreasonable time, press the Stop button to abort the Regex engine.
You can make changes in the Regex or Replacement code boxes while you are testing the shortcut Regex. To move any changes back to the maintenance tab, click the "Move to Shortcuts" button. The Code Shortcuts tab will come to the front. Make sure that click the Update button before moving to another row in the ListView.
Save to XML
Click this button to save the contents of the ListView to the xml file. Pressing the Close button will save the ListView also.
Top of Page
|