PageRenderTime 62ms CodeModel.GetById 59ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1/*
 2 * Move_Line_Up.bsh - a BeanShell macro for moving lines up.
 3 *
 4 * Copyright (C) 2004 Nicholas O'Leary nol@deferential.net
 5 * 
 6 * :mode=beanshell:tabSize=3:indentSize=3:maxLineLen=0:noTabs=true:
 7 * :indentOnTab=true:indentOnEnter=true:folding=explicit:collapseFolds=1:
 8 *
 9 * {{{ License
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with the jEdit program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 * }}}
24 *
25 *  
26 * Changes:
27 *  05-Jul-04: Initial Implementation
28 *
29 * $Id: Move_Line_Up.bsh 5073 2004-07-06 00:14:58Z spestov $
30 */
31
32// Get the current line
33int lineNo = textArea.getCaretLine();
34
35// Make sure we are allowed to edit the buffer, and that we're not at the start
36if (!buffer.isEditable() || lineNo == 0) {
37   textArea.getToolkit().beep();
38   return 1;
39}
40// Start the edit
41buffer.beginCompoundEdit();
42// Get the caret position on the line
43int lineCaretOffset = textArea.getCaretPosition()-buffer.getLineStartOffset(lineNo);
44// Get the line text to move
45String line = buffer.getLineText(lineNo);
46// Remove the line
47textArea.deleteLine();
48// Get the position to insert the line at
49int newLinePos = buffer.getLineStartOffset(lineNo-1);
50// Inser the line
51buffer.insert(newLinePos,line+"\n");
52// Move the cursor into the same position on the new line
53textArea.setCaretPosition(newLinePos+lineCaretOffset);
54// Indent this line
55buffer.indentLine(lineNo-1,true);
56// End the edit
57buffer.endCompoundEdit();
58
59/*
60
61Macro index data (in DocBook format)
62
63   <listitem>
64      <para><filename>Move_Line_Up.bsh</filename></para>
65      <abstract><para>Moves the current line up one, with automatic 
66      indentation.</para></abstract>   
67      </listitem>
68
69*/