Return to Snippet

Revision: 50562
at October 18, 2013 21:15 by guai


Updated Code
buffer.setMode("groovy");
buffers = jEdit.getBuffers();
for(i = 0; i < buffers.length; i++) {
    gsh = buffers[i].getProperty("GroovyShell");
    if(gsh != null) { break; }
}
if(gsh == null) {
    libfiles = new File(System.getenv("GROOVY_HOME") + "/lib/").listFiles();
    cl = this.getClass().getClassLoader();
    for(i = 0; i < libfiles.length; i++)
        cl.addURL(new URL("jar:" + libfiles[i].toURL().toString() + "!/"));
    gsh = new groovy.lang.GroovyShell(cl);
}
for(i = 0; i < buffers.length; i++)
    buffers[i].setProperty("GroovyShell", gsh);
outbuffer = buffer.getProperty("outbuffer");
if((outbuffer == null) || outbuffer.isClosed()) {
    outbuffer = jEdit.newFile(view);
    buffer.setProperty("outbuffer", outbuffer);
}
out = new java.io.StringWriter();
gsh.setProperty("out", out);
String text() {
    view.showBuffer(buffer);
    res = textArea.getSelectedText();
    if(res == null || res.length() == 0) { res = buffer.getText(); }
    return res;
}
String cwd = System.getProperty("user.dir");
System.setProperty("user.dir", buffer.getDirectory());
result = gsh.evaluate(text());
System.setProperty("user.dir", cwd);
outbuffer.remove(0, outbuffer.getLength());
outbuffer.insert(0, out.toString());
outbuffer.insert(outbuffer.getLength(),"\n\tResult: " + result);
if(result != null) {
    view.showBuffer(outbuffer);
}

Revision: 50561
at July 30, 2013 22:26 by guai


Updated Code
buffer.setMode("groovy");
buffers = jEdit.getBuffers();
for(i = 0; i < buffers.length; i++) {
    gsh = buffers[i].getProperty("GroovyShell");
    if(gsh != null) { break; }
}
if(gsh == null) {
    libfiles = new File(System.getenv("GROOVY_HOME") + "/lib/").listFiles();
    cl = this.getClass().getClassLoader();
    for(i = 0; i < libfiles.length; i++)
        cl.addURL(new URL("jar:" + libfiles[i].toURL().toString() + "!/"));
    gshClass = cl.loadClass("groovy.lang.GroovyShell");
    gsh = gshClass.getConstructor(new Class[] {java.lang.ClassLoader.class}).newInstance(new Object[] {cl});
}
for(i = 0; i < buffers.length; i++)
    buffers[i].setProperty("GroovyShell", gsh);
outbuffer = buffer.getProperty("outbuffer");
if((outbuffer == null) || outbuffer.isClosed()) {
    outbuffer = jEdit.newFile(view);
    buffer.setProperty("outbuffer", outbuffer);
}
out = new java.io.StringWriter();
gsh.setProperty("out", out);
String text() {
    view.showBuffer(buffer);
    res = textArea.getSelectedText();
    if(res == null || res.length() == 0) { res = buffer.getText(); }
    return res;
}
String cwd = System.getProperty("user.dir");
System.setProperty("user.dir", buffer.getDirectory());
result = gsh.evaluate(text());
System.setProperty("user.dir", cwd);
outbuffer.remove(0, outbuffer.getLength());
outbuffer.insert(0, out.toString());
outbuffer.insert(outbuffer.getLength(),"\n\tResult: " + result);
if(result != null) {
    view.showBuffer(outbuffer);
}

Revision: 50560
at December 30, 2011 18:17 by guai


Updated Code
buffer.setMode("groovy");
buffers = jEdit.getBuffers();
for(i = 0; i < buffers.length; i++) {
    gsh = buffers[i].getProperty("GroovyShell");
    if(gsh != null) { break; }
}
if(gsh == null) {
    libfiles = new File(System.getenv("GROOVY_HOME") + "/lib/").listFiles();
    urls = new URL[libfiles.length];
    for(i = 0; i < libfiles.length; i++) {
        urls[i] = new URL("jar:" + libfiles[i].toURL().toString() + "!/");
    }
    groovycl = new java.net.URLClassLoader(urls, this.getClass().getClassLoader());
    gshClass = groovycl.loadClass("groovy.lang.GroovyShell");
    gsh = gshClass.getConstructor(new Class[] {java.lang.ClassLoader.class}).newInstance(new Object[] {groovycl});
}
for(i = 0; i < buffers.length; i++) {
    buffers[i].setProperty("GroovyShell", gsh);
}
outbuffer = buffer.getProperty("outbuffer");
if((outbuffer == null) || outbuffer.isClosed()) {
    outbuffer = jEdit.newFile(view);
    buffer.setProperty("outbuffer", outbuffer);
}
out = new java.io.StringWriter();
gsh.setProperty("out", out);
String text() {
    view.showBuffer(buffer);
    res = textArea.getSelectedText();
    if(res == null || res.length() == 0) { res = buffer.getText(); }
    return res;
}
String cwd = System.getProperty("user.dir");
System.setProperty("user.dir", buffer.getDirectory());
result = gsh.evaluate(text());
System.setProperty("user.dir", cwd);
outbuffer.remove(0, outbuffer.getLength());
outbuffer.insert(0, out.toString());
outbuffer.insert(outbuffer.getLength(),"\n\tResult: " + result);
if(result != null) {
    view.showBuffer(outbuffer);
}

Revision: 50559
at December 8, 2011 22:20 by guai


Updated Code
buffer.setMode("groovy");
buffers = jEdit.getBuffers();
for(i = 0; i < buffers.length; i++) {
    gsh = buffers[i].getProperty("GroovyShell");
    if(gsh != null) { break; }
}
if(gsh == null) {
    libfiles = new File(System.getenv("GROOVY_HOME") + "/lib/").listFiles();
    urls = new URL[libfiles.length];
    for(i = 0; i < libfiles.length; i++) {
        urls[i] = new URL("jar:" + libfiles[i].toURL().toString() + "!/");
    }
    groovycl = new java.net.URLClassLoader(urls, this.getClass().getClassLoader());
    gshClass = groovycl.loadClass("groovy.lang.GroovyShell");
    gsh = gshClass.getConstructor(new Class[] {java.lang.ClassLoader.class}).newInstance(new Object[] {groovycl});
}
for(i = 0; i < buffers.length; i++) {
    buffers[i].setProperty("GroovyShell", gsh);
}
outbuffer = buffer.getProperty("outbuffer");
if((outbuffer == null) || outbuffer.isClosed()) {
    outbuffer = jEdit.newFile(view);
    buffer.setProperty("outbuffer", outbuffer);
}
out = new java.io.StringWriter();
gsh.setProperty("out", out);
String text() {
    res = textArea.getSelectedText();
    if(res == null || res.length() == 0) { res = buffer.getText(); }
    return res;
}
String cwd = System.getProperty("user.dir");
System.setProperty("user.dir", buffer.getDirectory());
result = gsh.evaluate(text());
System.setProperty("user.dir", cwd);
outbuffer.remove(0, outbuffer.getLength());
outbuffer.insert(0, out.toString());
outbuffer.insert(outbuffer.getLength(),"\n\tResult: " + result);
view.showBuffer(outbuffer);

Revision: 50558
at August 26, 2011 14:12 by guai


Initial Code
buffer.setMode("groovy");
buffers = jEdit.getBuffers();
for(i = 0; i < buffers.length; i++) {
    gsh = buffers[i].getProperty("GroovyShell");
    if(gsh != null) { break; }
}
if(gsh == null) {
    libfiles = new File(System.getenv("GROOVY_HOME") + "/lib/").listFiles();
    urls = new URL[libfiles.length];
    for(i = 0; i < libfiles.length; i++) {
        urls[i] = new URL("jar:" + libfiles[i].toURL().toString() + "!/");
    }
    groovycl = new java.net.URLClassLoader(urls, this.getClass().getClassLoader());
    gshClass = groovycl.loadClass("groovy.lang.GroovyShell");
    gsh = gshClass.getConstructor(new Class[] {java.lang.ClassLoader.class}).newInstance(new Object[] {groovycl});
}
for(i = 0; i < buffers.length; i++) {
    buffers[i].setProperty("GroovyShell", gsh);
}
outbuffer = buffer.getProperty("outbuffer");
if((outbuffer == null) || outbuffer.isClosed()) {
    outbuffer = jEdit.newFile(view);
    buffer.setProperty("outbuffer", outbuffer);
}
out = new java.io.StringWriter();
gsh.setProperty("out", out);
String text() {
    res = textArea.getSelectedText();
    if(res == null || res.length() == 0) { res = buffer.getText(); }
    return res;
}
result = gsh.evaluate(text());
outbuffer.remove(0, outbuffer.getLength());
outbuffer.insert(0, out.toString());
outbuffer.insert(outbuffer.getLength(),"\n\tResult: " + result);
view.showBuffer(outbuffer);

Initial URL

                                

Initial Description
bind it to ctrl+enter and everything that GroovyConsole do jEdit will do too.
Uses groovy installation.

Initial Title
jEdit macro that makes it just like GroovyConsole

Initial Tags
groovy

Initial Language
Java