EclipseMonkey hacking

I’d been wanting to do some programming with eclipse itself. However, writing a full blown plugin for something rather simple is not exactly fun. Then I discovered Eclipse Monkey a few days back. I decided to give it a run when I came across a simple problem of commenting a specific method in my code. Yes, this is very useless but a good start IMO. :)
So, here’s my first experience with Eclipse Monkey:
This example just comments lines with stall function. Yeah kinda lame, but okay for a first shot IMO
In the meantime, checkout https://github.com/prasincs/eclipsemonkey-scripts/tree

where I’ll be posting more of these eclipsemonkey scripts

/*
* Menu: Editors > Comment Stalls
* Kudos: Prasanna Gautam
* License: EPL 1.0
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
* OnLoad: main()
*/
var comment = "//";
function main(){
var sourceEditor = editors.activeEditor;

var valid = true;

// make sure we have an editor
if (sourceEditor === undefined) {
valid = false;
showError("No active editor");
}

if (valid){
var newSource = "";
var source = sourceEditor.source;
var parts = source.split('\n');
for (var i = 0; i< parts.length; i++){
if(match=parts[i].match(/^((?:\s+)?stall.+)/)){
newSource +="// ";
}
newSource += parts[i] +"\n";
}
sourceEditor.applyEdit(0,source.length, newSource);
}
}

For more info on Eclipse Monkey, visit:
http://aptana.com/monkey/

Update:

Sorry for posting code from wrong file (one of the example ones)

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • description
  • LinkedIn
  • Live
  • StumbleUpon
  • Technorati

Leave a comment

Your comment