PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/macros/Text/Next_Char.bsh

#
Unknown | 73 lines | 64 code | 9 blank | 0 comment | 0 complexity | f48651b510ffc52aa05ba2c657f53f6e 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 * Next_char.bsh - a BeanShell macro script for the
 3 * jEdit text editor - finds next occurence of character on
 4 * current line
 5 * Copyright (C) 2001 John Gellene
 6 * jgellene@nyc.rr.com
 7 * http://community.jedit.org
 8 *
 9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the jEdit program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 *
23 * $Id: Next_Char.bsh 3911 2001-11-24 03:33:01Z jgellene $
24 *
25 * Checked for jEdit 4.0 API
26 *
27 */
28
29void nextChar()
30{
31	script = new StringBuffer(512);
32	script.append( "start = textArea.getCaretPosition();"        );
33	script.append( "line = textArea.getCaretLine();"             );
34	script.append( "end = textArea.getLineEndOffset(line) + 1;"  );
35	script.append( "text = buffer.getText(start, end - start)"   );
36	script.append( "match = text.indexOf(__char__, 1);"          );
37	script.append( "if(match != -1) {"                           );
38	script.append( "if(__char__ != '\\n') ++match;"              );
39	script.append( "textArea.select(start, start + match - 1);}" );
40
41	view.getInputHandler().readNextChar("Enter a character",script.toString());
42}
43
44nextChar();
45
46/*
47	Macro index data (in DocBook format)
48
49<listitem>
50    <para><filename>Next_Char.bsh</filename></para>
51    <abstract><para>
52        Finds next occurence of character on current line.
53    </para></abstract>
54    <para>
55        The macro takes the next character typed after macro execution
56        as the character being searched.  That character is not
57        displayed.  If the character does not appear in the balance of
58        the current line, no action occurs.
59    </para>
60    <para>
61        This macro illustrates the use of
62        <function>InputHandler.readNextChar()</function> as a means of
63        obtaining user input. <!-- See <xref
64		linkend="macro-tips-single-char" -->
65        />.
66    </para>
67 </listitem>
68
69*/
70
71
72// end Next_char.bsh
73