Interpolation ShortcutsIntroductionUse interpolation codes to insert shortcuts in commands and code snippets. Shortcuts make it possible to use codes consisting of a single word or character to represent things such as dates and selected passages of text. They can be inserted manually or by selecting them from the shortcut menus in the Run Command and Snippet Properties dialog boxes. Click the arrow button in each of these dialog boxes to display a list of shortcut codes. Interpolation CodesThe following table contains all of the interpolation shortcut codes available in Komodo.
* This code uses special options. It does not use the same options described in the Basic Interpolation Options section. ![]() Basic Interpolation Code SyntaxInterpolation code blocks come in two forms: bracketed and non-bracketed. Run commands use the non-bracketed format. Snippets use the bracketed format. Non-bracketed syntaxThe syntax for a non-bracketed interpolation code is: %(<code><backref>:<options>...) where <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 separate sections. The following are examples of non-bracketed interpolation code: %(perl)
%w
%guid2
%(ask:Your Name:Trent Mick) The parentheses are optional if the code 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>...)]] where <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 OptionsThe following table shows the standard options available for most interpolation codes (these options do not apply to the codes displayed with an asterisk in the Interpolation Codes table.
![]() The "date" Interpolation CodeA date interpolation code will be replaced with the current date, formatted according to a given optional format or the default format. "date" Code SyntaxThe syntax of the date code 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" Code Format OptionIf no <optional-format> is specified in a date code, 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 the format with a string in accordance with the spec for the "format" argument of Python's *time.strftime()* method [1]_. The table is reproduced here for convenience.
For more information about Python 2.2's time access and conversions, visit http://www.python.org/doc/2.2/lib/module-time.html ![]() The "ask" Interpolation CodeAn "ask" code will prompt the user for the value to use as its replacement. The user is prompted using a pop-up dialog box. If a code snippet or run command includes more than one "ask" code, then the pop-up dialog box will request values for all of these codes. "ask" Code SyntaxThe syntax of the *ask* code is as follows: %(ask<backref>:<optional-question>:<optional-default>) [[%(ask<backref>:<optional-question>:<optional-default>)]] 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: %ask [[%ask:Name]] %ask:Name:Trent %(ask:What is Your Name:Trent Mick) "ask" Code OptionsAn "ask" code takes two optional parameters. The first, <optional-question>, is the text to display to the user when prompting for the value for that code. The second, <optional-defaultt>, is a default string to preload the text entry field in which the user specifies a value. The Query Dialog for "ask"-modified and "orask"-modified CodesWhen a list of strings are interpolated using interpolation shortcuts, the user may be prompted to supply values for certain codes. The user is asked via the Interpolation Query dialog box. This dialog will contain one or more text entry fields with labels describing the data expected for that field. These labels are determined from the specific interpolation code (both the "ask" code and the "orask" modifier include an option to specify a label). The label or question fields maintain recently-entered results that are displayed as a drop-down list of matching recent entries. ![]() 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. Without back-referencing, the user would be prompted as many times as there were instances of the interpolation in the snippet. Back-reference syntaxYou create a back-referenced set of codes by suffixing an interpolation code with a number. The syntax for back-reference is as follows: %(<code><backref>:<options>...) [[%(<code><backref>:<options>...)]] For example: %(ask1:Name:Trent) %w1:else:Foo [[%guid1]] All interpolation code blocks with the same code name and reference number 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, consider this run command: echo Hi there %(ask1:Name:Trent). That name again is %ask1 This would generate a Query dialog 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. ![]()
|