PageRenderTime 50ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/macros/Clipboard/Cut_Lines_Containing.bsh

#
Unknown | 42 lines | 40 code | 2 blank | 0 comment | 0 complexity | 79af732dd765e5ce354de0c8de9bfc86 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. * Cut_Lines_Containing.bsh - Cuts lines from current buffer that
  3. * contain a user-supplied string to the clipboard.
  4. *
  5. * Copyright (C) 2004 Ollie Rutherfurd <oliver@jedit.org>
  6. *
  7. * $Id: Cut_Lines_Containing.bsh 5098 2004-08-03 21:31:48Z orutherfurd $
  8. */
  9. cutLinesContaining(){
  10. String text = Macros.input(view,"Cut lines containing:");
  11. if(text == null || "".equals(text))
  12. return;
  13. int count = 0;
  14. int start = 0;
  15. int end = 0;
  16. StringBuffer buff = new StringBuffer();
  17. try{
  18. buffer.beginCompoundEdit();
  19. for(int i = buffer.getLineCount() - 1 ; i >= 0; i--){
  20. String line = buffer.getLineText(i);
  21. if(line.indexOf(text) > -1){
  22. buff.insert(0,'\n').insert(0,line);
  23. int start = buffer.getLineStartOffset(i);
  24. int end = buffer.getLineEndOffset(i);
  25. buffer.remove(start,Math.min(end,buffer.getLength())-start);
  26. count++;
  27. }
  28. }
  29. }
  30. finally{
  31. buffer.endCompoundEdit();
  32. }
  33. Registers.setRegister('$',buff.toString());
  34. HistoryModel.getModel("clipboard").addItem(buff.toString());
  35. view.getStatus().setMessageAndClear("" + count + " lines cut");
  36. }
  37. if(buffer.isReadOnly())
  38. Toolkit.getDefaultToolkit().beep();
  39. else
  40. cutLinesContaining();