PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/doc/users-guide/macro-basics.xml

#
XML | 99 lines | 80 code | 12 blank | 7 comment | 0 complexity | e3dbcf7dbf3ada5fd85bff57a43c81ed 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. <!-- jEdit 3.2 Macro Guide, (C) 2001 John Gellene -->
  2. <!-- Revised Tue Jun 19 18:02:08 EDT 2001 @959 /Internet Time/ -->
  3. <!-- -->
  4. <!-- jEdit buffer-local properties: -->
  5. <!-- :indentSize=1:noTabs=yes:maxLineLen=72:tabSize=2: -->
  6. <!-- -->
  7. <!-- This file cover the introductory section of the macro guide -->
  8. <chapter id="macro-basics"><title>Introducing BeanShell</title>
  9. <para>
  10. Here is how BeanShell's author, Pat Niemeyer, describes his creation:
  11. </para>
  12. <blockquote>
  13. <para>
  14. <quote>BeanShell is a small, free, embeddable, Java source
  15. interpreter with object scripting language features, written in
  16. Java. BeanShell executes standard Java statements and
  17. expressions, in addition to obvious scripting commands and
  18. syntax. BeanShell supports scripted objects as simple method
  19. closures like those in Perl and JavaScript.</quote>
  20. </para>
  21. </blockquote>
  22. <para>
  23. As you might gather from this short quote, BeanShell is very similar to
  24. Java and is designed to be easy for Java programmers to learn. If you
  25. know how to program in Java, you already know how to write BeanShell
  26. macros. Nonetheless, the premise of this guide is that you should not
  27. have to know anything about Java to begin writing your own macros for
  28. jEdit.
  29. </para>
  30. <para>
  31. If you are not a Java programmer, you will have to learn a
  32. little about Java classes and syntax, but that's not a bad thing.
  33. You will also have to learn a little (but not too much) about
  34. some of the classes that are defined and used by the jEdit
  35. program itself. That is in fact the major strength of using
  36. BeanShell with a program written in Java: it allows the user to
  37. customize the program's behavior by employing the same interfaces
  38. designed and used by the program's developer. Thus, BeanShell can
  39. turn a well-designed application into a powerful toolkit.
  40. </para>
  41. <para>
  42. This guide focuses on using BeanShell in macros. If you are interested
  43. in learning more about BeanShell generally, consult the <ulink
  44. url="http://www.beanshell.org">BeanShell web site</ulink>. Information
  45. on how to run and organize macros, whether included with the jEdit
  46. installation or written by you, can be found in
  47. <xref linkend="using-macros"/>.
  48. </para>
  49. <sect1 id="single-macros"><title>Single Execution Macros</title>
  50. <para>
  51. There are two ways jEdit lets you use BeanShell quickly on a
  52. <quote>one time only</quote> basis. You will find both of them in the
  53. <guimenu>Utilities</guimenu> menu.
  54. </para>
  55. <para>
  56. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Evaluate BeanShell
  57. Expression</guimenuitem> causes jEdit to display a text input dialog
  58. that asks you to type a single line of BeanShell commands. You can type
  59. more than one BeanShell statement so long as each of them ends with a
  60. semicolon. If BeanShell successfully interprets your input, a message
  61. box will appear with the return value of the last statement. You can do
  62. the same thing using the BeanShell interpreter provided with the
  63. <application>Console</application> plugin; the return value will appear
  64. in the output window.
  65. </para>
  66. <para>
  67. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Evaluate Selection</guimenuitem>
  68. evaluates the selected text as a BeanShell script and
  69. replaces the selected text with the return value of the last BeanShell
  70. statement.
  71. </para>
  72. <para>
  73. Using <guimenuitem>Evaluate Selection</guimenuitem> is an
  74. easy way to do arithmetic calculations inline while editing. BeanShell
  75. uses numbers and arithmetic operations in an ordinary, intuitive way.
  76. </para>
  77. <informalexample>
  78. <para>
  79. Try typing an expression like <userinput>(3745*856)+74</userinput>
  80. in the buffer, select it, and choose
  81. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Evaluate
  82. Selection</guimenuitem>. The selected text will be replaced by the
  83. answer, <userinput>3205794</userinput>.
  84. </para>
  85. </informalexample>
  86. </sect1>
  87. </chapter>