PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/doc/FAQ/faq-macros.xml

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