Macros
Prev |  | Next

## Macros

This section deals with questions on writing and running macros.

1. Using macros
  Q: Where can I get macro's from?
  Q: I just wrote a new macro for myself. Where should I save the file?
  Q: Do I have to use the .bsh file extension when I save one of my own macro scripts?
  Q: How can I store the result of a macro so that the next time I run it the macro can retrieve the value?
  Q: In a macro I'd like to exec an external program (e.g. jmk, javac) and capture its output to a buffer. I'd also like to see this output as the external program runs or be able to interact with the program. So when I exec, what happens to System.in/out/err of the exec'd program?

#### 1. Using macros
Q: Where can I get macro's from? Q: I just wrote a new macro for myself. Where should I save the file? Q: Do I have to use the .bsh file extension when I save one of my own macro scripts? Q: How can I store the result of a macro so that the next time I run it the macro can retrieve the value? Q: In a macro I'd like to exec an external program (e.g. jmk, javac) and capture its output to a buffer. I'd also like to see this output as the external program runs or be able to interact with the program. So when I exec, what happens to System.in/out/err of the exec'd program?
Q: | Where can I get macro's from?
A: | There is a plugin available called MacroManager that will provide a similar interface to jEdit's plugin manager for installing new macros. The plugin downloads the macros from the jEdit Community site, so an internet connection is necessary.
Q: | I just wrote a new macro for myself. Where should I save the file?
A: | There is a `macros` directory in your user settings directory. If you store your macro there it will appear in jEdit's Macros menu under the name you have given to the macro's source code file. The `.bsh` will be deleted in the macro entry, and underscore characters will be converted to whitespace, so that the file `My_New_Macro.bsh` will be displayed as My New Macro. You can create additional subdirectories in the `macros`to organize your personal macros by category. Each subdirectory will correspond to a submenu under the application's Macros menu. This is helpful to reduce the screen space used to display the macros menu at any one time.
Q: | Do I have to use the `.bsh` file extension when I save one of my own macro scripts?
A: | You need the `.bsh` extension in order for jEdit to detect and display the name of the macro in its Macros menu. The macro must also be in the `macros` directory of either the jEdit installation directory or the user settings directory. You do not need the extension to run a macro, however. By selecting Macros>Run Other Macro..., you can choose any file to be run as a macro. While in a macro, you can call `source("full_path")` to do the same thing.
Q: | How can I store the result of a macro so that the next time I run it the macro can retrieve the value?
A: | You can use either `jEdit.setProperty(String, String)` or `jEdit.setTemporaryProperty(String, String)`. Both methods take `String` values for the name of the property and its value. If you use `setProperty()`, the property will remain in jEdit's property store permanently, so if you only need the value during the course of a single editing session, use `setTemporaryProperty()`. To ensure that your value can be stored regardless of its type, use the following syntax:
    jEdit.setTemporaryProperty("myValueName", myValue.toString());
and remember to convert the “myValueName” property back to its intended type when you retrieve it.
Q: | In a macro I'd like to exec an external program (e.g. jmk, javac) and capture its output to a buffer. I'd also like to see this output as the external program runs or be able to interact with the program. So when I exec, what happens to System.in/out/err of the exec'd program?
A: | Use the `runInSystemShell()` or the `runCommandToBuffer()` script methods that come bundled with the Console plugin. The help documentation for Console provides details on these methods. Currently the Console's System shell is not interactive during execution of a command, but it does receive and display the standard output and error streams of the external process.

Prev | Up | Next
Usage Questions | Home | Plugin Questions