Quick tips for setting up Eclipse and Monkey
- eclipse-pdtis a php integrated eclipse IDE – good for rapid web development.
- download eclipse-pdt from above.
- setup subclipse (for svn) if you intend to use svn within eclipse. In eclipse->help->software updates->available software->add site, enter
URL: http://subclipse.tigris.org/update_1.6.x - Another good software to install is beyond cvs. In eclipse->help->software updates->available software->add site, enter URL: http://beyondcvs.sourceforge.net/update/0.8.x/
- install subeclipse and javaHL adapter.
- setup eclipse monkey (gives the ability to add your own short-cuts in eclipse). In eclipse->help->software updates->available software->add site, enter
URL: http://download.eclipse.org/technology/dash/update
- Optional – add whatever plugins that you think is useful for your development work.
Monkey Script
- To create a monkey script, add a new file under the “monkey” folder (need to create in eclipse). Name the file “author.js” for example (we are going to create a macro to insert developer’s comments). Copy and paste the following code in author.js
/*
* Menu: Editors > Developer's Comment
* Key: M3+M2+a
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
*/
var newDate = new Date();
var comment = "@author Bernard Peh "+newDate;
var commentLength = comment.length;
function main() {
var editor = editors.activeEditor;
// get range of lines in the selection (or at the cursor position)
var range = editor.selectionRange;
var startLine = editor.getLineAtOffset(range.startingOffset);
var endLine = editor.getLineAtOffset(range.endingOffset);
// determine if we're adding or removing comments
var source = editor.source;
var offset = editor.getOffsetAtLine(startLine);
var addComment = (source.substring(offset, offset + commentLength) != comment);
var adjust = 0;
editor.beginCompoundChange();
if (addComment) {
for (var i = startLine; i <= endLine; i++) {
var offset = range.startingOffset;
// var offset = editor.getOffsetAtLine(i);
editor.applyEdit(offset, 0, comment);
}
} else {
for (var i = startLine; i <= endLine; i++) {
var offset = range.startingOffset;
// var offset = editor.getOffsetAtLine(i);
if (source.substring(offset + adjust, offset + adjust + commentLength) == comment) {
editor.applyEdit(offset, commentLength, "");
adjust += commentLength;
}
}
}
editor.endCompoundChange();
}
Everything in author.js is javascript. Modify as you see fit. More examples can be seen in the plugins dir (org.eclipse.eclipsemonkey_x.x.x.xxxxxx). Now in any document, just press alt+shift+a to insert the author’s comment. Imagine what you can do with this technique!!
// eg. to add phpdoc using the shortcut, modify the variables var newDate = new Date(); var comment = "\t/**\n\t * .\n\t * @author Bernard Peh "+newDate+"\n\t * @param \n\t * @return \n\t */";
Note
- If the monkey shortcut key doesn’t work, check for keys conflict. Try out new key combination.
Other Tips
- CTRL + SHIFT + L : Shows you a list of your currently defined shortcut keys.
- mouse over a function or class to see quick description.
- CTRL + mouse over a function or class to see snippets of the class or function. While hovering the text, press F2 to see full code snippets.











