SuperAbbrevs plugin user's guide

(December 14 2012)


Table of Contents

Chapter 1. Introduction

This plugin gives you the ability to expand an abbreviation to a userdefined code template. When expanded, you can jump between the variables in the template using the TAB key. If you change the text of a variable, the text will instantly change at the variable's other positions in the template.

There are already some predefined abbreviations when you install the plugin. You can find them in the SuperAbbrevs optionpane. Each mode has a list of defined abbreviations, and you can select the mode with a dropdown menu at the top of the optionpane. The abbreviations associated with the mode will be shown in the table below. There is a special mode added, global, that defines abbreviations that work across all modes.

You can define, edit or delete abbreviations from this optionpane. This will be explained further in Chapter 2, Using the plugin.

Additionnaly, you can use the Zen Coding syntax. Zen Coding is an editor plugin for high-speed HTML, XML, XSL (or any other structured code format) coding and editing. His core of is a powerful abbreviation engine which allows you to expand expressions—similar to CSS selectors—into HTML code. For further information please look into the Chapter 5, Zen Coding section.

Chapter 2. Using the plugin
Expand an abbreviation

To expand an abbreviation, you must be in the mode the abbreviation is associated with, and the cursor should be placed after the abbreviation. Press the TAB key, and the template will be inserted, and the first variable will be selected. If you change the text of the variable, it changes everywhere the variable is placed in the template. By pressing the TAB key once more, the next variable is selected. If you want to jump back to an earlier variable you should just press S+TAB.

Expand an abbreviation on a selection

To expand an abbreviation when you have selected some text, you should invoke the Show expandsion dialog action in the Plugins menu. Type in the abbreviation and press ENTER. The abbreviation will be expanded and the selection will be available to the template generating code.

Add a new abbreviation

In the SuperAbbrevs optionpane, find the mode in the dropdown menu, for which you want to add the abbreviation. Then press the plus button below the abbreviation table. An abbreviation editor will appear. Type in the abbreviation and the template according to the syntax explained in Chapter 3, Writing templates. Press the Ok button. The abbreviation is not saved yet - you must press Apply or the Ok button, at the bottom of the optionpane, to save all the changes you made to the abbreviations.

Add a new abbreviation from the buffer

If you want to add a new abbreviation from the buffer, type the abbreviation and press S+TAB. An abbreviation editor dialog will be shown. This dialog is used the same way as in the section called “Add a new abbreviation” - the only difference is that there are two buttons instead of the Ok button, one for adding the abbreviation to the global mode and one for adding it to the current mode.

Edit a existing abbreviation

To edit an abbreviation, double click it, an abbreviation editor dialog will appear. Type in the abbreviation and the template according to the syntax explained in Chapter 3, Writing templates. Press the Ok button. The abbreviation is not saved yet, you still have to press Apply or the Ok button, at the bottom of the optionpane, to save all the changes you made to the abbreviations.

Add a new abbreviation from the buffer

If you want to edit an abbreviation from the buffer, type the abbreviation and press S+TAB. An abbreviation editor dialog will be shown. This dialog is used the same way as the section called “Edit a existing abbreviation”, the only difference is that there are two buttons instead of the ok button, one for adding the abbreviation to the global mode and one for adding it to the current mode.

Chapter 3. Writing templates

A template can consist of the following things:

  • Variable: Variables are the essential part of a template. You write a variable in a template as ${number:value} where number is the TAB index of the variable, and value is the text that will be inserted in the variable when the template is expanded. The value will be inserted instead of the variable when the template is expanded.

    The characters \ { } have to be escaped in the value as \\ \{ \}.

  • Variable reference: You can refer to a variable by inserting $number, where number is the TAB index of the variable you are referring to. This inserts the text of the variable instead of the reference.

  • Transformation variable reference: This is a special kind of reference where you can run beanshell code on the text of the referred variable. You insert it in the template as ${number=code} where number is the TAB index of the variable you are referring to, and code is arbitrary beanshell code. In the code, the beanshell variable s holds the text of the referred variable. The functions in the file .jedit/SuperAbbrevs/abbrevs_functions.bsh are also available in the code.

  • The end variable: A special variable is $end. This variable will always be defined for a template, and represents the last place the cursor will jump to in the template. If the $end variable is not explicitly defined, it will be inserted at the end of the template. When you type in the end variable the template becomes inactive and the TAB key functions as normal.

  • Normal text: Everything else is just normal text that's inserted and not manipulated by the template engine.

    One thing to be aware of is that there are some character sequences that have to be escaped. If you want to write $ in the text you have to escape it as \$. Similarly, \ should be escaped as \\.

This example shows you how to make a Java field with getter and setters. The firstUp function makes the first character of the variable uppercase.

private ${2:Type} ${1:field};

/**
 * Getter function for the field $1
 */ 
public $2 get${1=firstUp(s)}() {
	return $1;
}

/**
 * Setter function for the field $1
 */
public void set${1=firstUp(s)}($2 $1){
	this.$1 = $1;
}

The best advice I can give you is to look at the already defined templates and play around with them.

Chapter 4. Template generation

This is only for advanced users.

It's possible to generate a template with beanshell code, you embed code into the template in between <# code #>, the template is then turned inside out, so all the normal text is turned into print statements, and the code will be executed. It's possible to print new code to the template with <#= code #> where the code have to evaluate to a string. All the functions in the files .jedit/SuperAbbrevs/template_generation_functions.bsh .jedit/SuperAbbrevs/abbrevs_functions.bsh is available, as well as a variable selection, holding the selection.

This example shows how to generate an HTML multiplying table of 5 rows and 5 columns - not that useful by itself, but only your imagination holds you back.

<table>
<# for(i=0; i<=5; i++){ #>
  <tr>
  <# for(j=0; j<=5; j++){ #>
    <td><#= i*j #></td>
  <# } #>
  </tr>
<# } #>
</table>

Chapter 5. Zen Coding

The Zen Coding feature is inspired from Zen Coding http://code.google.com/p/zen-coding/ It is not an official implementation so it is possible to have some little differences. Below, the features of Zen Coding engine:

  • ID and CLASS attributes: div#page.section.main.

  • Custom attributes: div[title], a[title="Hello world" rel], td[colspan=2].

  • Element multiplication: li*5 will output li tag five times.

  • Item numbering with $ character: li.item$*3 will output li tag three times, replacing $ character with item number.

  • Multiple $ characters in a row are used as zero padding, i.e.: li.item$$$li.item001.

  • Abbreviation groups with unlimited nesting: div#page>(div#header>ul#nav>li*4>a)+(div#page>(h1>span)+p*2)+div#footer. You can literally write a full document markup with just a single line.

  • Filters support. For example div#content|e will expand in

    &lt;div id="content"&gt;

    .

  • div tag name can be omitted when writing element starting from ID or CLASS: #content>.section is the same as div#content>div.section.

  • Text support: p>{Click }+a{here}+{ to continue}.

The example div#page>div.logo+ul#navigation>li*5>a[title] will expand in:

 <div id="page">
 	<div class="logo"></div>
 	<ul id="navigation">
 		<li>
 			<a title="" href=""></a>
 		</li>
 		<li>
 			<a title="" href=""></a>
 		</li>
 		<li>
 			<a title="" href=""></a>
 		</li>
 		<li>
 			<a title="" href=""></a>
 		</li>
 		<li>
 			<a title="" href=""></a>
 		</li>
 	</ul>
 </div>