/** * remove-trailing-ws.bsh - a BeanShell macro for the jEdit text editor that * removes Trailing WhiteSpaces of selected lines (as the action with same * name does). In contrast, if no selection is present, all lines are processed. * * * :folding=indent:collapseFolds=1: * * Copyright (C) 2008 Robert Schwenn * 02.05.2008 1.0 initial Version * * This macro is based on the retainLines.bsh macro * by Jia Zhiming jiazhimi@yahoo.com.cn * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ void removeTrailingWhitespaces() { // if (textArea.getSelection().length > 0) { // selection is present textArea.removeTrailingWhiteSpace(); } else { // no selection => process all lines //backup current lineNo. CaretLine = textArea.getCaretLine(); //remove trailing whitespaces of all lines textArea.selectAll(); textArea.removeTrailingWhiteSpace(); //deselect all, move caret to the line that was active before the macro started. textArea.selectNone(); textArea.moveCaretPosition(textArea.getLineStartOffset(CaretLine)); } } // starting point if (buffer.isReadOnly() || !textArea.isEditable()) { final static String ErrorNotEditableDialogTitle = jEdit.getProperty("macro.rs.general.ErrorNotEditableDialog.title", "Not Editable"); final static String ErrorNotEditableDialogMessage = jEdit.getProperty("macro.rs.general.ErrorNotEditableDialog.message", "Buffer can't be edited!"); JOptionPane.showMessageDialog(view, ErrorNotEditableDialogMessage, ErrorNotEditableDialogTitle, JOptionPane.ERROR_MESSAGE); } else { removeTrailingWhitespaces(); }