PageRenderTime 48ms CodeModel.GetById 44ms app.highlight 1ms 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
 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
10cutLinesContaining(){
11	String text = Macros.input(view,"Cut lines containing:");
12	if(text == null || "".equals(text))
13		return;
14	int count = 0;
15	int start = 0;
16	int end = 0;
17	StringBuffer buff = new StringBuffer();
18	try{
19		buffer.beginCompoundEdit();
20		for(int i = buffer.getLineCount() - 1 ; i >= 0; i--){
21			String line = buffer.getLineText(i);
22			if(line.indexOf(text) > -1){
23				buff.insert(0,'\n').insert(0,line);
24				int start = buffer.getLineStartOffset(i);
25				int end = buffer.getLineEndOffset(i);
26				buffer.remove(start,Math.min(end,buffer.getLength())-start);
27				count++;
28			}
29		}
30	}
31	finally{
32		buffer.endCompoundEdit();
33	}
34	Registers.setRegister('$',buff.toString());
35	HistoryModel.getModel("clipboard").addItem(buff.toString());
36	view.getStatus().setMessageAndClear("" + count + " lines cut");
37}
38
39if(buffer.isReadOnly())
40	Toolkit.getDefaultToolkit().beep();
41else
42	cutLinesContaining();