Please enable JavaScript to view this site.

PrimalScript - Help Manual

Navigation: » No topics above this level «

Snippet Editor

Scroll Prev Top Next More

PrimalScript and PowerShell Studio provide a collection of snippets to help you complete common coding tasks quickly. You can use the Snippet Editor to easily edit and create snippets.

About Snippets

Snippets are small pieces of reusable code that can be quickly inserted into your scripts, thus saving you time and reducing errors. This piece, or "snippet" of code, can vary from a full-fledged function to a simple single line statement. Snippets come in a variety of languages such VBScript, PowerShell, C#, etc.

PrimalScript and PowerShell Studio come with extensive libraries of reusable code snippets. You can also save any text or code block as a snippet to automate code development. Snippets can include placeholders; PrimalScript and PowerShell Studio will prompt you to supply values for these when you use the snippet.

Snippet Browser

Use the Snippet Browser to access and manage snippets:

To view the Snippet Browser

On the View ribbon, in the Panels section, select Snippets.

-OR-

On the docking area to the right of the Code Editor, hover over the Snippet Browser tab to un-hide the Snippet Browser.

To create a snippet

Highlight the code you want, right-click and choose Save as Snippet....

To insert a snippet

In the Snippet Browser, locate the desired snippet and either double-click or right-click and select Insert Snippet. The snippet will be inserted in the location of the cursor.

Snippet Editor

The Snippet Editor is a self-contained program within PrimalScript and PowerShell Studio that supports multiple programming languages. Using the Snippet Editor is a fast and easy way to edit existing snippets and to create your own.

The Snippet Editor will launch when you edit an existing snippet or create a new snippet:

The Snippet Editor

The Snippet Editor

Snippet Properties

The top section of the Snippet Editor allows you to enter the following snippet properties:

Title

The name of the snippet.

Shortcut

The text you need to type in the code editor to invoke the snippet.

Description

A short description of the snippet explaining what it does.

Author

The snippet author details.

Help URL

A link to help information. This will be displayed in the code editor.

Language

Set to ’powershell’ for snippets used in PowerShell Studio.

Set to the appropriate language for snippets used in PrimalScript.

Type

This setting defines how the snippet will be displayed in the code editor (inserted into the code, or surrounding existing code). The options are:

oExpansion

Select this if your snippet is intended to be simply inserted into code.

oSurrounds With

Select this if your snippet can surround existing code.

oBoth

Select this if your snippet can be used both ways.

The selection you choose for the Type property will dictate the menu options available when you insert the snippet in the code editor:

Insert Snippet…

Only displays snippets where the 'Type' property is defined as Expansion or Both.

Surround With Snippet…

Only displays snippets where the 'Type' property is defined as Surrounds With or Both.

  If you choose a 'Type' value of Surrounds With or Both you must include the $selected$ placeholder variable* somewhere in your snippet code body, otherwise you may overwrite user code when your snippet is used:

( * Refer to the Built-in Placeholder Variables section below for more information about the placeholder variables provided with the Snippet Editor.)

Snippet Windows

The tabs at the bottom of the Snippet Editor provide more configuration options for your snippets:

References

This section tells PrimalScript or PowerShell Studio what dependencies your snippet has. The assemblies you list here will be loaded into PrimalScript or PowerShell Studio when you use the snippet.

Output

This section is not used for PowerShell snippets.

Variable Details

Before you configure the variable details you must add a placeholder variable to a snippet:

1.Position your cursor in the snippet code editor where you want to insert a variable, then right-click and select Add Variable:

2.Name the variable:

3.The variable will appear in the snippet as $<variable>$ (e.g., $condition$):

4.Configure additional variable properties:

ID

The variable name.

Default

A default value if required.

Function

Not used in PowerShell snippets.

Type

Not used in PowerShell snippets.

Kind

Not used in PowerShell snippets.

Editable

Not used in PowerShell snippets.

ToolTip

Provides some text explaining the purpose of the variable. This helps the snippet user understand how to complete the snippet. PrimalScript or PowerShell Studio will display these tooltips as the user navigates between the placeholders in the code editor.

Imports

This section is not used for PowerShell snippets.

Built-in Placeholder Variables

The Snippet Editor provides two built-in placeholder variables:

$selected$

Allows you to merge code from the code editor into your snippet when it is used. For example, you could create a snippet called ExtractFunction containing this code:

Now you can highlight lines of code and use this snippet to refactor them into a reusable function.

$end$

Specifies where the cursor should be placed when a snippet is inserted into the code editor.

 

 

See also:

Snippet Browser

PrimalScript Editor

Getting Help

 

SAPIEN Technologies, Inc. provides administrative tools to support all of your Windows scripting needs.