/jEdit/tags/jedit-4-3-pre15/doc/users-guide/using-macros.xml

# · XML · 184 lines · 152 code · 29 blank · 3 comment · 0 complexity · 8f8307fef892d869a8a2f326cf09e5c8 MD5 · raw file

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <chapter id="using-macros">
  3. <title>Using Macros</title>
  4. <!-- jEdit buffer-local properties: -->
  5. <!-- :tabSize=1:indentSize=1:noTabs=true:wrap=soft:maxLineLen=80: -->
  6. <!-- :xml.root=users-guide.xml: -->
  7. <para>Macros in jEdit are short scripts written in a scripting language
  8. called <firstterm>BeanShell</firstterm>. They provide an easy way to
  9. automate repetitive keyboard and menu procedures, as well as access to the
  10. objects and methods created by jEdit. Macros also provide a powerful
  11. facility for customizing jEdit and automating complex text processing and
  12. programming tasks. This section describes how to record and run macros. A
  13. detailed guide on writing macros appears later; see <xref
  14. linkend="writing-macros-part" />.</para>
  15. <sidebar>
  16. <title>Other scripting languages</title>
  17. <para>A number of jEdit plugins provide support for writing scripts in
  18. alternative programming languages, like Python and Prolog. Consult the
  19. documentation for the appropriate plugins for more information.</para>
  20. </sidebar>
  21. <sect1 id="recording-macros">
  22. <title>Recording Macros</title>
  23. <para>The simplest use of macros is to record a series of key strokes
  24. and menu commands as a BeanShell script, and play them back later. While
  25. this doesn't let you take advantage of the full power of BeanShell, it
  26. is still a great time saver and can even be used to
  27. <quote>prototype</quote> more complicated macros.</para>
  28. <para><guimenu>Macros</guimenu>&gt;<guimenuitem>Record
  29. Macro</guimenuitem> (shortcut: <keycap>C+m C+r</keycap>) prompts for a
  30. macro name and begins recording.</para>
  31. <para>While recording is in progress, the string <quote>Macro
  32. recording</quote> is displayed in the status bar. jEdit records the
  33. following:</para>
  34. <itemizedlist>
  35. <listitem>
  36. <para>Key strokes</para>
  37. </listitem>
  38. <listitem>
  39. <para>Menu item commands</para>
  40. </listitem>
  41. <listitem>
  42. <para>Tool bar clicks</para>
  43. </listitem>
  44. <listitem>
  45. <para>All search and replace operations, except incremental
  46. search</para>
  47. </listitem>
  48. </itemizedlist>
  49. <para>Mouse clicks in the text area are <emphasis>not</emphasis>
  50. recorded; use text selection commands or arrow keys instead.</para>
  51. <para><guimenu>Macros</guimenu>&gt;<guimenuitem>Stop
  52. Recording</guimenuitem> (shortcut: <keycap>C+m C+s</keycap>) stops
  53. recording. It also switches to the buffer containing the recorded macro,
  54. giving you a chance to check over the recorded commands and make any
  55. necessary changes. When you are happy with the macro, save the buffer
  56. and it will appear in the <guimenu>Macros</guimenu> menu. To discard the
  57. macro, close the buffer without saving it.</para>
  58. <para>The file name extension <filename>.bsh</filename> is automatically
  59. appended to the macro name, and all spaces are converted to underscore
  60. characters, in order to make the macro name a valid file name. These two
  61. operations are reversed when macros are displayed in the
  62. <guimenu>Macros</guimenu> menu; see <xref linkend="organizing-macros" />
  63. for details.</para>
  64. <para>If a complicated operation only needs to be repeated a few times,
  65. using the temporary macro feature is quicker than saving a new macro
  66. file.</para>
  67. <para><guimenu>Macros</guimenu>&gt;<guimenuitem>Record Temporary
  68. Macro</guimenuitem> (shortcut: <keycap>C+m C+m</keycap>) begins
  69. recording to a buffer named <filename>Temporary_Macro.bsh</filename>.
  70. Once recording of a temporary macro is complete, jEdit does not display
  71. the buffer containing the recorded commands, but the name
  72. <filename>Temporary_Macro.bsh</filename> will be visible on any list of
  73. open buffers. By switching to that buffer, you can view the commands,
  74. edit them, and save them if you wish to a permanent macro file. Whether
  75. or not you look at or save the temporary macro contents, it is
  76. immediately available for playback.</para>
  77. <para><guimenu>Macros</guimenu>&gt;<guimenuitem>Run Temporary
  78. Macro</guimenuitem> (shortcut: <keycap>C+m C+p</keycap>) plays the macro
  79. recorded to the <filename>Temporary_Macro.bsh</filename> buffer.</para>
  80. <para>Only one temporary macro is available at a time. If you begin
  81. recording a second temporary macro, the first is erased and cannot be
  82. recovered unless you have saved the contents to a file with a name other
  83. than <filename>Temporary_Macro.bsh</filename>. If you do not save the
  84. temporary macro, you must keep the buffer containing the macro script
  85. open during your jEdit session. To have the macro available for your
  86. next jEdit session, save the buffer
  87. <filename>Temporary_Macro.bsh</filename> as an ordinary macro with a
  88. descriptive name of your choice. The new name will then be displayed in
  89. the <guimenu>Macros</guimenu> menu.</para>
  90. </sect1>
  91. <sect1 id="running-macros">
  92. <title>Running Macros</title>
  93. <para>Macros supplied with jEdit, as well as macros that you record or
  94. write, are displayed under the <guimenu>Macros</guimenu> menu in a
  95. hierarchical structure. The jEdit installation includes about 30 macros
  96. divided into several major categories. Each category corresponds to a
  97. nested submenu under the <guimenu>Macros</guimenu> menu. An index of
  98. these macros containing short descriptions and usage notes is found in
  99. <xref linkend="macro-index" />.</para>
  100. <para>To run a macro, choose the <guimenu>Macros</guimenu> menu,
  101. navigate through the hierarchy of submenus, and select the name of the
  102. macro to execute. You can also assign execution of a particular macro to
  103. a keyboard shortcut, toolbar button or context menu using the
  104. <guimenuitem>Macro Shortcuts</guimenuitem>, <guimenuitem>Tool
  105. Bar</guimenuitem> or <guimenuitem>Context Menu</guimenuitem> panes of
  106. the <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  107. Options</guimenuitem> dialog; see <xref linkend="global-opts" />.</para>
  108. </sect1>
  109. <sect1 id="organizing-macros">
  110. <title>How jEdit Organizes Macros</title>
  111. <para>Every macro, whether or not you originally recorded it, is stored
  112. on disk and can be edited as a text file. The file name of a macro must
  113. have a <filename>.bsh</filename> extension in order for jEdit to be
  114. aware of it. By default, jEdit associates a <filename>.bsh</filename>
  115. file with the BeanShell edit mode for purposes of syntax highlighting,
  116. indentation and other formatting. However, BeanShell syntax does not
  117. impose any indentation or line break requirements.</para>
  118. <para>The <guimenu>Macros</guimenu> menu lists all macros stored in two
  119. places: the <filename>macros</filename> subdirectory of the jEdit home
  120. directory, and the <filename>macros</filename> subdirectory of the
  121. user-specific settings directory (see <xref
  122. linkend="settings-directory" /> for information about the settings
  123. directory). Any macros you record will be stored in the user-specific
  124. directory.</para>
  125. <para>Macros stored elsewhere can be run using the
  126. <guimenu>Macros</guimenu>&gt;<guimenuitem>Run Other Macro</guimenuitem>
  127. command, which displays a file chooser dialog box, and runs the
  128. specified file.</para>
  129. <para>The listing of individual macros in the <guimenu>Macros</guimenu>
  130. menu can be organized in a hierarchy using subdirectories in the general
  131. or user-specific macro directories; each subdirectory appears as a
  132. submenu. You will find such a hierarchy in the default macro set
  133. included with jEdit.</para>
  134. <para>When jEdit first loads, it scans the designated macro directories
  135. and assembles a listing of individual macros in the
  136. <guimenu>Macros</guimenu> menu. When scanning the names, jEdit will
  137. delete underscore characters and the <filename>.bsh</filename> extension
  138. for menu labels, so that
  139. <filename>List_Useful_Information.bsh</filename>, for example, will be
  140. displayed in the <guimenu>Macros</guimenu> menu as <guimenuitem>List
  141. Useful Information</guimenuitem>.</para>
  142. <para>You can browse the user and system macro directories by opening
  143. the <filename>macros</filename> directory from the
  144. <guimenu>Utilities</guimenu>&gt;<guimenuitem>jEdit Home
  145. Directory</guimenuitem> and
  146. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Settings
  147. Directory</guimenuitem> menus.</para>
  148. <para>Macros can be opened and edited much like ordinary files from the
  149. file system browser. Editing macros from within jEdit will automatically
  150. update the macros menu; however, if you modify macros from another
  151. program or add macro files to the macro directories, you should run the
  152. <guimenu>Macros</guimenu>&gt;<guimenuitem>Rescan Macros</guimenuitem>
  153. command to update the macro list.</para>
  154. </sect1>
  155. </chapter>