PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/doc/users-guide/bsh-commands.xml

#
XML | 603 lines | 435 code | 62 blank | 106 comment | 0 complexity | 7eec6f29332ffc2ad1032cf3fc72c2b0 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 3.2 Macro Guide, (C) 2001 John Gellene -->
  2. <!-- Thu Jun 21 23:49:14 EDT 2001 @200 /Internet Time/ -->
  3. <!-- -->
  4. <!-- jEdit buffer-local properties: -->
  5. <!-- :indentSize=1:noTabs=yes:maxLineLen=72:tabSize=2: -->
  6. <chapter id="BeanShell-commands"><title>BeanShell Commands</title>
  7. <para>
  8. BeanShell includes a set of <firstterm>commands</firstterm>;
  9. subroutines that
  10. can be called from any script or macro. The following is a summary of
  11. those commands which may be useful within jEdit.
  12. </para>
  13. <note>
  14. <para>
  15. Plugins, because they are written in Java and not BeanShell,
  16. cannot make use of BeanShell commands.
  17. </para>
  18. </note>
  19. <sect1 id="BeanShell-commands-output"><title>Output Commands</title>
  20. <itemizedlist>
  21. <listitem>
  22. <funcsynopsis>
  23. <funcprototype>
  24. <funcdef>void <function>print</function></funcdef>
  25. <paramdef><parameter>arg</parameter></paramdef>
  26. </funcprototype>
  27. </funcsynopsis>
  28. <para>
  29. Writes the string value of the argument to the activity log,
  30. or if run from the <application>Console</application> plugin,
  31. to the current output window. If <parameter>arg</parameter> is
  32. an array, <function>print</function> runs itself recursively
  33. on the array's elements.
  34. </para>
  35. </listitem>
  36. <!-- one day jEdit will provide its own error() implementation -->
  37. <!-- <listitem>
  38. <funcsynopsis>
  39. <funcprototype>
  40. <funcdef>void <function>error</function></funcdef>
  41. <paramdef>String <parameter>errorMsg</parameter></paramdef>
  42. </funcprototype>
  43. </funcsynopsis>
  44. <para>
  45. Writes the string represented by <parameter>errorMsg</parameter>
  46. to the error stream of the current process.
  47. </para>
  48. </listitem> -->
  49. <listitem>
  50. <funcsynopsis>
  51. <funcprototype>
  52. <funcdef>void <function>cat</function></funcdef>
  53. <paramdef>String <parameter>filename</parameter></paramdef>
  54. </funcprototype>
  55. </funcsynopsis>
  56. <para>
  57. Writes the contents of <parameter>filename</parameter>
  58. to the activity log.
  59. </para>
  60. </listitem>
  61. <listitem>
  62. <funcsynopsis>
  63. <funcprototype>
  64. <funcdef>void <function>javap</function></funcdef>
  65. <paramdef>String | Object | Class <parameter>target</parameter></paramdef>
  66. </funcprototype>
  67. </funcsynopsis>
  68. <para>
  69. Writes the public fields and methods of the specified class to
  70. the output stream of the current process. Requires Java 2
  71. version 1.3 or greater.
  72. </para>
  73. </listitem>
  74. </itemizedlist>
  75. </sect1>
  76. <sect1 id="BeanShell-commands-file"><title>File Management Commands</title>
  77. <itemizedlist>
  78. <listitem>
  79. <funcsynopsis>
  80. <funcprototype>
  81. <funcdef>void <function>dir</function></funcdef>
  82. <paramdef>String <parameter>dirname</parameter></paramdef>
  83. </funcprototype>
  84. </funcsynopsis>
  85. <para>
  86. Displays the contents of directory <parameter>dirname</parameter>.
  87. The format of the display is similar to the Unix
  88. <function>ls -l</function> command.
  89. </para>
  90. </listitem>
  91. <listitem>
  92. <funcsynopsis>
  93. <funcprototype>
  94. <funcdef>File <function>pathToFile</function></funcdef>
  95. <paramdef>String <parameter>filename</parameter></paramdef>
  96. </funcprototype>
  97. </funcsynopsis>
  98. <para>
  99. Create a <classname>File</classname> object corresponding to
  100. <function>filename</function>. Relative paths are resolved with
  101. reference to the BeanShell interpreter's working
  102. directory.
  103. </para>
  104. </listitem>
  105. <listitem>
  106. <funcsynopsis>
  107. <funcprototype>
  108. <funcdef>void <function>cd</function></funcdef>
  109. <paramdef>String <parameter>dirname</parameter></paramdef>
  110. </funcprototype>
  111. </funcsynopsis>
  112. <para>
  113. Changes the working directory of the BeanShell interpreter
  114. to <parameter>dirname</parameter>.
  115. </para>
  116. </listitem>
  117. <listitem>
  118. <funcsynopsis>
  119. <funcprototype>
  120. <funcdef>void <function>pwd</function></funcdef>
  121. <void/>
  122. </funcprototype>
  123. </funcsynopsis>
  124. <para>
  125. Writes the current working directory of the BeanShell interpreter
  126. to the output stream of the current process.
  127. </para>
  128. </listitem>
  129. <listitem>
  130. <funcsynopsis>
  131. <funcprototype>
  132. <funcdef><function>mv</function></funcdef>
  133. <paramdef>String <parameter>fromFile</parameter></paramdef>
  134. <paramdef>String <parameter>toFile</parameter></paramdef>
  135. </funcprototype>
  136. </funcsynopsis>
  137. <para>
  138. Moves the file named by <parameter>fromFile</parameter> to
  139. <parameter>toFile</parameter>.
  140. </para>
  141. </listitem>
  142. <listitem>
  143. <funcsynopsis>
  144. <funcprototype>
  145. <funcdef>void <function>rm</function></funcdef>
  146. <paramdef>String <parameter>pathname</parameter></paramdef>
  147. </funcprototype>
  148. </funcsynopsis>
  149. <para>
  150. Deletes the file name by <parameter>pathname</parameter>.
  151. </para>
  152. </listitem>
  153. </itemizedlist>
  154. </sect1>
  155. <sect1 id="BeanShell-commands-serial"><title>Component Commands</title>
  156. <itemizedlist>
  157. <listitem>
  158. <funcsynopsis>
  159. <funcprototype>
  160. <funcdef>Object <function>load</function></funcdef>
  161. <paramdef>String <parameter>filename</parameter></paramdef>
  162. </funcprototype>
  163. </funcsynopsis>
  164. <para>
  165. Loads and returns a serialized Java object from
  166. <parameter>filename</parameter>.
  167. </para>
  168. </listitem>
  169. <listitem>
  170. <funcsynopsis>
  171. <funcprototype>
  172. <funcdef>void <function>save</function></funcdef>
  173. <paramdef>Component <parameter>component</parameter></paramdef>
  174. <paramdef>String <parameter>filename</parameter></paramdef>
  175. </funcprototype>
  176. </funcsynopsis>
  177. <para>
  178. Saves <parameter>component</parameter> in serialized form
  179. to <parameter>filename</parameter>.
  180. </para>
  181. </listitem>
  182. <listitem>
  183. <funcsynopsis>
  184. <funcprototype>
  185. <funcdef>JFrame <function>frame</function></funcdef>
  186. <paramdef>Component <parameter>frame</parameter></paramdef>
  187. </funcprototype>
  188. </funcsynopsis>
  189. <para>
  190. Displays the component in a top-level <classname>JFrame</classname>,
  191. centered and packed. Returns the <classname>JFrame</classname> object.
  192. </para>
  193. </listitem>
  194. <listitem>
  195. <funcsynopsis>
  196. <funcprototype>
  197. <funcdef>Font <function>setFont</function></funcdef>
  198. <paramdef>Component <parameter>comp</parameter></paramdef>
  199. <paramdef>int <parameter>ptsize</parameter></paramdef>
  200. </funcprototype>
  201. </funcsynopsis>
  202. <para>
  203. Set the font size of <parameter>component</parameter> to
  204. <parameter>ptsize</parameter> and returns the new
  205. font.
  206. </para>
  207. </listitem>
  208. </itemizedlist>
  209. </sect1>
  210. <sect1 id="BeanShell-commands-resource">
  211. <title>Resource Management Commands</title>
  212. <itemizedlist>
  213. <listitem>
  214. <funcsynopsis>
  215. <funcprototype>
  216. <funcdef>URL <function>getResource</function></funcdef>
  217. <paramdef>String <parameter>path</parameter></paramdef>
  218. </funcprototype>
  219. </funcsynopsis>
  220. <para>
  221. Returns the resource specified by <parameter>path</parameter>.
  222. A absolute path must be used to return any resource available in
  223. the current classpath.
  224. </para>
  225. </listitem>
  226. <!-- bsh.classpath not supported in jEdit -->
  227. <!--
  228. <listitem>
  229. <funcsynopsis>
  230. <funcprototype>
  231. <funcdef>void <function>addClassPath</function></funcdef>
  232. <paramdef>String <parameter>path</parameter></paramdef>
  233. </funcprototype>
  234. </funcsynopsis>
  235. </listitem>
  236. <listitem>
  237. <funcsynopsis>
  238. <funcprototype>
  239. <funcdef>void <function>addClassPath</function></funcdef>
  240. <paramdef>URL <parameter>path</parameter></paramdef>
  241. </funcprototype>
  242. </funcsynopsis>
  243. <para>
  244. Adds the directory or jar archive file specified by
  245. <parameter>path</parameter> to the classpath used by the
  246. interpreter.
  247. </para>
  248. </listitem>
  249. <listitem>
  250. <funcsynopsis>
  251. <funcprototype>
  252. <funcdef>void <function>setClassPath</function></funcdef>
  253. <paramdef>URL[] <parameter>paths</parameter></paramdef>
  254. </funcprototype>
  255. </funcsynopsis>
  256. <para>
  257. Changes the classpath for the BeanShell interpreter to the specified
  258. array of directories and/or archives.
  259. </para>
  260. </listitem>
  261. <listitem>
  262. <funcsynopsis>
  263. <funcprototype>
  264. <funcdef>URL[] <function>getClassPath</function></funcdef>
  265. <void/>
  266. </funcprototype>
  267. </funcsynopsis>
  268. <para>
  269. Retruns an array containing the current classpath.
  270. </para>
  271. </listitem>
  272. <listitem>
  273. <funcsynopsis>
  274. <funcprototype>
  275. <funcdef>void <function>reloadClasses</function></funcdef>
  276. <paramdef>String <parameter>packagename</parameter></paramdef>
  277. </funcprototype>
  278. </funcsynopsis>
  279. </listitem>
  280. <listitem>
  281. <funcsynopsis>
  282. <funcprototype>
  283. <funcdef>void <function>reloadClasses</function></funcdef>
  284. <void/>
  285. </funcprototype>
  286. </funcsynopsis>
  287. <para>
  288. Reloads the class or package specified by
  289. <parameter>packagename</parameter> in the BeanShell interpreter.
  290. If called without a parameter, releads all classes
  291. in the interpreter's classpath.
  292. </para>
  293. </listitem>
  294. <listitem>
  295. <funcsynopsis>
  296. <funcprototype>
  297. <funcdef>Class <function>getClass</function></funcdef>
  298. <paramdef>String <parameter>classname</parameter></paramdef>
  299. </funcprototype>
  300. </funcsynopsis>
  301. <para>
  302. This method is similar to the <function>Class.forName()</function>
  303. method of the Java platform, but it uses the classpath of the
  304. current BeanShell interpreter, which can contain additional
  305. classes and packages as well as reloaded classes.
  306. </para>
  307. </listitem> -->
  308. </itemizedlist>
  309. </sect1>
  310. <sect1 id="BeanShell-commands-script"><title>Script Execution Commands</title>
  311. <itemizedlist>
  312. <listitem>
  313. <funcsynopsis>
  314. <funcprototype>
  315. <funcdef><function>exec</function></funcdef>
  316. <paramdef>String <parameter>cmdline</parameter></paramdef>
  317. </funcprototype>
  318. </funcsynopsis>
  319. <para>
  320. Start the external process by calling
  321. <function>Runtime.exec()</function> on
  322. <parameter>cmdline</parameter>. Any output is directed to the
  323. output stream of the calling process.
  324. </para>
  325. </listitem>
  326. <listitem>
  327. <funcsynopsis>
  328. <funcprototype>
  329. <funcdef>void <function>source</function></funcdef>
  330. <paramdef>String <parameter>filename</parameter></paramdef>
  331. </funcprototype>
  332. </funcsynopsis>
  333. <para>
  334. Evaluates the contents of <parameter>filename</parameter>
  335. as a BeanShell script in the interpreter's current namespace.
  336. </para>
  337. </listitem>
  338. <listitem>
  339. <funcsynopsis>
  340. <funcprototype>
  341. <funcdef>Object <function>eval</function></funcdef>
  342. <paramdef>String <parameter>expression</parameter></paramdef>
  343. </funcprototype>
  344. </funcsynopsis>
  345. <para>
  346. Evaluates the string <parameter>expression</parameter> as
  347. a BeanShell script in the interpreter's current namespace.
  348. Returns the result of the evaluation of <constant>null</constant>.
  349. </para>
  350. </listitem>
  351. <listitem>
  352. <funcsynopsis>
  353. <funcprototype>
  354. <funcdef>bsh.This <function>run</function></funcdef>
  355. <paramdef>String <parameter>filename</parameter></paramdef>
  356. </funcprototype>
  357. </funcsynopsis>
  358. <para>
  359. Run the BeanShell script named by <parameter>filename</parameter>
  360. in a copy of the existing namespace. The return value represent
  361. the object context of the script, allowing you to access its variables
  362. and methods.
  363. </para>
  364. </listitem>
  365. <listitem>
  366. <funcsynopsis>
  367. <funcprototype>
  368. <funcdef>Thread <function>bg</function></funcdef>
  369. <paramdef>String <parameter>filename</parameter></paramdef>
  370. </funcprototype>
  371. </funcsynopsis>
  372. <para>
  373. Run the BeanShell script named by <parameter>filename</parameter>
  374. in a copy of the existing namespace and in a separate thread. Returns
  375. the <classname>Thread</classname> object so created.
  376. </para>
  377. </listitem>
  378. <listitem>
  379. <funcsynopsis>
  380. <funcprototype>
  381. <funcdef>void <function>server</function></funcdef>
  382. <paramdef>int <parameter>port</parameter></paramdef>
  383. </funcprototype>
  384. </funcsynopsis>
  385. <para>
  386. Createes a <quote>server</quote> version of the BeanShell
  387. interpreter that shares the same namespace as the current
  388. interpreter. The server interpreter listens on the designated
  389. port.
  390. </para>
  391. <para>
  392. This requires the <classname>bsh.util</classname> package, which
  393. is not included with jEdit. It can be found in the stand-alone
  394. BeanShell distribution, available from <ulink
  395. url="http://www.beanshell.org">http://www.beanshell.org</ulink>.
  396. </para>
  397. <caution><para>
  398. Security of this port is not guaranteed. Use this command
  399. with extreme caution.
  400. </para></caution>
  401. </listitem>
  402. </itemizedlist>
  403. </sect1>
  404. <sect1 id="BeanShell-commands-object">
  405. <title>BeanShell Object Management Commands</title>
  406. <itemizedlist>
  407. <listitem>
  408. <funcsynopsis>
  409. <funcprototype>
  410. <funcdef>bsh.This <function>object</function></funcdef>
  411. <void/>
  412. </funcprototype>
  413. </funcsynopsis>
  414. <para>
  415. Creates a new BeanShell <classname>This</classname> scripted object which
  416. can hold data members. You can use this to create an object for
  417. storing miscellaneous crufties, like so:
  418. </para>
  419. <informalexample><programlisting>crufties = object();
  420. crufties.foo = "hello world";
  421. crufties.counter = 5;
  422. ...</programlisting></informalexample>
  423. </listitem>
  424. <listitem>
  425. <funcsynopsis>
  426. <funcprototype>
  427. <funcdef>bsh.This <function>extend</function></funcdef>
  428. <paramdef>bsh.This <parameter>object</parameter></paramdef>
  429. </funcprototype>
  430. </funcsynopsis>
  431. <para>
  432. Creates a new BeanShell <classname>This</classname> scripted object
  433. that is a child of the parameter <parameter>object</parameter>.
  434. </para>
  435. </listitem>
  436. <listitem>
  437. <funcsynopsis>
  438. <funcprototype>
  439. <funcdef>bsh.This <function>super</function></funcdef>
  440. <paramdef>String <parameter>scopename</parameter></paramdef>
  441. </funcprototype>
  442. </funcsynopsis>
  443. <para>
  444. Returns a refernece to the BeanShell <classname>This</classname>
  445. object representing the enclosing method scope specified
  446. by <parameter>scopename</parameter>. This method work similar to
  447. the <function>super</function> keyword but can refer to enclosing
  448. scope at higher levels in a hierarchy of scopes.
  449. </para>
  450. </listitem>
  451. <listitem>
  452. <funcsynopsis>
  453. <funcprototype>
  454. <funcdef><function>bind</function></funcdef>
  455. <paramdef>bsh.This <parameter>ths</parameter></paramdef>
  456. <paramdef>bsh.Namespace <parameter>namespace</parameter></paramdef>
  457. </funcprototype>
  458. </funcsynopsis>
  459. <para>
  460. Binds the scripted object <parameter>ths</parameter> to
  461. <parameter>namespace</parameter>.
  462. </para>
  463. </listitem>
  464. <listitem>
  465. <funcsynopsis>
  466. <funcprototype>
  467. <funcdef>void <function>unset</function></funcdef>
  468. <paramdef>String <parameter>name</parameter></paramdef>
  469. </funcprototype>
  470. </funcsynopsis>
  471. <para>
  472. Removes the variable named by <parameter>name</parameter> from
  473. the current interpreter namespace. This has the effect of
  474. <quote>undefining</quote> the variable.
  475. </para>
  476. </listitem>
  477. <listitem>
  478. <funcsynopsis>
  479. <funcprototype>
  480. <funcdef><function>setNameSpace</function></funcdef>
  481. <paramdef>bsh.Namespace <parameter>namespace</parameter></paramdef>
  482. </funcprototype>
  483. </funcsynopsis>
  484. <para>
  485. Set the namespace of the current scope to
  486. <parameter>namespace</parameter>.
  487. </para>
  488. </listitem>
  489. </itemizedlist>
  490. </sect1>
  491. <sect1 id="BeanShell-commands-other"><title>Other Commands</title>
  492. <itemizedlist>
  493. <listitem>
  494. <funcsynopsis>
  495. <funcprototype>
  496. <funcdef>void <function>exit</function></funcdef>
  497. <void/>
  498. </funcprototype>
  499. </funcsynopsis>
  500. <para>
  501. Calls <function>System.exit(0)</function>.
  502. </para>
  503. <caution><para>
  504. While this command is available, you should always call
  505. <function>jEdit.exit()</function> instead so the application will
  506. shutdown in an orderly fashion.
  507. </para></caution>
  508. </listitem>
  509. <listitem>
  510. <funcsynopsis>
  511. <funcprototype>
  512. <funcdef>void <function>debug</function></funcdef>
  513. <void/>
  514. </funcprototype>
  515. </funcsynopsis>
  516. <para>
  517. Toggles BeanShell's internal debug reporting to the
  518. output stream of the current process.
  519. </para>
  520. </listitem>
  521. <listitem>
  522. <funcsynopsis>
  523. <funcprototype>
  524. <funcdef><function>getSourceFileInfo</function></funcdef>
  525. <void/>
  526. </funcprototype>
  527. </funcsynopsis>
  528. <para>
  529. Returns the name of the file or other source from which the
  530. BeanShell interpreter is reading.
  531. </para>
  532. </listitem>
  533. </itemizedlist>
  534. </sect1>
  535. </chapter>