/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
- /*
- * Cut_Lines_Containing.bsh - Cuts lines from current buffer that
- * contain a user-supplied string to the clipboard.
- *
- * Copyright (C) 2004 Ollie Rutherfurd <oliver@jedit.org>
- *
- * $Id: Cut_Lines_Containing.bsh 5098 2004-08-03 21:31:48Z orutherfurd $
- */
- cutLinesContaining(){
- String text = Macros.input(view,"Cut lines containing:");
- if(text == null || "".equals(text))
- return;
- int count = 0;
- int start = 0;
- int end = 0;
- StringBuffer buff = new StringBuffer();
- try{
- buffer.beginCompoundEdit();
- for(int i = buffer.getLineCount() - 1 ; i >= 0; i--){
- String line = buffer.getLineText(i);
- if(line.indexOf(text) > -1){
- buff.insert(0,'\n').insert(0,line);
- int start = buffer.getLineStartOffset(i);
- int end = buffer.getLineEndOffset(i);
- buffer.remove(start,Math.min(end,buffer.getLength())-start);
- count++;
- }
- }
- }
- finally{
- buffer.endCompoundEdit();
- }
- Registers.setRegister('$',buff.toString());
- HistoryModel.getModel("clipboard").addItem(buff.toString());
- view.getStatus().setMessageAndClear("" + count + " lines cut");
- }
- if(buffer.isReadOnly())
- Toolkit.getDefaultToolkit().beep();
- else
- cutLinesContaining();