diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 3f1d8b041f..eba5ddee8e 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -28,6 +28,7 @@ + listener/plugin: +- words with < in name - auto insert USE: - why > 1 popup - listener backspace overzealous diff --git a/library/image.factor b/library/image.factor index 05a0816714..f2fd2f637f 100644 --- a/library/image.factor +++ b/library/image.factor @@ -341,28 +341,11 @@ IN: cross-compiler ( 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 -- ) "big-endian" get [ - write-big-endian + big-endian-32 ] [ - write-little-endian + little-endian-32 ] ifte ; : write-image ( image file -- ) diff --git a/library/jedit/jedit-local.factor b/library/jedit/jedit-local.factor new file mode 100644 index 0000000000..516b2613ce --- /dev/null +++ b/library/jedit/jedit-local.factor @@ -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 ; diff --git a/library/jedit/jedit-remote.factor b/library/jedit/jedit-remote.factor new file mode 100644 index 0000000000..4df69cab06 --- /dev/null +++ b/library/jedit/jedit-remote.factor @@ -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 [ + 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 [ + 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 + [ + "restore" off + "newView" off + "newPlainView" off + ] extend make-jedit-request send-jedit-request ; diff --git a/library/jedit/jedit.factor b/library/jedit/jedit.factor index 8f3bf28567..409503a7b4 100644 --- a/library/jedit/jedit.factor +++ b/library/jedit/jedit.factor @@ -28,73 +28,23 @@ IN: jedit USE: arithmetic USE: combinators +USE: kernel USE: namespaces USE: stack USE: strings USE: words -: view ( -- view ) - [ ] "org.gjt.sp.jedit.jEdit" - "getActiveView" jinvoke-static ; +! Doesn't exist in native Factor. +DEFER: local-jedit-line/file -: edit-pane ( -- editPane ) - view - [ ] "org.gjt.sp.jedit.View" "getEditPane" jinvoke ; +: jedit-local? ( -- ? ) + java? [ global [ "jedit" get ] bind ] [ f ] ifte ; -: 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* ; - -: open-line/file ( line dir file -- ) - open-file [ - wait-for-requests text-area goto-line +: jedit-line/file ( line dir file -- ) + jedit-local? [ + local-jedit-line/file ] [ - drop + remote-jedit-line/file ] ifte ; : resource-path ( -- path ) @@ -109,7 +59,7 @@ USE: words : word-line/file ( word -- line dir file ) #! 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 -- ) - intern word-line/file open-line/file ; + intern word-line/file jedit-line/file ; diff --git a/library/platform/jvm/boot-sumo.factor b/library/platform/jvm/boot-sumo.factor index eba9a97d3c..da24cf63aa 100644 --- a/library/platform/jvm/boot-sumo.factor +++ b/library/platform/jvm/boot-sumo.factor @@ -85,6 +85,7 @@ USE: parser "/library/math/simpson.factor" run-resource ! math !!! Development tools. +"/library/stdio-binary.factor" run-resource ! stdio "/library/vocabulary-style.factor" run-resource ! style "/library/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 !!! 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... "/library/init.factor" run-resource ! init diff --git a/library/platform/native/boot.factor b/library/platform/native/boot.factor index e9c0cf231b..aaf8216558 100644 --- a/library/platform/native/boot.factor +++ b/library/platform/native/boot.factor @@ -69,6 +69,7 @@ primitives, "/library/random.factor" "/library/sbuf.factor" "/library/stdio.factor" + "/library/stdio-binary.factor" "/library/stream.factor" "/library/strings.factor" "/library/styles.factor" diff --git a/library/stdio-binary.factor b/library/stdio-binary.factor new file mode 100644 index 0000000000..8cdc5de8b9 --- /dev/null +++ b/library/stdio-binary.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 ;