CFeclipse Snippets
As a programmer you find many times with the need to write the same code again and again for each component or file, or within the same file when defining functions, for example, all have the same format or syntax, you can copy and paste but there are ways More convenient like Snippets, which are stored predefined code blocks which can be inserted with some combinations of characters predefined by the user in conjunction with key combinations or shortcuts; Many IDE's have this function and Eclipse is not far behind for example whenever I want to insert the definition of a function write the word function and then press the keys ctrl + j, this opens a window with fields like name, displayname, hint , ReturnType, access; Once the fields are filled I press OK and I get the definition of a function ready to start with the code of the body of this one.
Let's for example to create a snippet to insert the init function that is occupied in all components as the object constructor, if you are using Object Oriented Programming, if you do not use it, you should.
To define a variable, which will be converted to a field in the window that needs to be filled at the time of inserting the snippet, is used $$ {Setting: variable not found}; Then the snippet would be defined as follows:
*Note. This is my way of defining and documenting functions is not a rule but you can take it as an example
/**
*@Displayname $${Setting: displaname not found}
* $${Setting: hint not found}
*
**/
$${Setting: access:private|public|remote not found} $${Setting: returntype:any|array|boolean|numeric|struct|void not found} function $${Setting: name not found}(){
return;
}
In the previous example we find something like this: {setting: access | private | public | remote not found} with this we are indicating that the variable access can have the following values private, public, remote then at the time of inserting the snippet, Eclipse Will show a drop-down list with these options in the window, but if you need to write something different to any of these options you can do so.
Eclipse allows you to organize snippets into packages so you can group them by language, functionality or as you see fit.
Steps to Create a CFeclipse Snippet
- Show the snippets panel, in the default perspective of CFeclipse, can be found in the left toolbar or in the main menu Window – Show view – Snip Tree View
- Click on the New snippet icon
- Write the name of the snippet (Snippet name)
- Write the text that will trigger the insertion of the snippet (trigger text), to insert a snippet can be from the corresponding panel, or typing the trigger text and pressing the keys ctrl + j
- In the window, two text areas are offered for the body of the snippet, this is because in markup languages an opening tag and a closing tag are occupied, then when a snippet is created using the two fields, at the time of insertion, Text that is selected will be enclosed by first inserting the first block (starting block), and then the second (closing block), for functions for example only the first field (starting block) will be used.
Steps to insert a CFeclipse snippet
First Method
- Position the cursor in the place where you want to insert the snippet.
- Locate the snippet in the panel and click on it to select it.
- Click on the Insert snippet icon
Second method
- Position the cursor in the place where you want to insert the snippet
- Write the trigger text corresponding to the snippet at the time of creating it and press ctrl + j the trigger text is case sensitive, if no variable was defined in the snippet, the snippet body text will be inserted, otherwise a window will appear for Write the corresponding variables.
If you want to backup your snippets, share them, or add someone else's, just copy the files to or from the following path <workspacelocation> /workspace/.metadata/.plugins/org.cfeclipse.cfml/snippets; There you will find XML files organized in folders that are the packages that you created. By default the <workspace location> path is /users/[username]/documents/
Remember that the workspace was defined the first time you ran Eclipse, or whenever you open it, if you did not activate the Always use this path.
Download some Snippets here.
Links of Interest for CFeclipse
Https://github.com/cfeclipse/CFEclipse/wiki/code-snippets