factor/library/tools/jedit.factor

108 lines
3.1 KiB
Factor
Raw Normal View History

2004-08-18 01:13:56 -04:00
! :folding=indent:collapseFolds=1:
! $Id$
!
! Copyright (C) 2004 Slava Pestov.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are met:
!
! 1. Redistributions of source code must retain the above copyright notice,
! this list of conditions and the following disclaimer.
!
! 2. Redistributions in binary form must reproduce the above copyright notice,
! this list of conditions and the following disclaimer in the documentation
! and/or other materials provided with the distribution.
!
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: jedit
USE: kernel
2004-08-18 01:13:56 -04:00
USE: lists
USE: namespaces
USE: parser
USE: streams
USE: stdio
USE: strings
USE: unparser
2004-11-16 23:14:01 -05:00
USE: words
2004-08-18 01:13:56 -04:00
: jedit-server-file ( -- path )
"jedit-server-file" get
[ "~" get "/.jedit/server" cat2 ] unless* ;
: jedit-server-info ( -- port auth )
jedit-server-file <file-reader> [
2004-08-18 01:13:56 -04:00
read drop
read parse-number
read parse-number
] with-stream ;
: bool, ( ? -- str )
"true" "false" ? , ;
2004-08-18 01:13:56 -04:00
: list>bsh-array, ( list -- code )
"new String[] {" ,
[ unparse , "," , ] each
"null}" , ;
2004-08-18 01:13:56 -04:00
: make-jedit-request ( files dir params -- code )
[
[
"EditServer.handleClient(" ,
"restore" get bool, "," ,
"newView" get bool, "," ,
"newPlainView" get bool, "," ,
( If the dir is not set, we don't want to send f )
dup [ unparse ] [ drop "null" ] ifte , "," ,
list>bsh-array, ");\n" ,
] make-string
2004-08-18 01:13:56 -04:00
] bind ;
: send-jedit-request ( request -- )
jedit-server-info swap "localhost" swap <client> [
write-big-endian-32
dup str-length write-big-endian-16
write flush
2004-08-18 01:13:56 -04:00
] with-stream ;
2004-11-16 23:14:01 -05:00
: jedit-line/file ( line dir file -- )
2004-08-18 01:13:56 -04:00
rot "+line:" swap unparse cat2 unit cons swap
<namespace> [
"restore" off
"newView" off
"newPlainView" off
] extend make-jedit-request send-jedit-request ;
2004-11-16 23:14:01 -05:00
: word-file ( path -- dir file )
dup [
2004-12-19 03:04:03 -05:00
"resource:/" ?str-head [
resource-path swap
2004-11-16 23:14:01 -05:00
] [
2004-12-19 03:04:03 -05:00
f swap
2004-11-16 23:14:01 -05:00
] ifte
] [
f
] ifte ;
: word-line/file ( word -- line dir file )
#! Note that line numbers here start from 1
dup "line" word-property swap "file" word-property
word-file ;
: jedit ( word -- )
word-line/file dup [
jedit-line/file
] [
3drop "Unknown source" print
] ifte ;