File: bsh-commands.xml

package info (click to toggle)
jedit 5.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,252 kB
  • ctags: 11,190
  • sloc: java: 98,480; xml: 94,070; makefile: 52; sh: 42; cpp: 6; python: 6
file content (718 lines) | stat: -rw-r--r-- 25,905 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
<?xml version="1.0" encoding="UTF-8"?>
<chapter id="bsh-commands">
<!-- jEdit buffer local properties:
      :indentSize=2:noTabs=yes:maxLineLen=90:tabSize=2:
      :xml.root=users-guide.xml:
      jEdit 3.2 Macro Guide, (C) 2001 John Gellene
      Thu Jun 21 23:49:14 EDT 2001 @200 /Internet Time/ -->

    <title>BeanShell Commands</title>

    <para>BeanShell includes a set of <firstterm>commands</firstterm>;
    subroutines that can be called from any script or macro. The following is a
    summary of those commands which may be useful within jEdit.</para>

    <note>
        <para>Java classes in plugins cannot make use of BeanShell commands
        directly. However, these commands can be called from BeanShell code that
        is part of a plugin, for example the snippets in
        <filename>actions.xml</filename>, or any BeanShell scripts shipped with
        the plugin and loaded on startup.</para>
    </note>

    <section id="bsh-commands-output">
        <title>Output Commands</title>

        <itemizedlist>
            <!-- one day jEdit will provide its own error() implementation -->

            <!-- <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>void <function>error</function></funcdef>
          <paramdef>String <parameter>errorMsg</parameter></paramdef>
        </funcprototype>
      </funcsynopsis>
      <para>
        Writes the string represented by <parameter>errorMsg</parameter>
        to the error stream of the current process.
      </para>
    </listitem> -->

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>cat</function></funcdef>

                        <paramdef>String
                        <parameter>filename</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Writes the contents of <parameter>filename</parameter> to
                the activity log.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>javap</function></funcdef>

                        <paramdef>String | Object | Class
                        <parameter>target</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Writes the public fields and methods of the specified
                class to the output stream of the current process. </para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>print</function></funcdef>

                        <paramdef><parameter>arg</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Writes the string value of the argument to the activity
                log, or if run from the <application>Console</application>
                plugin, to the current output window. If
                <parameter>arg</parameter> is an array,
                <function>print</function> runs itself recursively on the
                array's elements.</para>
            </listitem>
        </itemizedlist>
    </section>

    <section id="bsh-commands-file">
        <title>File Management Commands</title>

        <itemizedlist>
            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>cd</function></funcdef>

                        <paramdef>String
                        <parameter>dirname</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Changes the working directory of the BeanShell interpreter
                to <parameter>dirname</parameter>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>cp</function></funcdef>

                        <paramdef>String
                        <parameter>fromFile</parameter></paramdef>

                        <paramdef>String
                        <parameter>toFile</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Copy <parameter>fromFile</parameter> to
                <parameter>toFile</parameter>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>dir</function></funcdef>

                        <paramdef>String
                        <parameter>dirname</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Displays the contents of directory
                <parameter>dirname</parameter>. The format of the display is
                similar to the Unix <function>ls -l</function> command.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>mv</function></funcdef>

                        <paramdef>String
                        <parameter>fromFile</parameter></paramdef>

                        <paramdef>String
                        <parameter>toFile</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Moves the file named by <parameter>fromFile</parameter> to
                <parameter>toFile</parameter>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>File <function>pathToFile</function></funcdef>

                        <paramdef>String
                        <parameter>filename</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Create a <classname>File</classname> object corresponding
                to <function>filename</function>. Relative paths are resolved
                with reference to the BeanShell interpreter's working
                directory.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>pwd</function></funcdef>

                        <void />
                    </funcprototype>
                </funcsynopsis>

                <para>Writes the current working directory of the BeanShell
                interpreter to the output stream of the current process.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>rm</function></funcdef>

                        <paramdef>String
                        <parameter>pathname</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Deletes the file name by
                <parameter>pathname</parameter>.</para>
            </listitem>
        </itemizedlist>
    </section>

    <section id="bsh-commands-serial">
        <title>Component Commands</title>

        <itemizedlist>
            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>JFrame <function>frame</function></funcdef>

                        <paramdef>Component
                        <parameter>frame</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Displays the component in a top-level
                <classname>JFrame</classname>, centered and packed. Returns the
                <classname>JFrame</classname> object.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>Object <function>load</function></funcdef>

                        <paramdef>String
                        <parameter>filename</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Loads and returns a serialized Java object from
                <parameter>filename</parameter>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>save</function></funcdef>

                        <paramdef>Component
                        <parameter>component</parameter></paramdef>

                        <paramdef>String
                        <parameter>filename</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Saves <parameter>component</parameter> in serialized form
                to <parameter>filename</parameter>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>Font <function>setFont</function></funcdef>

                        <paramdef>Component
                        <parameter>comp</parameter></paramdef>

                        <paramdef>int <parameter>ptsize</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Set the font size of <parameter>component</parameter> to
                <parameter>ptsize</parameter> and returns the new font.</para>
            </listitem>
        </itemizedlist>
    </section>

    <section id="bsh-commands-resource">
        <title>Resource Management Commands</title>

        <itemizedlist>
            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>URL <function>getResource</function></funcdef>

                        <paramdef>String <parameter>path</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Returns the resource specified by
                <parameter>path</parameter>. An absolute path must be used to
                return any resource available in the current classpath.</para>
            </listitem>

            <!-- bsh.classpath not supported in jEdit -->

            <!--
    <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>void <function>addClassPath</function></funcdef>
          <paramdef>String <parameter>path</parameter></paramdef>
        </funcprototype>
      </funcsynopsis>
    </listitem>

    <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>void <function>addClassPath</function></funcdef>
          <paramdef>URL <parameter>path</parameter></paramdef>
        </funcprototype>
      </funcsynopsis>
      <para>
        Adds the directory or jar archive file specified by
        <parameter>path</parameter> to the classpath used by the
        interpreter.
      </para>
    </listitem>

    <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>void <function>setClassPath</function></funcdef>
          <paramdef>URL[] <parameter>paths</parameter></paramdef>
        </funcprototype>
      </funcsynopsis>
      <para>
        Changes the classpath for the BeanShell interpreter to the specified
        array of directories and/or archives.
      </para>
    </listitem>

    <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>URL[] <function>getClassPath</function></funcdef>
          <void/>
        </funcprototype>
      </funcsynopsis>
      <para>
        Returns an array containing the current classpath.
      </para>
    </listitem>

    <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>void <function>reloadClasses</function></funcdef>
          <paramdef>String <parameter>packagename</parameter></paramdef>
        </funcprototype>
      </funcsynopsis>
    </listitem>

    <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>void <function>reloadClasses</function></funcdef>
          <void/>
        </funcprototype>
      </funcsynopsis>
      <para>
        Reloads the class or package specified by
        <parameter>packagename</parameter> in the BeanShell interpreter.
        If called without a parameter, reloads all classes
        in the interpreter's classpath.
      </para>
    </listitem>

    <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>Class <function>getClass</function></funcdef>
          <paramdef>String <parameter>classname</parameter></paramdef>
        </funcprototype>
      </funcsynopsis>
      <para>
        This method is similar to the <function>Class.forName()</function>
        method of the Java platform, but it uses the classpath of the
        current BeanShell interpreter, which can contain additional
        classes and packages as well as reloaded classes.
      </para>
    </listitem> -->
        </itemizedlist>
    </section>

    <section id="bsh-commands-script">
        <title>Script Execution Commands</title>

        <itemizedlist>
            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>Thread <function>bg</function></funcdef>

                        <paramdef>String
                        <parameter>filename</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Run the BeanShell script named by
                <parameter>filename</parameter> in a copy of the existing
                namespace and in a separate thread. Returns the
                <classname>Thread</classname> object so created.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>exec</function></funcdef>

                        <paramdef>String
                        <parameter>cmdline</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Start the external process by calling
                <function>Runtime.exec()</function> on
                <parameter>cmdline</parameter>. Any output is directed to the
                output stream of the calling process.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>Object <function>eval</function></funcdef>

                        <paramdef>String
                        <parameter>expression</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Evaluates the string <parameter>expression</parameter> as
                a BeanShell script in the interpreter's current namespace.
                Returns the result of the evaluation of
                <constant>null</constant>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>org.gjt.sp.jedit.bsh.This
                            <function>run</function></funcdef>

                        <paramdef>String
                        <parameter>filename</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Run the BeanShell script named by
                <parameter>filename</parameter> in a copy of the existing
                namespace. The return value represent the object context of the
                script, allowing you to access its variables and methods.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void
                        <function>setAccessibility</function></funcdef>

                        <paramdef>boolean <parameter>flag</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>If <parameter>flag</parameter> is <literal>true</literal>,
                BeanShell scripts are allowed to change and modify private
                variables, and call private methods. The default is
                <literal>false</literal>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void
                        <function>setStrictJava</function></funcdef>

                        <paramdef>boolean <parameter>flag</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>If <parameter>flag</parameter> is <literal>true</literal>,
                BeanShell scripts must follow a much more strict, Java-like
                syntax, and are not able to use the convenience features
                described in <xref
                linkend="macro-tips-BeanShell-convenience" />.</para>
            </listitem>

            <!-- <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>void <function>server</function></funcdef>
          <paramdef>int <parameter>port</parameter></paramdef>
        </funcprototype>
      </funcsynopsis>
      <para>
        Creates a <quote>server</quote> version of the BeanShell
        interpreter that shares the same namespace as the current
        interpreter.  The server interpreter listens on the designated
        port.
      </para>
      <para>
        This requires the <classname>bsh.util</classname> package, which
        is not included with jEdit. It can be found in the stand-alone
        BeanShell distribution, available from <ulink
        url="http://www.beanshell.org">http://www.beanshell.org</ulink>.
      </para>
      <caution><para>
        Security of this port is not guaranteed.  Use this command
        with extreme caution.
      </para></caution>
    </listitem> -->

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>source</function></funcdef>

                        <paramdef>String
                        <parameter>filename</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Evaluates the contents of <parameter>filename</parameter>
                as a BeanShell script in the interpreter's current
                namespace.</para>
            </listitem>
        </itemizedlist>
    </section>

    <section id="bsh-commands-object">
        <title>BeanShell Object Management Commands</title>

        <itemizedlist>
            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef><function>bind</function></funcdef>

                        <paramdef>org.gjt.sp.jedit.bsh.This
                            <parameter>ths</parameter></paramdef>

                        <paramdef>org.gjt.sp.jedit.bsh.Namespace
                        <parameter>namespace</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Binds the scripted object <parameter>ths</parameter> to
                <parameter>namespace</parameter>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>clear</function></funcdef>

                        <void />
                    </funcprototype>
                </funcsynopsis>

                <para>Clear all variables, methods, and imports from this
                namespace. If this namespace is the root, it will be reset to
                the default imports.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>org.gjt.sp.jedit.bsh.This
                            <function>extend</function></funcdef>

                        <paramdef>org.gjt.sp.jedit.bsh.This
                        <parameter>object</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Creates a new BeanShell <classname>This</classname>
                scripted object that is a child of the parameter
                <parameter>object</parameter>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void
                        <function>importObject</function></funcdef>

                        <paramdef>Object
                        <parameter>object</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Import an object into this namespace. This is somewhat
                similar to Java 1.5 static class imports, except you can import
                the methods and fields of a Java object instance into a
                BeanShell namespace, for example:</para>

                <informalexample>
                    <programlisting>Map map = new HashMap();
    importObject( map );
    put("foo", "bar");
    print( get("foo") ); // "bar"</programlisting>
                </informalexample>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>org.gjt.sp.jedit.bsh.This
                            <function>object</function></funcdef>

                        <void />
                    </funcprototype>
                </funcsynopsis>

                <para>Creates a new BeanShell <classname>This</classname>
                scripted object which can hold data members. You can use this to
                create an object for storing miscellaneous crufties, like
                so:</para>

                <informalexample>
                    <programlisting>crufties = object();
crufties.foo = "hello world";
crufties.counter = 5;
...</programlisting>
                </informalexample>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef><function>setNameSpace</function></funcdef>

                        <paramdef>org.gjt.sp.jedit.bsh.Namespace
                        <parameter>namespace</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Set the namespace of the current scope to
                <parameter>namespace</parameter>.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>org.gjt.sp.jedit.bsh.This
                            <function>super</function></funcdef>

                        <paramdef>String
                        <parameter>scopename</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Returns a reference to the BeanShell
                <classname>This</classname> object representing the enclosing
                method scope specified by <parameter>scopename</parameter>. This
                method work similar to the <function>super</function> keyword
                but can refer to enclosing scope at higher levels in a hierarchy
                of scopes.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>unset</function></funcdef>

                        <paramdef>String <parameter>name</parameter></paramdef>
                    </funcprototype>
                </funcsynopsis>

                <para>Removes the variable named by <parameter>name</parameter>
                from the current interpreter namespace. This has the effect of
                <quote>undefining</quote> the variable.</para>
            </listitem>
        </itemizedlist>
    </section>

    <section id="bsh-commands-other">
        <title>Other Commands</title>

        <itemizedlist>
            <!-- <listitem>
      <funcsynopsis>
        <funcprototype>
          <funcdef>void <function>exit</function></funcdef>
          <void/>
        </funcprototype>
      </funcsynopsis>
      <para>
        Calls <function>System.exit(0)</function>.
      </para>
      <caution><para>
        While this command is available, you should always call
        <function>jEdit.exit()</function> instead so the application will
        shutdown in an orderly fashion.
      </para></caution>
    </listitem> -->

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef>void <function>debug</function></funcdef>

                        <void />
                    </funcprototype>
                </funcsynopsis>

                <para>Toggles BeanShell's internal debug reporting to the output
                stream of the current process.</para>
            </listitem>

            <listitem>
                <funcsynopsis>
                    <funcprototype>
                        <funcdef><function>getSourceFileInfo</function></funcdef>

                        <void />
                    </funcprototype>
                </funcsynopsis>

                <para>Returns the name of the file or other source from which
                the BeanShell interpreter is reading.</para>
            </listitem>
        </itemizedlist>
    </section>
</chapter>