PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/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. void nextChar()
  29. {
  30. script = new StringBuffer(512);
  31. script.append( "start = textArea.getCaretPosition();" );
  32. script.append( "line = textArea.getCaretLine();" );
  33. script.append( "end = textArea.getLineEndOffset(line) + 1;" );
  34. script.append( "text = buffer.getText(start, end - start)" );
  35. script.append( "match = text.indexOf(__char__, 1);" );
  36. script.append( "if(match != -1) {" );
  37. script.append( "if(__char__ != '\\n') ++match;" );
  38. script.append( "textArea.select(start, start + match - 1);}" );
  39. view.getInputHandler().readNextChar("Enter a character",script.toString());
  40. }
  41. nextChar();
  42. /*
  43. Macro index data (in DocBook format)
  44. <listitem>
  45. <para><filename>Next_Char.bsh</filename></para>
  46. <abstract><para>
  47. Finds next occurence of character on current line.
  48. </para></abstract>
  49. <para>
  50. The macro takes the next character typed after macro execution
  51. as the character being searched. That character is not
  52. displayed. If the character does not appear in the balance of
  53. the current line, no action occurs.
  54. </para>
  55. <para>
  56. This macro illustrates the use of
  57. <function>InputHandler.readNextChar()</function> as a means of
  58. obtaining user input. <!-- See <xref
  59. linkend="macro-tips-single-char" -->
  60. />.
  61. </para>
  62. </listitem>
  63. */
  64. // end Next_char.bsh