/jEdit/tags/jedit-4-3-pre5/macros/Editing/Move_Line_Up.bsh
Unknown | 69 lines | 63 code | 6 blank | 0 comment | 0 complexity | 7881c80225bd52d30312380b6325257f MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * Move_Line_Up.bsh - a BeanShell macro for moving lines up.
- *
- * Copyright (C) 2004 Nicholas O'Leary nol@deferential.net
- *
- * :mode=beanshell:tabSize=3:indentSize=3:maxLineLen=0:noTabs=true:
- * :indentOnTab=true:indentOnEnter=true:folding=explicit:collapseFolds=1:
- *
- * {{{ License
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with the jEdit program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * }}}
- *
- *
- * Changes:
- * 05-Jul-04: Initial Implementation
- *
- * $Id: Move_Line_Up.bsh 5073 2004-07-06 00:14:58Z spestov $
- */
- // Get the current line
- int lineNo = textArea.getCaretLine();
- // Make sure we are allowed to edit the buffer, and that we're not at the start
- if (!buffer.isEditable() || lineNo == 0) {
- textArea.getToolkit().beep();
- return 1;
- }
- // Start the edit
- buffer.beginCompoundEdit();
- // Get the caret position on the line
- int lineCaretOffset = textArea.getCaretPosition()-buffer.getLineStartOffset(lineNo);
- // Get the line text to move
- String line = buffer.getLineText(lineNo);
- // Remove the line
- textArea.deleteLine();
- // Get the position to insert the line at
- int newLinePos = buffer.getLineStartOffset(lineNo-1);
- // Inser the line
- buffer.insert(newLinePos,line+"\n");
- // Move the cursor into the same position on the new line
- textArea.setCaretPosition(newLinePos+lineCaretOffset);
- // Indent this line
- buffer.indentLine(lineNo-1,true);
- // End the edit
- buffer.endCompoundEdit();
- /*
- Macro index data (in DocBook format)
- <listitem>
- <para><filename>Move_Line_Up.bsh</filename></para>
- <abstract><para>Moves the current line up one, with automatic
- indentation.</para></abstract>
- </listitem>
- */