/jEdit/tags/jedit-4-3/macros/Editing/Duplicate_Lines_Above.bsh

# · Unknown · 69 lines · 61 code · 8 blank · 0 comment · 0 complexity · 93d0a1acac34206f61b918896a36c150 MD5 · raw file

  1. /*
  2. * Duplicate_Lines_Above.bsh - a BeanShell macro script for the
  3. * jEdit text editor - duplicates the cursor line.
  4. * Copyright (C) 2001 Francesc Roses
  5. * Copyright (c) 2008 encorejane
  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. * based on: Duplicate_Line.bsh 3866 2001-11-06 15:04:21Z jgellene
  21. *
  22. * Checked for jEdit 4.3 API
  23. *
  24. */
  25. void duplicateLinesAbove()
  26. {
  27. /*
  28. * Guard for readonly files becuase Buffer.insert()
  29. * ignores the flag
  30. *
  31. */
  32. if(buffer.isReadOnly())
  33. {
  34. Macros.error(view, "This file is read only.");
  35. return;
  36. }
  37. selections = textArea.getSelectedLines();
  38. if(selections.length == 0){
  39. selections = new int [] {textArea.getCaretLine()};
  40. }
  41. start = textArea.getLineStartOffset(selections[0]);
  42. stop = textArea.getLineEndOffset(selections[selections.length-1]);
  43. if(stop-1 == textArea.getBufferLength()){
  44. text = textArea.getText(start,stop-start-1)+'\n';
  45. }else{
  46. text = textArea.getText(start,stop-start);
  47. }
  48. buffer.insert(start, text);
  49. }
  50. duplicateLinesAbove();
  51. /*
  52. Macro index data (in DocBook format)
  53. <listitem>
  54. <para><filename>Duplicate_Line.bsh</filename></para>
  55. <abstract><para>
  56. Duplicates the line on which the caret lies immediately
  57. above it.
  58. </para></abstract>
  59. </listitem>
  60. */
  61. // end Duplicate_Line.bsh