/jEdit/tags/jedit-4-1-pre10/macros/Text/Next_Char.bsh
# · Unknown · 73 lines · 64 code · 9 blank · 0 comment · 0 complexity · f48651b510ffc52aa05ba2c657f53f6e MD5 · raw file
- /*
- * Next_char.bsh - a BeanShell macro script for the
- * jEdit text editor - finds next occurence of character on
- * current line
- * Copyright (C) 2001 John Gellene
- * jgellene@nyc.rr.com
- * http://community.jedit.org
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with the jEdit program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id: Next_Char.bsh 3911 2001-11-24 03:33:01Z jgellene $
- *
- * Checked for jEdit 4.0 API
- *
- */
- void nextChar()
- {
- script = new StringBuffer(512);
- script.append( "start = textArea.getCaretPosition();" );
- script.append( "line = textArea.getCaretLine();" );
- script.append( "end = textArea.getLineEndOffset(line) + 1;" );
- script.append( "text = buffer.getText(start, end - start)" );
- script.append( "match = text.indexOf(__char__, 1);" );
- script.append( "if(match != -1) {" );
- script.append( "if(__char__ != '\\n') ++match;" );
- script.append( "textArea.select(start, start + match - 1);}" );
- view.getInputHandler().readNextChar("Enter a character",script.toString());
- }
- nextChar();
- /*
- Macro index data (in DocBook format)
- <listitem>
- <para><filename>Next_Char.bsh</filename></para>
- <abstract><para>
- Finds next occurence of character on current line.
- </para></abstract>
- <para>
- The macro takes the next character typed after macro execution
- as the character being searched. That character is not
- displayed. If the character does not appear in the balance of
- the current line, no action occurs.
- </para>
- <para>
- This macro illustrates the use of
- <function>InputHandler.readNextChar()</function> as a means of
- obtaining user input. <!-- See <xref
- linkend="macro-tips-single-char" -->
- />.
- </para>
- </listitem>
- */
- // end Next_char.bsh