PageRenderTime 32ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/doc/users-guide/using-macros.xml

#
XML | 223 lines | 195 code | 25 blank | 3 comment | 0 complexity | c379942ed7de9900ca68b15a096f16b0 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 buffer-local properties: -->
  2. <!-- :indentSize=1:noTabs=yes:maxLineLen=72:tabSize=2: -->
  3. <!-- :collapseFolds=0: -->
  4. <chapter id="using-macros"><title>Using Macros</title>
  5. <para>
  6. Macros in jEdit are short scripts written in a scripting language called
  7. <firstterm>BeanShell</firstterm>. They provide an wasy way to
  8. automate repetitive keyboard and menu procedures,
  9. as well as access to the objects and methods created by
  10. jEdit. Macros
  11. also provide a powerful facility for customizing jEdit and automating
  12. complex text processing and programming tasks. In this section we
  13. describe how to record and run macros. A detailed guide on
  14. writing macros appears later in a separate part of the user's
  15. guide; see <xref linkend="writing-macros-part"/>.
  16. </para>
  17. <sect1 id="recording-macros"><title>Recording Macros</title>
  18. <para>
  19. The simplest use of macros is to record a series of key strokes and
  20. menu commands as a BeanShell script, and play them back at a later
  21. time. While this doesn't let you take advantage of the full power of
  22. BeanShell, it is still a great time saver and can even be used to
  23. <quote>prototype</quote> more complicated macros.
  24. </para>
  25. <para>
  26. <guimenu>Macros</guimenu>&gt;<guimenuitem>Record Macro</guimenuitem>
  27. (shortcut:
  28. <keycombo><keycap>Control</keycap><keycap>M</keycap></keycombo>
  29. <keycombo><keycap>Control</keycap><keycap>R</keycap></keycombo>) prompts
  30. for a macro name and begins recording.
  31. </para>
  32. <para>
  33. While recording is in progress, the string <quote>Macro
  34. recording</quote> is displayed in the status bar. jEdit records the
  35. following:
  36. </para>
  37. <itemizedlist>
  38. <listitem><para>Key strokes</para></listitem>
  39. <listitem><para>Menu item commands</para></listitem>
  40. <listitem><para>Tool bar clicks</para></listitem>
  41. <listitem><para>All search and replace operations except incremental
  42. search</para></listitem>
  43. </itemizedlist>
  44. <para>
  45. Mouse clicks in the text area are <emphasis>not</emphasis> recorded; to
  46. record the equivalent of mouse operations, use the text selection commands
  47. or arrow keys.
  48. </para>
  49. <para>
  50. <guimenu>Macros</guimenu>&gt;<guimenuitem>Stop Recording</guimenuitem>
  51. (shortcut: <keycombo><keycap>Control</keycap><keycap>M</keycap></keycombo>
  52. <keycombo><keycap>Control</keycap><keycap>S</keycap></keycombo>) 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. The file name extension <filename>.bsh</filename> is
  56. automatically appended to the macro name, and all spaces are converted
  57. to underscore characters, in order to make the macro name a valid file
  58. name. These two operations are reversed when macros are displayed in the
  59. <guimenu>Macros</guimenu> menu. See <xref linkend="organizing-macros"/>
  60. for details. When you are happy with the macro, save the buffer and it
  61. will appear in the <guimenu>Macros</guimenu> menu. To discard the macro,
  62. close the buffer without saving.
  63. </para>
  64. <para>
  65. If a complicated operation only needs to be repeated a few of
  66. times, using the temporary macro feature is quicker than saving a new
  67. macro file.
  68. </para>
  69. <para>
  70. <guimenu>Macros</guimenu>&gt;<guimenuitem>Record Temporary
  71. Macro</guimenuitem> (shortcut:
  72. <keycombo><keycap>Control</keycap><keycap>M</keycap></keycombo>
  73. <keycombo><keycap>Control</keycap><keycap>M</keycap></keycombo>) begins
  74. recording to a buffer named <filename>Temporary_Macro.bsh</filename>.
  75. Once recording is complete, you don't need to save the
  76. <filename>Temporary_Macro.bsh</filename>buffer before playing it back.
  77. </para>
  78. <para>
  79. <guimenu>Macros</guimenu>&gt;<guimenuitem>Run Temporary
  80. Macro</guimenuitem> (shortcut:
  81. <keycombo><keycap>Control</keycap><keycap>M</keycap></keycombo>
  82. <keycombo><keycap>Control</keycap><keycap>P</keycap></keycombo>) plays
  83. the macro recorded to the <filename>Temporary_Macro.bsh</filename> buffer.
  84. </para>
  85. <para>
  86. If you do not save the temporary macro, you must keep the buffer
  87. containing the macro script open during your jEdit session. To have the
  88. macro available for your next jEdit session, save the buffer
  89. <filename>Temporary_Macro.bsh</filename> as an ordinary macro with a
  90. descriptive name of your choice. The new name will then be displayed in
  91. the <guimenu>Macros</guimenu> menu.
  92. </para>
  93. </sect1>
  94. <sect1 id="running-macros"><title>Running Macros</title>
  95. <para>
  96. Macros supplied with jEdit, as well as macros that you record or write,
  97. are displayed under the <guimenu>Macros</guimenu> menu in a
  98. hierarchical structure. The jEdit installation includes about 50 macros
  99. divided into several major categories. Each category corresponds to a
  100. nested submenu under the <guimenu>Macros</guimenu> menu. An index of
  101. these macros containing short descriptions and usage notes is found in
  102. <xref linkend="macro-index"/>.
  103. </para>
  104. <para>
  105. To run a macro, choose the <guimenu>Macros</guimenu> menu,
  106. navigate through the hierarchy of submenus, and select the name
  107. of the macro to execute. You can also assign execution of a
  108. particular macro to a keyboard shortcut, toolbar button or
  109. context menu using the
  110. <guimenuitem>Macro Shortcuts</guimenuitem>,
  111. <guimenuitem>Tool Bar</guimenuitem> or
  112. <guimenuitem>Context Menu</guimenuitem> panes of the
  113. <guimenu>Utilities</guimenu>&gt;<guimenuitem>Global
  114. Options</guimenuitem> dialog; see
  115. <xref linkend="global-opts"/>.
  116. </para>
  117. <para>
  118. <guimenu>Macros</guimenu>&gt;<guimenuitem>Run Last Macro</guimenuitem>
  119. (shortcut:
  120. <keycombo><keycap>Control</keycap><keycap>M</keycap></keycombo>
  121. <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>)
  122. runs the last macro run by jEdit again.
  123. </para>
  124. <sidebar><title>XInsert plugin</title>
  125. <para>
  126. The <application>XInsert</application> plugin has a feature that
  127. lists the title of macros, organized by subdirectories, as part of
  128. its tree list display. Clicking on the leaf of the tree
  129. corresponding to a macro name causes jEdit to execute the macro
  130. immediately. The plugin allows you to keep a list of macros and
  131. cut-and-paste text fragments available while editing
  132. without opening menus. For information about installing plugins, see
  133. <xref linkend="using-plugins"/>.
  134. </para>
  135. </sidebar>
  136. </sect1>
  137. <sect1 id="organizing-macros"><title>How jEdit Organizes Macros</title>
  138. <para>
  139. Every macro, whether or not you originally recorded it, is stored on
  140. disk and can be edited as a text file. The file names of macros
  141. must have a <filename>.bsh</filename> extension.
  142. By default, jEdit associates a
  143. <filename>.bsh</filename> file with the BeanShell edit
  144. mode for purposes of syntax highlighting, indentation and other
  145. formatting. However, BeanShell syntax does not impose any indentation or
  146. line break requirements.
  147. </para>
  148. <para>
  149. The <guimenu>Macros</guimenu> menu
  150. lists all macros stored in two places: the <filename>macros</filename>
  151. subdirectory of the jEdit install directory, and the
  152. <filename>macros</filename> subdirectory of the user-specific
  153. settings directory (see <xref linkend="settings-directory"/> for
  154. information about the settings directory). Any macros you record will be
  155. stored in the user-specific directory.
  156. </para>
  157. <para>
  158. Macros stored elsewhere can be run using the
  159. <guimenu>Macros</guimenu>&gt;<guimenuitem>Run Other Macro</guimenuitem>
  160. command, which
  161. displays a file chooser dialog box, and runs the specified file.
  162. </para>
  163. <para>
  164. The listing of individual macros in the <guimenu>Macros</guimenu> menu
  165. can be organized in a hierarchy using subdirectories in the general
  166. or user-specific macro directories; each subdirectory
  167. appears as a submenu. You will find such a hierarchy in the
  168. default macro set included with jEdit.
  169. </para>
  170. <para>
  171. When jEdit first loads, it scans the designated macro directories and
  172. assembles a listing of individual macros in the <guimenu>Macros</guimenu>
  173. menu. When scanning the names, jEdit will delete underscore characters
  174. and the <filename>.bsh</filename> extension for menu labels, so that
  175. <filename>List_Useful_Information.bsh</filename>, for example, will be
  176. displayed in the <guimenu>Macros</guimenu> menu as <guimenuitem>List
  177. Useful Information</guimenuitem>.
  178. </para>
  179. <para>
  180. <guimenu>Macros</guimenu>&gt;<guimenuitem>Browse System Macros</guimenuitem>
  181. displays the <filename>macros</filename> subdirectory of the
  182. directory in which jEdit is installed in the file system browser.
  183. </para>
  184. <para>
  185. <guimenu>Macros</guimenu>&gt;<guimenuitem>Browse User Macros</guimenuitem>
  186. displays the <filename>macros</filename> subdirectory of the
  187. user settings directory in the file system browser.
  188. </para>
  189. <para>
  190. Macros can be opened and edited much like ordinary files from the
  191. file system browser. Editing macros from within jEdit will
  192. automatically update the macros menu; however, if you modify macros
  193. from another program, the
  194. <guimenu>Macros</guimenu>&gt;<guimenuitem>Rescan Macros</guimenuitem>
  195. will need to be invoked to update the macro list.
  196. </para>
  197. </sect1>
  198. </chapter>