PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/macros/Text/Duplicate_Line.bsh

#
Unknown | 70 lines | 63 code | 7 blank | 0 comment | 0 complexity | 59e6806496f3c3aa8c81b04f01069c56 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. * Duplicate_Line.bsh - a BeanShell macro script for the
  3. * jEdit text editor - duplicates the cursor line.
  4. * Copyright (C) 2001 Francesc Roses
  5. * froses@menta.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with the jEdit program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *
  21. *
  22. * $Id: Duplicate_Line.bsh 3866 2001-11-06 15:04:21Z jgellene $
  23. *
  24. * Checked for jEdit 4.0 API
  25. *
  26. */
  27. void duplicateLine()
  28. {
  29. /*
  30. * Guard for readonly files becuase Buffer.insert()
  31. * ignores the flag
  32. *
  33. */
  34. if(buffer.isReadOnly())
  35. {
  36. Macros.error(view, "This file is read only.");
  37. return;
  38. }
  39. line = textArea.getCaretLine();
  40. offset = textArea.getLineEndOffset(line);
  41. // handle last line differently
  42. if(line == textArea.getLineCount() - 1)
  43. {
  44. text = "\n" + textArea.getLineText(line);
  45. --offset;
  46. }
  47. else
  48. text = textArea.getLineText(line) + "\n";
  49. buffer.insert(offset, text);
  50. textArea.goToNextLine(false);
  51. }
  52. duplicateLine();
  53. /*
  54. Macro index data (in DocBook format)
  55. <listitem>
  56. <para><filename>Duplicate_Line.bsh</filename></para>
  57. <abstract><para>
  58. Duplicates the line on which the caret lies immediately
  59. beneath it and moves the caret to the new line.
  60. </para></abstract>
  61. </listitem>
  62. */
  63. // end Duplicate_Line.bsh