PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/www/tags/NOV_07_2009/htdocs/42docs/users-guide/scripts-command-line.html

#
HTML | 66 lines | 63 code | 3 blank | 0 comment | 0 complexity | 15318d4edb3e270cc31ff678f988aa50 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. <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Running Scripts from the Command
  2. Line</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="jEdit 4.2 User's Guide"><link rel="up" href="macro-tips.html" title="Chapter 15. Macro Tips and Techniques"><link rel="previous" href="startup-scripts.html" title="Startup Scripts"><link rel="next" href="macro-tips-BeanShell.html" title="Advanced BeanShell Techniques"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Running Scripts from the Command
  3. Line</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="startup-scripts.html">Prev</a> </td><th width="60%" align="center">Chapter 15. Macro Tips and Techniques</th><td width="20%" align="right"> <a accesskey="n" href="macro-tips-BeanShell.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="scripts-command-line"></a>Running Scripts from the Command
  4. Line</h2></div></div><div></div></div><p>
  5. The <b class="userinput"><tt>-run</tt></b> command line switch specifies a BeanShell
  6. script to run on startup:
  7. </p><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="screen"><tt class="prompt">$ </tt><b class="userinput"><tt>jedit -run=test.bsh</tt></b></pre></td></tr></table><p>
  8. Note that just like with startup scripts, the <tt class="varname">view</tt>,
  9. <tt class="varname">textArea</tt>, <tt class="varname">editPane</tt> and
  10. <tt class="varname">buffer</tt> variables are not defined.
  11. </p><p>
  12. If another instance is already running, the script will be run in that
  13. instance, and you will be able to use the
  14. <tt class="function">jEdit.getLastView()</tt> method to obtain a view.
  15. However, if a new instance of jEdit is being started, the script will
  16. be run at the same time as all other startup scripts; that is, before
  17. the first view is opened.
  18. </p><p>
  19. If your script needs a view instance to operate on, you can use the
  20. following code pattern to obtain one, no matter how or when the script is
  21. being run:
  22. </p><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">void doSomethingUseful()
  23. {
  24. void run()
  25. {
  26. view = jEdit.getLastView();
  27. // put actual script body here
  28. }
  29. if(jEdit.getLastView() == null)
  30. VFSManager.runInAWTThread(this);
  31. else
  32. run();
  33. }
  34. doSomethingUseful();</pre></td></tr></table><p>
  35. If the script is being run in a loaded
  36. instance, it can be invoked to perform its work immediately.
  37. However, if
  38. the script is running at startup, before an initial view exists, its
  39. operation must be delayed to allow the view object first to be created
  40. and displayed.
  41. In order to queue the macro's operation, the scripted &#8220;<span class="quote">closure</span>&#8221;
  42. named <tt class="function">doSomethingUseful()</tt> implements the
  43. <tt class="classname">Runnable</tt> interface of the Java platform.
  44. That interface contains only
  45. a single <tt class="function">run()</tt> method that takes no parameters
  46. and has no return value. The macro's implementation of the
  47. <tt class="function">run()</tt> method contains the &#8220;<span class="quote">working</span>&#8221;
  48. portion of the macro. Then the scripted object, represented by a
  49. reference to <tt class="varname">this</tt>, is passed to the
  50. <tt class="function">runInAWTThread()</tt> method. This schedules the
  51. macro's operations for execution after the startup routine is complete.
  52. </p><p>
  53. As this example illustrates, the <tt class="function">runInAWTThread()</tt>
  54. method can be used to ensure that a macro will perform operations
  55. after other operations have
  56. completed. If it is invoked during startup, it schedules the specified
  57. <tt class="classname">Runnable</tt> object to run after startup is complete.
  58. If invoked when jEdit is fully loaded, the <tt class="classname">Runnable</tt>
  59. object will execute after
  60. all pending input/output is complete, or immediately if there are no
  61. pending I/O operations. This will delay operations on a new buffer,
  62. for example, until after the buffer is loaded and displayed.
  63. </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="startup-scripts.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="macro-tips.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="macro-tips-BeanShell.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Startup Scripts </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Advanced BeanShell Techniques</td></tr></table></div></body></html>