Code Snippets

Parent Previous Next

Code Snippets.

When invoking the menu item Insert Snippets from the Edit Menu the form "Insert Snippets" is presented containing multiple lines of code ready for insertion anywhere in your source code. Each line represent a single snippet, which you can select and insert simply by double-clicking or pressing Enter.

SCRAMBLECODE is deployed with a simple editable text file snippets.txt containing these code snippets, and this file can be edited and extended to include the code you want to use from time to time. The location of this file is specified in Options.

Using Code Snippets.

When the form is opened it can either present all available snippets, or it can use a filter to present only a subset. The filter is editable.

The current editor position of the cursor represents the insertion point where to insert a chosen code snippet. If the cursor doesn't touch any text, then the form is opened without a filter presenting all snippets. If the cursor touches some text, this text is used as a filter and only snippets containing this text in some form are presented. The filter is not case sensitive.


Suppose you write func like this and the cursor | touches this text as shown:



If you then press Ctrl+J to open the list of code snippets, you will be presented with only those snippets that contain this text:

Suppose you select the snippet  Private Function |Foo()\n{\n}  it will be inserted in the editor like this:

 Private Function |Foo()



Notice how the text func was replaced with the snippet, and how the snippet was "unfolded" over several lines as defined by the placeholder \n which represents inserting a new line properly indented. Finally notice how the cursor is repositioned which refer to the | identifying the name as probably the first thing to edit after insertion. The rules for using placeholders are explained next.

Modifying the File.

Please follow this guideline while editing the file snippets.txt:

Placeholders are not present in the inserted text.