// Macro XEnter.bsh // Author: Gael Ecorchard (galou_breizh yahoo.fr) // Version 0.1 // 2007 08 30 // insert new line, then behaves // either as normal insert enter and indent, if the line is a normal code line // or insert the line comment token and indent the line if the current line // is a comment // Usage: // - use the macro at the end of a comment line // Best used with a shortcut like S-Enter import java.util.regex.Pattern; import java.util.regex.Matcher; lineCommentToken = buffer.getStringProperty("lineComment") ; Pattern pattern = Pattern.compile("\\s*" + lineCommentToken + "\\s*"); // main subroutine void XEnter() { line = textArea.getCaretLine(); LineText = textArea.getLineText(line); Matcher matcher = pattern.matcher(LineText); if (matcher.find()) { // insert "\n" without indenting textArea.insert("\n",false); // insert the matching expression which contains the indentation textArea.insert(matcher.group(),false); } else { // if the line doesn't match the regexpr, do insertEnterAndIndent // if Enter is mapped to something else, this will cause problem textArea.insertEnterAndIndent(); } } // this single line of code is the script's main routine // it calls the methods and exits if(buffer.isReadOnly()) Macros.error(view, "Buffer is read-only."); else XEnter();