How to enable and use Code Snippets in the IDE

As of Clarion 7 the IDE now provides support for code snippets. There are a few things you need to do to get these to work effectively, the below is a copy from my original blog post at ClarionEdge.

How to Enable Code Snippets

Add .appclw and .APPCLW (no “*” in front of it) to the list in the Code Snippets setup. This tells the IDE to show snippets in the code completion list for the embed editor and the embeditor.

In my IDE I have this set of extensions for Clarion snippets:

.clw;.CLW;.appclw;.APPCLW

##Using Code Snippets

If you are in the “Embed Editor” then the Ctrl+J shortcut will bring up the snippets list. If you are in the Embeditor then Ctrl+J takes you to the “next filled embed” until you get to the last one and then Ctrl+J pops up the snippets.

The Clarion Binding in the IDE also includes an option to show the snippets, or not, in the normal Code Completion list:

Power User Hint

In my testing Ctrl+J for snippets works fine in the “Embed Editor” but when you are in the “Embeditor” (source view) Ctrl+J is assigned to “next filled embed”. However, snippets do appear in the standard code completion list ( Ctrl+Space ) and additionally, if you hit Ctrl+J enough times to get to the last “filled embed” then the snippets will popup after you get to the last one :smiley:

Of course you could use my KeyboardShortcuts addin to alter the assigned Ctrl+J keystroke on “next filled embed” which then allows Ctrl+J to popup the snippets list from the embeditor (the hardest part is finding an available shortcut to replace Ctrl+J) !

Additional Notes

One of the features in the EditorExtras addin is additional macros to popup a dialog so you can enter text that will be used in the snippet.

${PROMPT} – will popup a dialog and will be replaced with the entered value

${PROMPT_VALUE} – can be used within the same snippet multiple times and will be replaced with the value already entered.

Head on over to the product page for more details or dive straight into a short video demonstration!

Available Macros – Examples

Hint: Copy the example text below into a snippet and test it yourself!

! ======================
! Standard properties
! ======================

! Using ResourceService (this means anything found via the ResourceService.GetString() class)
${res:MainWindow.Windows.TaskList}
! Date/Time
${DATE}
${TIME}
 
! ProductName
${ProductName}
! Guid
${GUID}
! User
${USER}
! Version
${Version}
! Platform
${Platform}
! Get an ADDIN Path (This can refer to any addin "identity" e.g. SharpDevelop)
${ADDINPATH:SharpDevelop}
! Using the ENV prefix (This will search for a match using System.Environment.GetEnvironmentVariable(string) e.g. WinDir)
${ENV:WinDir}
! Using the PROPERTY prefix (This can be used to find values in the properties file e.g. UILanguage)
${PROPERTY:CoreProperties.UILanguage}
The following is the description from the #develop source:
/// <summary>
/// Allow special syntax to retrieve property values:
/// ${property:PropertyName}
/// ${property:PropertyName??DefaultValue}
/// ${property:ContainerName/PropertyName}
/// ${property:ContainerName/PropertyName??DefaultValue}
/// A container is a Properties instance stored in the PropertyService. This is
/// used by many AddIns to group all their properties into one container.
/// </summary>
 
! ======================
! Additional items provided by a built in custom "StringTagProvider"
! ======================
! ItemPath
${ItemPath}
! ItemDir
${ItemDir}
! ItemFilename
${ItemFilename}
! ItemExt
${ItemExt}
! TargetPath
${TargetPath}
! TargetDir
${TargetDir}
! TargetName
${TargetName}
! TargetExt
${TargetExt}
! CurrentProjectName
${CurrentProjectName}
! ProjectDir
${ProjectDir}
! ProjectFilename
${ProjectFilename}
! CombineDir
${CombineDir}
! CombineFilename
${CombineFilename}
! Startuppath
${Startuppath}
! TaskService.Warnings
${TaskService.Warnings}
! TaskService.Errors
${TaskService.Errors}
! TaskService.Messages
${TaskService.Messages}