The #prompt
directive allows the template author to
specify a variable, and have the application prompt the user for a value.
This directive takes up to 4 parameters:
prompt string (required)
variable name (required)
default value (optional)
override context flag (optional)
The following code:
would result in the user being prompted for the class name:
The #yes_no
directive allows the template author to
have the application prompt the user to select one of two values (referred
to here as the "yes" and "no" values). After the user makes his/her
selection, the supplied variable will contain a Boolean object whose value
will be "true" if the user selected the "yes" value, "false" otherwise.
This directive takes up to 4 parameters:
prompt string (required)
variable name (required)
text to display for the "Yes" button (optional, default = "Yes")
text to display for the "No" button (optional, default = "No")
For example, the following code:
Example 4.8. #yes_no Directive example
#yes_no ( "Do you like cats?" $response "Yes, I do" "No, I don't")
would result in the user being presented with the following dialog:
The #today
directive can be used to assign the current
date to a variable. Any of the date formatting options supported by
java.text.SimpleDateFormat
may be used to format the
resulting date string.
This directive takes up to 2 parameters:
variable name (required)
formatting string (optional)
For example, the following code:
Example 4.9. #today Directive example
#today ( $defaultdate ) #today ( $yearonly "yyyy" ) #today ( $otherdate "dd-MMM-yyyy" ) The default format: $defaultdate Year only: $yearonly Another format: $otherdate
might yield the following output when processed:
The default format: Wed May 08 01:00:05 EDT 2002 Year only: 2002 Another format: 08-MAY-2002
The #caret
directive can be used to mark the location
at which the caret cursor should be placed following the processing of the
template. This directive takes no parameters.
For example, the following code would create a skeleton web page, and place the cursor in the body of the page in preparation for the user to begin entering the page's HTML code:
Example 4.10. #caret Directive example
<HTML> <HEAD> <TITLE>Skeleton web page</TITLE> </HEAD> <BODY> #caret () </BODY> </HTML>
The #buffermode
directive can be used to
programmatically set the mode of the current buffer.
This directive takes a single parameter:
buffer mode string (required)
For example, if we had a template for a generic Oracle SQL query, we might want to have the template automatically set the buffer mode for Oracle PL-SQL. This could be accomplished with the following code:
Example 4.11. #buffermode Directive example
#buffermode ( "pl-sql" ) ## ## The remainder of the template starts here ##
The #beanshell
directive is very powerful in that it
can be used to take advantage of the BeanShell interpreter included with
jEdit. Embedded BeanShell scripts can be used for a multitude of
tasks, such as processing the contents of variables, or accessing jEdit
internals.
This directive is a block directive, so the BeanShell script
is enclosed in a block which starts with the #beanshell ()
directive, and ends with an #end
statement.
This directive takes a single parameter:
return result flag (optional)
By default, the result of the script, if non-null, is written to the template. You can disable this by passing a boolean "false" as the "return result flag" parameter. The default value for this parameter is "true".
For example, the following code will retrieve the file name corresponding to the current buffer, as well as the user name, and put them in variables called "filename" and "author" respectively. Note that we pass in false as the first argument in order to suppress the return value of the last statement, 'context.put...', which returns the original value replaced by the 'put' call.
Example 4.12. #beanshell Directive example
#beanshell (false) context.put("filename", buffer.getName()); context.put("author", System.getProperty("user.name")); #end