PageRenderTime 46ms CodeModel.GetById 24ms 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
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
  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. // Get the current line
  32. int lineNo = textArea.getCaretLine();
  33. // Make sure we are allowed to edit the buffer, and that we're not at the start
  34. if (!buffer.isEditable() || lineNo == 0) {
  35. textArea.getToolkit().beep();
  36. return 1;
  37. }
  38. // Start the edit
  39. buffer.beginCompoundEdit();
  40. // Get the caret position on the line
  41. int lineCaretOffset = textArea.getCaretPosition()-buffer.getLineStartOffset(lineNo);
  42. // Get the line text to move
  43. String line = buffer.getLineText(lineNo);
  44. // Remove the line
  45. textArea.deleteLine();
  46. // Get the position to insert the line at
  47. int newLinePos = buffer.getLineStartOffset(lineNo-1);
  48. // Inser the line
  49. buffer.insert(newLinePos,line+"\n");
  50. // Move the cursor into the same position on the new line
  51. textArea.setCaretPosition(newLinePos+lineCaretOffset);
  52. // Indent this line
  53. buffer.indentLine(lineNo-1,true);
  54. // End the edit
  55. buffer.endCompoundEdit();
  56. /*
  57. Macro index data (in DocBook format)
  58. <listitem>
  59. <para><filename>Move_Line_Up.bsh</filename></para>
  60. <abstract><para>Moves the current line up one, with automatic
  61. indentation.</para></abstract>
  62. </listitem>
  63. */