2005-02-08 22:02:44 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-08-18 01:13:56 -04:00
|
|
|
IN: jedit
|
2005-09-20 20:18:01 -04:00
|
|
|
USING: arrays errors io kernel listener lists math namespaces
|
2005-12-17 09:55:00 -05:00
|
|
|
parser prettyprint sequences strings words ;
|
2004-08-18 01:13:56 -04:00
|
|
|
|
2005-07-17 16:29:17 -04:00
|
|
|
! Some words to send requests to a running jEdit instance to
|
|
|
|
! edit files and position the cursor on a specific line number.
|
|
|
|
|
2004-08-18 01:13:56 -04:00
|
|
|
: jedit-server-info ( -- port auth )
|
2005-09-14 00:37:50 -04:00
|
|
|
"~" get "/.jedit/server" append <file-reader> [
|
2005-07-21 21:43:37 -04:00
|
|
|
readln drop
|
2005-08-21 20:50:14 -04:00
|
|
|
readln string>number
|
|
|
|
readln string>number
|
2004-08-18 01:13:56 -04:00
|
|
|
] with-stream ;
|
|
|
|
|
2005-02-08 22:02:44 -05:00
|
|
|
: make-jedit-request ( files params -- code )
|
2004-08-18 01:13:56 -04:00
|
|
|
[
|
2005-08-21 20:50:14 -04:00
|
|
|
"EditServer.handleClient(false,false,false,null," write
|
|
|
|
"new String[] {" write
|
|
|
|
[ pprint "," write ] each
|
|
|
|
"null});\n" write
|
|
|
|
] string-out ;
|
2004-08-18 01:13:56 -04:00
|
|
|
|
|
|
|
: send-jedit-request ( request -- )
|
|
|
|
jedit-server-info swap "localhost" swap <client> [
|
2005-06-14 05:01:07 -04:00
|
|
|
4 >be write
|
|
|
|
dup length 2 >be write
|
2005-09-14 00:37:50 -04:00
|
|
|
write
|
2004-08-18 01:13:56 -04:00
|
|
|
] with-stream ;
|
|
|
|
|
2005-02-08 22:02:44 -05:00
|
|
|
: jedit-line/file ( file line -- )
|
2005-09-11 20:46:55 -04:00
|
|
|
number>string "+line:" swap append 2array
|
2005-02-08 22:02:44 -05:00
|
|
|
make-jedit-request send-jedit-request ;
|
2004-11-16 23:14:01 -05:00
|
|
|
|
2005-02-08 22:02:44 -05:00
|
|
|
: jedit-file ( file -- )
|
2005-09-11 20:46:55 -04:00
|
|
|
1array make-jedit-request send-jedit-request ;
|
2004-11-16 23:14:01 -05:00
|
|
|
|
|
|
|
: jedit ( word -- )
|
2005-02-08 22:02:44 -05:00
|
|
|
#! Note that line numbers here start from 1
|
2005-09-14 00:37:50 -04:00
|
|
|
dup word-file swap "line" word-prop jedit-line/file ;
|
2005-07-17 16:29:17 -04:00
|
|
|
|
|
|
|
! Wire protocol for jEdit to evaluate Factor code.
|
|
|
|
! Packets are of the form:
|
|
|
|
!
|
|
|
|
! 4 bytes length
|
|
|
|
! <n> bytes data
|
|
|
|
!
|
|
|
|
! jEdit sends a packet with code to eval, it receives the output
|
|
|
|
! captured with string-out.
|
|
|
|
|
|
|
|
: write-len ( seq -- ) length 4 >be write ;
|
|
|
|
|
|
|
|
: write-packet ( string -- ) dup write-len write flush ;
|
|
|
|
|
|
|
|
: read-packet ( -- string ) 4 read be> read ;
|
|
|
|
|
2005-08-23 15:50:32 -04:00
|
|
|
: eval>string ( str -- )
|
2006-01-05 00:33:12 -05:00
|
|
|
[ [ [ eval ] keep ] try drop ] string-out ;
|
2005-08-23 15:50:32 -04:00
|
|
|
|
2005-07-17 16:29:17 -04:00
|
|
|
: wire-server ( -- )
|
|
|
|
#! Repeatedly read jEdit requests and execute them. Return
|
|
|
|
#! on EOF.
|
|
|
|
read-packet [ eval>string write-packet wire-server ] when* ;
|
|
|
|
|
|
|
|
: jedit-lookup ( word -- list )
|
|
|
|
#! A utility word called by the Factor plugin to get some
|
|
|
|
#! required word info.
|
|
|
|
dup [
|
|
|
|
[
|
2005-08-30 18:12:21 -04:00
|
|
|
dup definer ,
|
|
|
|
dup word-vocabulary ,
|
|
|
|
dup word-name ,
|
|
|
|
"stack-effect" word-prop ,
|
|
|
|
] [ ] make
|
2005-07-17 16:29:17 -04:00
|
|
|
] when ;
|
|
|
|
|
|
|
|
: completions ( str pred -- list | pred: str word -- ? )
|
|
|
|
#! Make a list of completions. Each element of the list is
|
|
|
|
#! a vocabulary/name/stack-effect triplet list.
|
|
|
|
word-subset-with [ jedit-lookup ] map ;
|
2005-09-20 20:18:01 -04:00
|
|
|
|
|
|
|
! The telnet server is for the jEdit plugin.
|
|
|
|
: telnetd ( port -- )
|
|
|
|
\ telnetd [ print-banner listener ] with-server ;
|
|
|
|
|
2005-12-17 09:55:00 -05:00
|
|
|
: search ( name vocabs -- word )
|
|
|
|
dupd [ lookup ] find-with nip lookup ;
|
|
|
|
|
2005-09-20 20:18:01 -04:00
|
|
|
IN: shells
|
|
|
|
|
|
|
|
: telnet
|
|
|
|
"telnetd-port" get string>number telnetd ;
|
|
|
|
|
|
|
|
! This is a string since we string>number it above.
|
|
|
|
global [ "9999" "telnetd-port" set ] bind
|