/* Remove_Comments.bsh Author: jakub@webkitchen.cz Licence: GNU GPL v2.0 */ void removeComments(int startLine, int endLine) { ArrayList commentTokens = new ArrayList(); // find COMMENT tokens for (int i = startLine; i <= endLine; i++) { DefaultTokenHandler tokenHandler = new DefaultTokenHandler(); buffer.markTokens(i, tokenHandler); Token lineToken = tokenHandler.getTokens(); while (lineToken.id != Token.END) { switch(lineToken.id) { case Token.COMMENT1: case Token.COMMENT2: case Token.COMMENT3: case Token.COMMENT4: commentTokens.add(new int[] { textArea.getLineStartOffset(i) + lineToken.offset, lineToken.length }); break; } lineToken = lineToken.next; } } // remove tokens for (int i = commentTokens.size() - 1; i >=0; i--) { int[] tokenProps = commentTokens.get(i); buffer.remove(tokenProps[0], tokenProps[1]); } } if (buffer.isReadOnly()) { Macros.error(view, "Buffer is read only"); return; } textArea.getDisplayManager().expandAllFolds(); textArea.scrollToCaret(false); int selectionCount = textArea.getSelectionCount(); if (selectionCount > 0) { for (int i = selectionCount - 1; i >= 0; i--) { Selection selection = textArea.getSelection(i); removeComments(selection.getStartLine(), selection.getEndLine()); } } else { removeComments(0, textArea.getLineCount() - 1); } textArea.getPainter().repaint();