Wednesday, December 15, 2004

Jedit macros

Thanks to Scalex in the JEdit community forums, I wrote a bunch of auto completion macros based upon some code he posted. I've saved each of these snippets my ~/.jedit/macros/.bsh and then associated each one as a short cut. That is, to initiate the bracket completion I assigned it to the "[" key as a shortcut. These are really basic and I plan to make updates (especially to the LOG one) as
I have time. For now they work and it's rather slick.

for auto quotes in JEdit:
-------------
buffer_mode = buffer.getMode().toString();
if (buffer_mode.equals("java")
||buffer_mode.equals("xml")
||buffer_mode.equals("html")) {
textArea.setSelectedText("\"\"");
textArea.goToPrevCharacter(false);
} else {
textArea.setSelectedText("\"");
}
-------------
for auto brackets:
-------------
buffer_mode = buffer.getMode().toString();
if (buffer_mode.equals("java")) {
textArea.setSelectedText("{");
textArea.insertEnterAndIndent();
textArea.setSelectedText("}");
textArea.shiftIndentLeft();
textArea.goToPrevLine(false);
textArea.goToEndOfWhiteSpace(false);
textArea.insertEnterAndIndent();

} else{
textArea.setSelectedText("{");
}
--------------
for auto parenthesis:
--------------
buffer_mode = buffer.getMode().toString();
if (buffer_mode.equals("java")) {
textArea.setSelectedText("()");
textArea.goToPrevCharacter(false);
} else {
textArea.setSelectedText("(");
}
--------------
for auto LOG debug statements:
--------------
textArea.setSelectedText("if(LOG.isDebugEnabled()){");
textArea.insertEnterAndIndent();
textArea.setSelectedText("LOG.debug()");
textArea.goToEndOfWhiteSpace(false);
textArea.setSelectedText(";");
textArea.insertEnterAndIndent();
textArea.setSelectedText("}");
textArea.shiftIndentLeft();
--------------

No comments: