PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

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