PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/doc/users-guide/bsh-commands.xml

#
XML | 617 lines | 408 code | 63 blank | 146 comment | 0 complexity | 1a1cd19e4c4869c229b9625c8659347d 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. <!-- one day jEdit will provide its own error() implementation -->
  22. <!-- <listitem>
  23. <funcsynopsis>
  24. <funcprototype>
  25. <funcdef>void <function>error</function></funcdef>
  26. <paramdef>String <parameter>errorMsg</parameter></paramdef>
  27. </funcprototype>
  28. </funcsynopsis>
  29. <para>
  30. Writes the string represented by <parameter>errorMsg</parameter>
  31. to the error stream of the current process.
  32. </para>
  33. </listitem> -->
  34. <listitem>
  35. <funcsynopsis>
  36. <funcprototype>
  37. <funcdef>void <function>cat</function></funcdef>
  38. <paramdef>String <parameter>filename</parameter></paramdef>
  39. </funcprototype>
  40. </funcsynopsis>
  41. <para>
  42. Writes the contents of <parameter>filename</parameter>
  43. to the activity log.
  44. </para>
  45. </listitem>
  46. <listitem>
  47. <funcsynopsis>
  48. <funcprototype>
  49. <funcdef>void <function>javap</function></funcdef>
  50. <paramdef>String | Object | Class <parameter>target</parameter></paramdef>
  51. </funcprototype>
  52. </funcsynopsis>
  53. <para>
  54. Writes the public fields and methods of the specified class to
  55. the output stream of the current process. Requires Java 2
  56. version 1.3 or greater.
  57. </para>
  58. </listitem>
  59. <listitem>
  60. <funcsynopsis>
  61. <funcprototype>
  62. <funcdef>void <function>print</function></funcdef>
  63. <paramdef><parameter>arg</parameter></paramdef>
  64. </funcprototype>
  65. </funcsynopsis>
  66. <para>
  67. Writes the string value of the argument to the activity log,
  68. or if run from the <application>Console</application> plugin,
  69. to the current output window. If <parameter>arg</parameter> is
  70. an array, <function>print</function> runs itself recursively
  71. on the array's elements.
  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>cd</function></funcdef>
  82. <paramdef>String <parameter>dirname</parameter></paramdef>
  83. </funcprototype>
  84. </funcsynopsis>
  85. <para>
  86. Changes the working directory of the BeanShell interpreter
  87. to <parameter>dirname</parameter>.
  88. </para>
  89. </listitem>
  90. <listitem>
  91. <funcsynopsis>
  92. <funcprototype>
  93. <funcdef>void <function>dir</function></funcdef>
  94. <paramdef>String <parameter>dirname</parameter></paramdef>
  95. </funcprototype>
  96. </funcsynopsis>
  97. <para>
  98. Displays the contents of directory <parameter>dirname</parameter>.
  99. The format of the display is similar to the Unix
  100. <function>ls -l</function> command.
  101. </para>
  102. </listitem>
  103. <listitem>
  104. <funcsynopsis>
  105. <funcprototype>
  106. <funcdef>void <function>mv</function></funcdef>
  107. <paramdef>String <parameter>fromFile</parameter></paramdef>
  108. <paramdef>String <parameter>toFile</parameter></paramdef>
  109. </funcprototype>
  110. </funcsynopsis>
  111. <para>
  112. Moves the file named by <parameter>fromFile</parameter> to
  113. <parameter>toFile</parameter>.
  114. </para>
  115. </listitem>
  116. <listitem>
  117. <funcsynopsis>
  118. <funcprototype>
  119. <funcdef>File <function>pathToFile</function></funcdef>
  120. <paramdef>String <parameter>filename</parameter></paramdef>
  121. </funcprototype>
  122. </funcsynopsis>
  123. <para>
  124. Create a <classname>File</classname> object corresponding to
  125. <function>filename</function>. Relative paths are resolved with
  126. reference to the BeanShell interpreter's working
  127. directory.
  128. </para>
  129. </listitem>
  130. <listitem>
  131. <funcsynopsis>
  132. <funcprototype>
  133. <funcdef>void <function>pwd</function></funcdef>
  134. <void/>
  135. </funcprototype>
  136. </funcsynopsis>
  137. <para>
  138. Writes the current working directory of the BeanShell interpreter
  139. to the output stream of the current process.
  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>JFrame <function>frame</function></funcdef>
  161. <paramdef>Component <parameter>frame</parameter></paramdef>
  162. </funcprototype>
  163. </funcsynopsis>
  164. <para>
  165. Displays the component in a top-level <classname>JFrame</classname>,
  166. centered and packed. Returns the <classname>JFrame</classname> object.
  167. </para>
  168. </listitem>
  169. <listitem>
  170. <funcsynopsis>
  171. <funcprototype>
  172. <funcdef>Object <function>load</function></funcdef>
  173. <paramdef>String <parameter>filename</parameter></paramdef>
  174. </funcprototype>
  175. </funcsynopsis>
  176. <para>
  177. Loads and returns a serialized Java object from
  178. <parameter>filename</parameter>.
  179. </para>
  180. </listitem>
  181. <listitem>
  182. <funcsynopsis>
  183. <funcprototype>
  184. <funcdef>void <function>save</function></funcdef>
  185. <paramdef>Component <parameter>component</parameter></paramdef>
  186. <paramdef>String <parameter>filename</parameter></paramdef>
  187. </funcprototype>
  188. </funcsynopsis>
  189. <para>
  190. Saves <parameter>component</parameter> in serialized form
  191. to <parameter>filename</parameter>.
  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. Returns 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, reloads 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>Thread <function>bg</function></funcdef>
  316. <paramdef>String <parameter>filename</parameter></paramdef>
  317. </funcprototype>
  318. </funcsynopsis>
  319. <para>
  320. Run the BeanShell script named by <parameter>filename</parameter>
  321. in a copy of the existing namespace and in a separate thread. Returns
  322. the <classname>Thread</classname> object so created.
  323. </para>
  324. </listitem>
  325. <listitem>
  326. <funcsynopsis>
  327. <funcprototype>
  328. <funcdef>void <function>exec</function></funcdef>
  329. <paramdef>String <parameter>cmdline</parameter></paramdef>
  330. </funcprototype>
  331. </funcsynopsis>
  332. <para>
  333. Start the external process by calling
  334. <function>Runtime.exec()</function> on
  335. <parameter>cmdline</parameter>. Any output is directed to the
  336. output stream of the calling process.
  337. </para>
  338. </listitem>
  339. <listitem>
  340. <funcsynopsis>
  341. <funcprototype>
  342. <funcdef>Object <function>eval</function></funcdef>
  343. <paramdef>String <parameter>expression</parameter></paramdef>
  344. </funcprototype>
  345. </funcsynopsis>
  346. <para>
  347. Evaluates the string <parameter>expression</parameter> as
  348. a BeanShell script in the interpreter's current namespace.
  349. Returns the result of the evaluation of <constant>null</constant>.
  350. </para>
  351. </listitem>
  352. <listitem>
  353. <funcsynopsis>
  354. <funcprototype>
  355. <funcdef>bsh.This <function>run</function></funcdef>
  356. <paramdef>String <parameter>filename</parameter></paramdef>
  357. </funcprototype>
  358. </funcsynopsis>
  359. <para>
  360. Run the BeanShell script named by <parameter>filename</parameter>
  361. in a copy of the existing namespace. The return value represent
  362. the object context of the script, allowing you to access its variables
  363. and methods.
  364. </para>
  365. </listitem>
  366. <!-- <listitem>
  367. <funcsynopsis>
  368. <funcprototype>
  369. <funcdef>void <function>server</function></funcdef>
  370. <paramdef>int <parameter>port</parameter></paramdef>
  371. </funcprototype>
  372. </funcsynopsis>
  373. <para>
  374. Creates a <quote>server</quote> version of the BeanShell
  375. interpreter that shares the same namespace as the current
  376. interpreter. The server interpreter listens on the designated
  377. port.
  378. </para>
  379. <para>
  380. This requires the <classname>bsh.util</classname> package, which
  381. is not included with jEdit. It can be found in the stand-alone
  382. BeanShell distribution, available from <ulink
  383. url="http://www.beanshell.org">http://www.beanshell.org</ulink>.
  384. </para>
  385. <caution><para>
  386. Security of this port is not guaranteed. Use this command
  387. with extreme caution.
  388. </para></caution>
  389. </listitem> -->
  390. <listitem>
  391. <funcsynopsis>
  392. <funcprototype>
  393. <funcdef>void <function>source</function></funcdef>
  394. <paramdef>String <parameter>filename</parameter></paramdef>
  395. </funcprototype>
  396. </funcsynopsis>
  397. <para>
  398. Evaluates the contents of <parameter>filename</parameter>
  399. as a BeanShell script in the interpreter's current namespace.
  400. </para>
  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><function>bind</function></funcdef>
  411. <paramdef>bsh.This <parameter>ths</parameter></paramdef>
  412. <paramdef>bsh.Namespace <parameter>namespace</parameter></paramdef>
  413. </funcprototype>
  414. </funcsynopsis>
  415. <para>
  416. Binds the scripted object <parameter>ths</parameter> to
  417. <parameter>namespace</parameter>.
  418. </para>
  419. </listitem>
  420. <listitem>
  421. <funcsynopsis>
  422. <funcprototype>
  423. <funcdef>void <function>clear</function></funcdef>
  424. <void/>
  425. </funcprototype>
  426. </funcsynopsis>
  427. <para>
  428. Clear all variables, methods, and imports from this namespace.
  429. If this namespace is the root, it will be reset to the default
  430. imports.
  431. </para>
  432. </listitem>
  433. <listitem>
  434. <funcsynopsis>
  435. <funcprototype>
  436. <funcdef>bsh.This <function>extend</function></funcdef>
  437. <paramdef>bsh.This <parameter>object</parameter></paramdef>
  438. </funcprototype>
  439. </funcsynopsis>
  440. <para>
  441. Creates a new BeanShell <classname>This</classname> scripted object
  442. that is a child of the parameter <parameter>object</parameter>.
  443. </para>
  444. </listitem>
  445. <listitem>
  446. <funcsynopsis>
  447. <funcprototype>
  448. <funcdef>bsh.This <function>object</function></funcdef>
  449. <void/>
  450. </funcprototype>
  451. </funcsynopsis>
  452. <para>
  453. Creates a new BeanShell <classname>This</classname> scripted object which
  454. can hold data members. You can use this to create an object for
  455. storing miscellaneous crufties, like so:
  456. </para>
  457. <informalexample><programlisting>crufties = object();
  458. crufties.foo = "hello world";
  459. crufties.counter = 5;
  460. ...</programlisting></informalexample>
  461. </listitem>
  462. <listitem>
  463. <funcsynopsis>
  464. <funcprototype>
  465. <funcdef><function>setNameSpace</function></funcdef>
  466. <paramdef>bsh.Namespace <parameter>namespace</parameter></paramdef>
  467. </funcprototype>
  468. </funcsynopsis>
  469. <para>
  470. Set the namespace of the current scope to
  471. <parameter>namespace</parameter>.
  472. </para>
  473. </listitem>
  474. <listitem>
  475. <funcsynopsis>
  476. <funcprototype>
  477. <funcdef>bsh.This <function>super</function></funcdef>
  478. <paramdef>String <parameter>scopename</parameter></paramdef>
  479. </funcprototype>
  480. </funcsynopsis>
  481. <para>
  482. Returns a reference to the BeanShell <classname>This</classname>
  483. object representing the enclosing method scope specified
  484. by <parameter>scopename</parameter>. This method work similar to
  485. the <function>super</function> keyword but can refer to enclosing
  486. scope at higher levels in a hierarchy of scopes.
  487. </para>
  488. </listitem>
  489. <listitem>
  490. <funcsynopsis>
  491. <funcprototype>
  492. <funcdef>void <function>unset</function></funcdef>
  493. <paramdef>String <parameter>name</parameter></paramdef>
  494. </funcprototype>
  495. </funcsynopsis>
  496. <para>
  497. Removes the variable named by <parameter>name</parameter> from
  498. the current interpreter namespace. This has the effect of
  499. <quote>undefining</quote> the variable.
  500. </para>
  501. </listitem>
  502. </itemizedlist>
  503. </sect1>
  504. <sect1 id="beanshell-commands-other"><title>Other Commands</title>
  505. <itemizedlist>
  506. <!-- <listitem>
  507. <funcsynopsis>
  508. <funcprototype>
  509. <funcdef>void <function>exit</function></funcdef>
  510. <void/>
  511. </funcprototype>
  512. </funcsynopsis>
  513. <para>
  514. Calls <function>System.exit(0)</function>.
  515. </para>
  516. <caution><para>
  517. While this command is available, you should always call
  518. <function>jEdit.exit()</function> instead so the application will
  519. shutdown in an orderly fashion.
  520. </para></caution>
  521. </listitem> -->
  522. <listitem>
  523. <funcsynopsis>
  524. <funcprototype>
  525. <funcdef>void <function>debug</function></funcdef>
  526. <void/>
  527. </funcprototype>
  528. </funcsynopsis>
  529. <para>
  530. Toggles BeanShell's internal debug reporting to the
  531. output stream of the current process.
  532. </para>
  533. </listitem>
  534. <listitem>
  535. <funcsynopsis>
  536. <funcprototype>
  537. <funcdef><function>getSourceFileInfo</function></funcdef>
  538. <void/>
  539. </funcprototype>
  540. </funcsynopsis>
  541. <para>
  542. Returns the name of the file or other source from which the
  543. BeanShell interpreter is reading.
  544. </para>
  545. </listitem>
  546. </itemizedlist>
  547. </sect1>
  548. </chapter>