Interpolation ShortcutsInterpolation shortcuts are codes embedded in run commands, snippets or templates that, at "execution" time, get replaced with values. For example, the path and name of the current file can be inserted via an interpolation shortcut when a run command is executed. Interpolation shortcuts can be inserted in Run Commands using the drop-down list to the right of Command field in the "Add Command..." and "Properties" dialog boxes, or entered manually. When using interpolation shortcuts in snippets or templates, insert the interpolation code using bracketed syntax. Run commands and snippets can be stored in a project or the Toolbox for frequent use. Interpolation Code ListThe following table shows the interpolation shortcuts available in Komodo. Windows users should enclose shortcuts for files and directories in double quotes (e.g. "%F") to ensure that spaces in the file name or file path are interpreted correctly.
Basic Interpolation Shortcut SyntaxInterpolation shortcut blocks come in two forms: bracketed and non-bracketed. Run commands use the non-bracketed format. snippets and templates use the bracketed format. Non-Bracketed SyntaxThe syntax for a non-bracketed interpolation code is: %<code> For shortcuts with options: %(<code>:<backref>:<options>...) For example: %(perl) %w %guid2 %(ask:Your Name:Trent Mick) The parentheses are optional if the block does not contain spaces. For example, the following two commands are equivalent: %ask:Name:Trent %(ask:Name:Trent) Bracketed SyntaxThe syntax for a bracketed interpolation code is: [[%(<code>:<backref>:<options>...)]] <code> is one of the codes shown in the table above, <backref> is a number and <options>... depend on the specific code. Back-references and options are discussed in other sections. The following are examples of bracketed syntax: [[%perl]] [[%w]] [[%guid2]] [[%ask:Your Name:Trent Mick]] With bracketed interpolation codes, the parentheses are always optional. The double brackets enclose spaces, making parentheses unnecessary. For example, both of the following commands are valid: [[%ask:Your Name:Trent Mick]] [[%(ask:Your Name:Trent Mick)]] Bracketed interpolation code blocks permit some excess space immediately adjacent to the double brackets. For example the following are equivalent: [[%ask:Your Name:Trent Mick]] [[ %ask:Your Name:Trent Mick]] [[%(ask:Your Name:Trent Mick) ]] [[ %(ask:Your Name:Trent Mick) ]] Basic Interpolation Shortcut OptionsThe following table shows the standard options available for most interpolation shortcuts. The %(ask), %(askpass), %(path), %(pref) and %(debugger) shortcuts have their own options and syntax.
Use the %(s:orask:Element Name) If there is no selected text, a pop-up dialog box appears with a text field called "Element Name". See Using Command
Query Shortcuts in the Run Command Tutorial for examples of
%(date)A %(date) shortcut is replaced with the current date, formatted according to a given optional format or the default format. %(date) SyntaxThe syntax of the %(date) shorcut is as follows: %(date:<backref>:<optional-format>) [[%(date:<optional-format>)]] As noted in the Basic Interpolation Code Syntax section, the parentheses are optional. The <backref> optional parameter is discussed in the Back-references section. The following examples are valid: %date [[%date]] %(date) %date:%H:%M:%S [[%date:%d/%m/%Y %H:%M:%S]] %(date) Format OptionIf no <optional-format> is specified in a date shortcut, the default date format is used. Configure the default date format using Komodo's Internationalization preferences. If this format is not appropriate, you can specify a different one
using the following date formatting codes (from Python's
For more information about Python's time access and conversions, see http://www.python.org/doc/2.2/lib/module-time.html %(ask) and %(askpass)The %(ask) and %(askpass) SyntaxThe %(ask[:NAME:[DEFAULT]]) %(askpass[:NAME:[DEFAULT]]) "NAME" appears next to the corresponding field in pop-up dialog box, and "DEFAULT" is an optional default value. A "DEFAULT" cannot be specified without a "NAME".
Typical usage of the %(askpass:Password) As noted in Basic Interpolation Code Syntax, usage of parentheses depends on the context. The following examples are valid: %ask [[%ask:Name]] %ask:Name:Joe %(ask:What is Your Name:Joe Smith) %(ask) and %(askpass) OptionsThe %(ask:<backref>:<optional-question>:<optional-default>) [[%(ask:<backref>:<optional-question>:<optional-default>)]] The <backref> optional parameter is discussed in the Back-references section. %(path)The "path" codes are used to provide special directory paths based on the installation of Komodo that is currently running. These include such items as the common data directory, which may be necessary if you are building run commands that you intend to work on shared files. %(path) SyntaxThe syntax of the path shortcut is as follows: %(path:<backref>:<pathName>) [[%(path:<backref>:<pathName>)]] %(path) OptionsThe %(path) shortcut takes one required parameter, "pathName". The pathName may be one of the following:
%(debugger)The %(debugger) shortcuts are used to provide runtime values from the debugger subsystem in Komodo. These codes can be used to provide debugging information to applications such as PerlApp. %(debugger) SyntaxThe syntax of the debugger shortcut is as follows: %(debugger:<backref>:<value>) [[%(debugger:<backref>:<value>)]] %(debugger) OptionsThe %(debugger) shortcut requires a <value> parameter, which can be one of the following:
The <backref> parameter is optional. %(pref)The %(pref) shortcut is used to provide values from Komodo's Preferences. The back-end of Komodo's preference system is undocumented, but you can examine the settings in the prefs.xml file in the user data directory to find the preference IDs. %(pref) SyntaxThe syntax of the %(pref:<backref>:<prefName>) [[%(pref:<backref>:<prefName>)]] Preference names may change between Komodo versions. Back-ReferencesBack-references are particularly useful for code snippets. You can use back-references to interpolate the same value any number of times in the snippet. Back-references make it possible to prompt the user for an input value only once, and then insert that value multiple times. For example, you could create a snippet that prompts for a value, which would then be entered at various places in the snippet text. Back-Reference SyntaxYou create a back-referenced set of shortcuts by suffixing the interpolation code with a number. The syntax for back-reference is as follows: %(<code><number>:<backref>:<options>...) [[%(<code><number>:<backref>:<options>...)]] For example: %(ask1:Name:Trent) %w1:else:Foo [[%guid1]] All interpolation blocks with the same shortcut/number pairs are part of the same back-reference set. All members of the same back-reference set will be replaced with the first code block in that set. For example: echo Hi there %(ask1:Name:Trent). That name again is %ask1 This opens a pop-up dialog box prompting for one entry, "Name", with a default of "Trent". Whatever value the user entered for "Name" would then be inserted in two places in the command, resulting in the following command: echo Hi there Bill. That name again is Bill Another useful application of back-references is the "guid" code. A guid code is replaced with a new GUID (Globally Unique Identifier). Sometimes it is desirable to have the same GUID inserted in more than one place in a file. In snippets, this can be done by using a code "%guid1" instead of just "%guid" wherever you want the GUID inserted. |