PageRenderTime 67ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/doc/FAQ/faq-macros.xml

#
XML | 127 lines | 109 code | 14 blank | 4 comment | 0 complexity | 4fcf65c0ba27f68cba0814315c392e2e 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. <?xml version="1.0" encoding="UTF-8"?>
  2. <section id="macros">
  3. <title>Macros</title>
  4. <!-- jEdit buffer-local properties: -->
  5. <!-- :indentSize=4:noTabs=false:maxLineLen=72:tabSize=4: -->
  6. <!-- :xml.root=faq.xml: -->
  7. <!-- jEdit FAQ -->
  8. <para>This section deals with questions on writing and running
  9. macros.</para>
  10. <qandaset defaultlabel="qanda">
  11. <qandadiv id="macro-using">
  12. <title>Using macros</title>
  13. <qandaentry>
  14. <question id="macro-getting">
  15. <para>Where can I get macro's from?</para>
  16. </question>
  17. <answer>
  18. <para>There is a plugin available called MacroManager that
  19. will provide a similar interface to jEdit's plugin manager
  20. for installing new macros. The plugin downloads the macros
  21. from the jEdit Community site, so an internet connection is
  22. necessary.</para>
  23. </answer>
  24. </qandaentry>
  25. <qandaentry>
  26. <question id="macro-new-store">
  27. <para>I just wrote a new macro for myself. Where should I
  28. save the file?</para>
  29. </question>
  30. <answer>
  31. <para>There is a <filename>macros</filename> directory in
  32. your user settings directory. If you store your macro there
  33. it will appear in jEdit's <guimenu>Macros</guimenu> menu
  34. under the name you have given to the macro's source code
  35. file. The <filename>.bsh</filename> will be deleted in the
  36. macro entry, and underscore characters will be converted to
  37. whitespace, so that the file
  38. <filename>My_New_Macro.bsh</filename> will be displayed as
  39. <guimenuitem>My New Macro</guimenuitem>.</para>
  40. <para>You can create additional subdirectories in the
  41. <filename>macros</filename>to organize your personal macros
  42. by category. Each subdirectory will correspond to a submenu
  43. under the application's <guimenu>Macros</guimenu> menu. This
  44. is helpful to reduce the screen space used to display the
  45. macros menu at any one time.</para>
  46. </answer>
  47. </qandaentry>
  48. <qandaentry>
  49. <question id="macro-new-ext">
  50. <para>Do I have to use the <filename>.bsh</filename> file
  51. extension when I save one of my own macro scripts?</para>
  52. </question>
  53. <answer>
  54. <para>You need the <filename>.bsh</filename> extension in
  55. order for jEdit to detect and display the name of the macro
  56. in its <guimenu>Macros</guimenu> menu. The macro must also
  57. be in the <filename>macros</filename> directory of either
  58. the jEdit installation directory or the user settings
  59. directory.</para>
  60. <para>You do not need the extension to run a macro, however.
  61. By selecting <guimenu>Macros</guimenu>&gt;<guimenuitem>Run
  62. Other Macro...</guimenuitem>, you can choose any file to be
  63. run as a macro. While in a macro, you can call
  64. <userinput>source("full_path")</userinput> to do the same
  65. thing.</para>
  66. </answer>
  67. </qandaentry>
  68. <qandaentry>
  69. <question id="macro-temp">
  70. <para>How can I store the result of a macro so that the next
  71. time I run it the macro can retrieve the value?</para>
  72. </question>
  73. <answer>
  74. <para>You can use either
  75. <userinput>jEdit.setProperty(String, String)</userinput> or
  76. <userinput>jEdit.setTemporaryProperty(String,
  77. String)</userinput>. Both methods take
  78. <classname>String</classname> values for the name of the
  79. property and its value. If you use
  80. <userinput>setProperty()</userinput>, the property will
  81. remain in jEdit's property store permanently, so if you only
  82. need the value during the course of a single editing
  83. session, use
  84. <userinput>setTemporaryProperty()</userinput>.</para>
  85. <para>To ensure that your value can be stored regardless of
  86. its type, use the following syntax:<programlisting>jEdit.setTemporaryProperty("myValueName", myValue.toString());</programlisting>
  87. and remember to convert the <quote>myValueName</quote>
  88. property back to its intended type when you retrieve
  89. it.</para>
  90. </answer>
  91. </qandaentry>
  92. <qandaentry>
  93. <question id="macro-exec">
  94. <para>In a macro I'd like to exec an external program (e.g.
  95. jmk, javac) and capture its output to a buffer. I'd also
  96. like to see this output as the external program runs or be
  97. able to interact with the program. So when I exec, what
  98. happens to System.in/out/err of the exec'd program?</para>
  99. </question>
  100. <answer>
  101. <para>Use the <filename>runInSystemShell()</filename> or the
  102. <filename>runCommandToBuffer()</filename> script methods
  103. that come bundled with the Console plugin. The help
  104. documentation for Console provides details on these methods.
  105. Currently the Console's System shell is not interactive
  106. during execution of a command, but it does receive and
  107. display the standard output and error streams of the
  108. external process.</para>
  109. </answer>
  110. </qandaentry>
  111. </qandadiv>
  112. </qandaset>
  113. </section>