PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
HTML | 49 lines | 46 code | 3 blank | 0 comment | 0 complexity | 9af8d285a1c43404fb812c2cc2dce318 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 Line</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="jEdit 4.3 User's Guide"><link rel="up" href="macro-tips.html" title="Chapter 15. Macro Tips and Techniques"><link rel="prev" 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 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 Line</h2></div></div></div><p>The <strong class="userinput"><code>-run</code></strong> command line switch specifies a
  2. BeanShell script to run on startup:</p><pre class="screen"><code class="prompt">$ </code><strong class="userinput"><code>jedit -run=test.bsh</code></strong></pre><p>Note that just like with startup scripts, the
  3. <code class="varname">view</code>, <code class="varname">textArea</code>,
  4. <code class="varname">editPane</code> and <code class="varname">buffer</code> variables are
  5. not defined.</p><p>If another instance is already running, the script will be run in
  6. that instance, and you will be able to use the
  7. <code class="function">jEdit.getLastView()</code> method to obtain a view.
  8. However, if a new instance of jEdit is being started, the script will be
  9. run at the same time as all other startup scripts; that is, before the
  10. first view is opened.</p><p>If your script needs a view instance to operate on, you can use
  11. the following code pattern to obtain one, no matter how or when the
  12. script is being run:</p><pre class="programlisting">void doSomethingUseful()
  13. {
  14. void run()
  15. {
  16. view = jEdit.getLastView();
  17. // put actual script body here
  18. }
  19. if(jEdit.getLastView() == null)
  20. VFSManager.runInAWTThread(this);
  21. else
  22. run();
  23. }
  24. doSomethingUseful();</pre><p>If the script is being run in a loaded instance, it can be invoked
  25. to perform its work immediately. However, if the script is running at
  26. startup, before an initial view exists, its operation must be delayed to
  27. allow the view object first to be created and displayed. In order to
  28. queue the macro's operation, the scripted &#8220;<span class="quote">closure</span>&#8221; named
  29. <code class="function">doSomethingUseful()</code> implements the
  30. <code class="classname">Runnable</code> interface of the Java platform. That
  31. interface contains only a single <code class="function">run()</code> method that
  32. takes no parameters and has no return value. The macro's implementation
  33. of the <code class="function">run()</code> method contains the
  34. &#8220;<span class="quote">working</span>&#8221; portion of the macro. Then the scripted object,
  35. represented by a reference to <code class="varname">this</code>, is passed to the
  36. <code class="function">runInAWTThread()</code> method. This schedules the macro's
  37. operations for execution after the startup routine is complete.</p><p>As this example illustrates, the
  38. <code class="function">runInAWTThread()</code> method can be used to ensure that
  39. a macro will perform operations after other operations have completed.
  40. If it is invoked during startup, it schedules the specified
  41. <code class="classname">Runnable</code> object to run after startup is complete.
  42. If invoked when jEdit is fully loaded, the
  43. <code class="classname">Runnable</code> object will execute after all pending
  44. input/output is complete, or immediately if there are no pending I/O
  45. operations. This will delay operations on a new buffer, for example,
  46. until after the buffer is loaded and displayed.</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>