communicating with jedit over a socket
parent
7eecd21b19
commit
a0b66d2028
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
+ listener/plugin:
|
+ listener/plugin:
|
||||||
|
|
||||||
|
- words with < in name
|
||||||
- auto insert USE:
|
- auto insert USE:
|
||||||
- why > 1 popup
|
- why > 1 popup
|
||||||
- listener backspace overzealous
|
- listener backspace overzealous
|
||||||
|
|
|
@ -341,28 +341,11 @@ IN: cross-compiler
|
||||||
|
|
||||||
( Image output )
|
( Image output )
|
||||||
|
|
||||||
: byte0 ( num -- byte ) 24 shift> HEX: ff bitand ;
|
|
||||||
: byte1 ( num -- byte ) 16 shift> HEX: ff bitand ;
|
|
||||||
: byte2 ( num -- byte ) 8 shift> HEX: ff bitand ;
|
|
||||||
: byte3 ( num -- byte ) HEX: ff bitand ;
|
|
||||||
|
|
||||||
: write-little-endian ( word -- )
|
|
||||||
dup byte3 >char write
|
|
||||||
dup byte2 >char write
|
|
||||||
dup byte1 >char write
|
|
||||||
byte0 >char write ;
|
|
||||||
|
|
||||||
: write-big-endian ( word -- )
|
|
||||||
dup byte0 >char write
|
|
||||||
dup byte1 >char write
|
|
||||||
dup byte2 >char write
|
|
||||||
byte3 >char write ;
|
|
||||||
|
|
||||||
: write-word ( word -- )
|
: write-word ( word -- )
|
||||||
"big-endian" get [
|
"big-endian" get [
|
||||||
write-big-endian
|
big-endian-32
|
||||||
] [
|
] [
|
||||||
write-little-endian
|
little-endian-32
|
||||||
] ifte ;
|
] ifte ;
|
||||||
|
|
||||||
: write-image ( image file -- )
|
: write-image ( image file -- )
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
! :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: arithmetic
|
||||||
|
USE: combinators
|
||||||
|
USE: namespaces
|
||||||
|
USE: stack
|
||||||
|
USE: strings
|
||||||
|
USE: words
|
||||||
|
|
||||||
|
: view ( -- view )
|
||||||
|
[ ] "org.gjt.sp.jedit.jEdit"
|
||||||
|
"getActiveView" jinvoke-static ;
|
||||||
|
|
||||||
|
: edit-pane ( -- editPane )
|
||||||
|
view
|
||||||
|
[ ] "org.gjt.sp.jedit.View" "getEditPane" jinvoke ;
|
||||||
|
|
||||||
|
: text-area ( -- textArea )
|
||||||
|
edit-pane
|
||||||
|
[ ] "org.gjt.sp.jedit.EditPane" "getTextArea" jinvoke ;
|
||||||
|
|
||||||
|
: text-area-buffer ( textArea -- buffer )
|
||||||
|
[ ] "org.gjt.sp.jedit.textarea.JEditTextArea"
|
||||||
|
"getBuffer" jinvoke ;
|
||||||
|
|
||||||
|
: buffer ( -- buffer )
|
||||||
|
edit-pane
|
||||||
|
[ ] "org.gjt.sp.jedit.EditPane" "getBuffer" jinvoke ;
|
||||||
|
|
||||||
|
: open-file* ( view parent path newFile props -- buffer )
|
||||||
|
[
|
||||||
|
"org.gjt.sp.jedit.View"
|
||||||
|
"java.lang.String"
|
||||||
|
"java.lang.String"
|
||||||
|
"boolean"
|
||||||
|
"java.util.Hashtable"
|
||||||
|
] "org.gjt.sp.jedit.jEdit" "openFile" jinvoke-static ;
|
||||||
|
|
||||||
|
: open-file ( parent path -- buffer )
|
||||||
|
view -rot f f open-file* ;
|
||||||
|
|
||||||
|
: wait-for-requests ( -- )
|
||||||
|
[ ]
|
||||||
|
"org.gjt.sp.jedit.io.VFSManager" "waitForRequests"
|
||||||
|
jinvoke-static ;
|
||||||
|
|
||||||
|
: line-count ( textarea -- lines )
|
||||||
|
[ ] "org.gjt.sp.jedit.textarea.JEditTextArea" "getLineCount"
|
||||||
|
jinvoke ;
|
||||||
|
|
||||||
|
: line>start-offset ( line textarea -- )
|
||||||
|
[ "int" ]
|
||||||
|
"org.gjt.sp.jedit.textarea.JEditTextArea"
|
||||||
|
"getLineStartOffset" jinvoke ;
|
||||||
|
|
||||||
|
: set-caret ( caret textarea -- )
|
||||||
|
[ "int" ]
|
||||||
|
"org.gjt.sp.jedit.textarea.JEditTextArea"
|
||||||
|
"setCaretPosition" jinvoke ;
|
||||||
|
|
||||||
|
: goto-line* ( line textarea -- )
|
||||||
|
tuck line>start-offset swap set-caret ;
|
||||||
|
|
||||||
|
: goto-line ( line textarea -- )
|
||||||
|
tuck line-count min swap goto-line* ;
|
||||||
|
|
||||||
|
: local-jedit-line/file ( line dir file -- )
|
||||||
|
open-file [
|
||||||
|
wait-for-requests pred text-area goto-line
|
||||||
|
] [
|
||||||
|
drop
|
||||||
|
] ifte ;
|
|
@ -0,0 +1,81 @@
|
||||||
|
! :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: combinators
|
||||||
|
USE: lists
|
||||||
|
USE: logic
|
||||||
|
USE: namespaces
|
||||||
|
USE: parser
|
||||||
|
USE: stack
|
||||||
|
USE: streams
|
||||||
|
USE: stdio
|
||||||
|
USE: strings
|
||||||
|
USE: unparser
|
||||||
|
|
||||||
|
: jedit-server-file ( -- path )
|
||||||
|
"jedit-server-file" get
|
||||||
|
[ "~" get "/.jedit/server" cat2 ] unless* ;
|
||||||
|
|
||||||
|
: jedit-server-info ( -- port auth )
|
||||||
|
jedit-server-file <filecr> [
|
||||||
|
read drop
|
||||||
|
read parse-number
|
||||||
|
read parse-number
|
||||||
|
] with-stream ;
|
||||||
|
|
||||||
|
: bool% ( ? -- str )
|
||||||
|
"true" "false" ? % ;
|
||||||
|
|
||||||
|
: list>bsh-array% ( list -- code )
|
||||||
|
"new String[] {" %
|
||||||
|
[ unparse % "," % ] each
|
||||||
|
"null}" % ;
|
||||||
|
|
||||||
|
: make-jedit-request ( files dir params -- code )
|
||||||
|
[
|
||||||
|
<%
|
||||||
|
"EditServer.handleClient(" %
|
||||||
|
"restore" get bool% "," %
|
||||||
|
"newView" get bool% "," %
|
||||||
|
"newPlainView" get bool% "," %
|
||||||
|
unparse % "," %
|
||||||
|
list>bsh-array% ");\n" % %>
|
||||||
|
] bind ;
|
||||||
|
|
||||||
|
: send-jedit-request ( request -- )
|
||||||
|
jedit-server-info swap "localhost" swap <client> [
|
||||||
|
big-endian-32 dup str-length big-endian-16 write flush
|
||||||
|
] with-stream ;
|
||||||
|
|
||||||
|
: remote-jedit-line/file ( line dir file -- )
|
||||||
|
rot "+line:" swap unparse cat2 unit cons swap
|
||||||
|
<namespace> [
|
||||||
|
"restore" off
|
||||||
|
"newView" off
|
||||||
|
"newPlainView" off
|
||||||
|
] extend make-jedit-request send-jedit-request ;
|
|
@ -28,73 +28,23 @@
|
||||||
IN: jedit
|
IN: jedit
|
||||||
USE: arithmetic
|
USE: arithmetic
|
||||||
USE: combinators
|
USE: combinators
|
||||||
|
USE: kernel
|
||||||
USE: namespaces
|
USE: namespaces
|
||||||
USE: stack
|
USE: stack
|
||||||
USE: strings
|
USE: strings
|
||||||
USE: words
|
USE: words
|
||||||
|
|
||||||
: view ( -- view )
|
! Doesn't exist in native Factor.
|
||||||
[ ] "org.gjt.sp.jedit.jEdit"
|
DEFER: local-jedit-line/file
|
||||||
"getActiveView" jinvoke-static ;
|
|
||||||
|
|
||||||
: edit-pane ( -- editPane )
|
: jedit-local? ( -- ? )
|
||||||
view
|
java? [ global [ "jedit" get ] bind ] [ f ] ifte ;
|
||||||
[ ] "org.gjt.sp.jedit.View" "getEditPane" jinvoke ;
|
|
||||||
|
|
||||||
: text-area ( -- textArea )
|
: jedit-line/file ( line dir file -- )
|
||||||
edit-pane
|
jedit-local? [
|
||||||
[ ] "org.gjt.sp.jedit.EditPane" "getTextArea" jinvoke ;
|
local-jedit-line/file
|
||||||
|
|
||||||
: text-area-buffer ( textArea -- buffer )
|
|
||||||
[ ] "org.gjt.sp.jedit.textarea.JEditTextArea"
|
|
||||||
"getBuffer" jinvoke ;
|
|
||||||
|
|
||||||
: buffer ( -- buffer )
|
|
||||||
edit-pane
|
|
||||||
[ ] "org.gjt.sp.jedit.EditPane" "getBuffer" jinvoke ;
|
|
||||||
|
|
||||||
: open-file* ( view parent path newFile props -- buffer )
|
|
||||||
[
|
|
||||||
"org.gjt.sp.jedit.View"
|
|
||||||
"java.lang.String"
|
|
||||||
"java.lang.String"
|
|
||||||
"boolean"
|
|
||||||
"java.util.Hashtable"
|
|
||||||
] "org.gjt.sp.jedit.jEdit" "openFile" jinvoke-static ;
|
|
||||||
|
|
||||||
: open-file ( parent path -- buffer )
|
|
||||||
view -rot f f open-file* ;
|
|
||||||
|
|
||||||
: wait-for-requests ( -- )
|
|
||||||
[ ]
|
|
||||||
"org.gjt.sp.jedit.io.VFSManager" "waitForRequests"
|
|
||||||
jinvoke-static ;
|
|
||||||
|
|
||||||
: line-count ( textarea -- lines )
|
|
||||||
[ ] "org.gjt.sp.jedit.textarea.JEditTextArea" "getLineCount"
|
|
||||||
jinvoke ;
|
|
||||||
|
|
||||||
: line>start-offset ( line textarea -- )
|
|
||||||
[ "int" ]
|
|
||||||
"org.gjt.sp.jedit.textarea.JEditTextArea"
|
|
||||||
"getLineStartOffset" jinvoke ;
|
|
||||||
|
|
||||||
: set-caret ( caret textarea -- )
|
|
||||||
[ "int" ]
|
|
||||||
"org.gjt.sp.jedit.textarea.JEditTextArea"
|
|
||||||
"setCaretPosition" jinvoke ;
|
|
||||||
|
|
||||||
: goto-line* ( line textarea -- )
|
|
||||||
tuck line>start-offset swap set-caret ;
|
|
||||||
|
|
||||||
: goto-line ( line textarea -- )
|
|
||||||
tuck line-count min swap goto-line* ;
|
|
||||||
|
|
||||||
: open-line/file ( line dir file -- )
|
|
||||||
open-file [
|
|
||||||
wait-for-requests text-area goto-line
|
|
||||||
] [
|
] [
|
||||||
drop
|
remote-jedit-line/file
|
||||||
] ifte ;
|
] ifte ;
|
||||||
|
|
||||||
: resource-path ( -- path )
|
: resource-path ( -- path )
|
||||||
|
@ -109,7 +59,7 @@ USE: words
|
||||||
|
|
||||||
: word-line/file ( word -- line dir file )
|
: word-line/file ( word -- line dir file )
|
||||||
#! Note that line numbers here start from 1
|
#! Note that line numbers here start from 1
|
||||||
[ "line" get pred "file" get word-file ] bind ;
|
[ "line" get "file" get word-file ] bind ;
|
||||||
|
|
||||||
: jedit ( word -- )
|
: jedit ( word -- )
|
||||||
intern word-line/file open-line/file ;
|
intern word-line/file jedit-line/file ;
|
||||||
|
|
|
@ -85,6 +85,7 @@ USE: parser
|
||||||
"/library/math/simpson.factor" run-resource ! math
|
"/library/math/simpson.factor" run-resource ! math
|
||||||
|
|
||||||
!!! Development tools.
|
!!! Development tools.
|
||||||
|
"/library/stdio-binary.factor" run-resource ! stdio
|
||||||
"/library/vocabulary-style.factor" run-resource ! style
|
"/library/vocabulary-style.factor" run-resource ! style
|
||||||
"/library/prettyprint.factor" run-resource ! prettyprint
|
"/library/prettyprint.factor" run-resource ! prettyprint
|
||||||
"/library/platform/jvm/prettyprint.factor" run-resource ! prettyprint
|
"/library/platform/jvm/prettyprint.factor" run-resource ! prettyprint
|
||||||
|
@ -118,7 +119,9 @@ USE: parser
|
||||||
"/library/httpd/default-responders.factor" run-resource ! default-responders
|
"/library/httpd/default-responders.factor" run-resource ! default-responders
|
||||||
|
|
||||||
!!! jEdit integration.
|
!!! jEdit integration.
|
||||||
"/library/jedit/jedit.factor" run-resource ! jedit
|
"/library/jedit/jedit-local.factor" run-resource ! jedit
|
||||||
|
"/library/jedit/jedit-remote.factor" run-resource ! jedit
|
||||||
|
"/library/jedit/jedit.factor" run-resource ! jedit
|
||||||
|
|
||||||
!!! Final initialization...
|
!!! Final initialization...
|
||||||
"/library/init.factor" run-resource ! init
|
"/library/init.factor" run-resource ! init
|
||||||
|
|
|
@ -69,6 +69,7 @@ primitives,
|
||||||
"/library/random.factor"
|
"/library/random.factor"
|
||||||
"/library/sbuf.factor"
|
"/library/sbuf.factor"
|
||||||
"/library/stdio.factor"
|
"/library/stdio.factor"
|
||||||
|
"/library/stdio-binary.factor"
|
||||||
"/library/stream.factor"
|
"/library/stream.factor"
|
||||||
"/library/strings.factor"
|
"/library/strings.factor"
|
||||||
"/library/styles.factor"
|
"/library/styles.factor"
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
! :folding=indent:collapseFolds=1:
|
||||||
|
|
||||||
|
! $Id$
|
||||||
|
!
|
||||||
|
! Copyright (C) 2003, 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: stdio
|
||||||
|
USE: arithmetic
|
||||||
|
USE: stack
|
||||||
|
USE: streams
|
||||||
|
USE: strings
|
||||||
|
|
||||||
|
: byte3 ( num -- byte ) 24 shift> HEX: ff bitand ;
|
||||||
|
: byte2 ( num -- byte ) 16 shift> HEX: ff bitand ;
|
||||||
|
: byte1 ( num -- byte ) 8 shift> HEX: ff bitand ;
|
||||||
|
: byte0 ( num -- byte ) HEX: ff bitand ;
|
||||||
|
|
||||||
|
: little-endian-32 ( word -- )
|
||||||
|
dup byte0 >char write
|
||||||
|
dup byte1 >char write
|
||||||
|
dup byte2 >char write
|
||||||
|
byte3 >char write ;
|
||||||
|
|
||||||
|
: big-endian-32 ( word -- )
|
||||||
|
dup byte3 >char write
|
||||||
|
dup byte2 >char write
|
||||||
|
dup byte1 >char write
|
||||||
|
byte0 >char write ;
|
||||||
|
|
||||||
|
: little-endian-16 ( char -- )
|
||||||
|
dup byte0 >char write
|
||||||
|
byte1 >char write ;
|
||||||
|
|
||||||
|
: big-endian-16 ( char -- )
|
||||||
|
dup byte1 >char write
|
||||||
|
byte0 >char write ;
|
Loading…
Reference in New Issue