PageRenderTime 105ms CodeModel.GetById 102ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Unknown | 70 lines | 63 code | 7 blank | 0 comment | 0 complexity | 59e6806496f3c3aa8c81b04f01069c56 MD5 | raw file
 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
28void duplicateLine()
29{
30	/*
31	 * Guard for readonly files becuase Buffer.insert()
32	 * ignores the flag
33	 *
34	 */
35	if(buffer.isReadOnly())
36	{
37		Macros.error(view, "This file is read only.");
38		return;
39	}
40	line = textArea.getCaretLine();
41	offset = textArea.getLineEndOffset(line);
42	// handle last line differently
43	if(line == textArea.getLineCount() - 1)
44	{
45		text = "\n" + textArea.getLineText(line);
46		--offset;
47	}
48	else
49		text = textArea.getLineText(line) + "\n";
50	buffer.insert(offset, text);
51	textArea.goToNextLine(false);
52}
53
54duplicateLine();
55
56/*
57
58Macro index data (in DocBook format)
59
60  <listitem>
61    <para><filename>Duplicate_Line.bsh</filename></para>
62	<abstract><para>
63	  Duplicates the line on which the caret lies immediately
64	  beneath it and moves the caret to the new line.
65	</para></abstract>
66  </listitem>
67
68*/
69
70// end Duplicate_Line.bsh