]> gitweb.factorcode.org Git - factor.git/commitdiff
Factor is now a console shell
authorSlava Pestov <slava@factorcode.org>
Sun, 31 Oct 2004 01:41:25 +0000 (01:41 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 31 Oct 2004 01:41:25 +0000 (01:41 +0000)
18 files changed:
TODO.FACTOR.txt
build.xml
dockables.xml [deleted file]
factor/FactorInterpreter.java
factor/FactorJava.java
factor/jedit/EvalListener.java [deleted file]
factor/jedit/FactorListener.java [deleted file]
factor/jedit/FactorListenerPanel.java [deleted file]
factor/jedit/FactorPlugin.java
factor/jedit/FactorPlugin.props
factor/jedit/FactorShell.java [new file with mode: 0644]
factor/jedit/ListenerHistoryText.java [deleted file]
factor/jedit/WordPreview.java
library/jedit/console.factor [new file with mode: 0644]
library/jedit/listener.factor [deleted file]
library/platform/jvm/boot-sumo.factor
library/platform/jvm/kernel.factor
services.xml

index 1079c0608e3bf20a473cff7be2aaecb9149bbccc..f259c3cf1786b927d35b6b70c070df2e93d5c5a2 100644 (file)
@@ -1,6 +1,6 @@
+\r
 FFI:\r
 \r
-- listener: use console shell api\r
 - add a socket timeout\r
 - fix error postoning -- not all errors thrown by i/o code are\r
   postponed\r
index 656e12bcbb666e4a39efd0267d775cbbba3d42a1..b227a06d0f2f9ab6ce4751dc0c10aafca9f898fd 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -23,6 +23,7 @@
        <path id="jedit-classpath">
                <pathelement location="${user.home}/.jedit/jars/ErrorList.jar" />
                <pathelement location="${user.home}/.jedit/jars/SideKick.jar" />
+               <pathelement location="${user.home}/.jedit/jars/Console.jar" />
        </path>
 
        <target name="compile-jedit" depends="init" if="jedit">
diff --git a/dockables.xml b/dockables.xml
deleted file mode 100644 (file)
index 1e3555b..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0"?>
-
-<!-- For jEdit plugin -->
-
-<!DOCTYPE DOCKABLES SYSTEM "dockables.dtd">
-
-<DOCKABLES>
-       <DOCKABLE NAME="factor">
-               new factor.jedit.FactorListenerPanel(
-                       factor.jedit.FactorPlugin.getInterpreter());
-       </DOCKABLE>
-</DOCKABLES>
index 923d44b1bf17531a3db407a3952e2dbe515f257d..2e5e477f245bd07d323c55a2cfdd83611772d6bc 100644 (file)
@@ -604,14 +604,11 @@ public class FactorInterpreter implements FactorObject, Runnable
                namestack.push(global);
                catchstack.top = 0;
                // DEFER: the word
-               define("kernel","exit*");
-               catchstack.push(new Cons(new Integer(1),
-                       new Cons(searchVocabulary("kernel","exit*"),null)));
-               define("continuations","suspend");
+               define("kernel","toplevel");
                define("errors","default-error-handler");
                catchstack.push(new Cons(searchVocabulary("errors",
                        "default-error-handler"),
-                       new Cons(searchVocabulary("continuations","suspend"),
+                       new Cons(searchVocabulary("kernel","toplevel"),
                        null)));
                callframe = null;
        } //}}}
index ff814aa58b23ff7b96b1029b11e4ed4e974bbf54..3d41425c7a282b697482675e619c434597f8f2ad 100644 (file)
@@ -70,30 +70,7 @@ public class FactorJava
                int i = 0;
                while(classes != null)
                {
-                       Object car = classes.car;
-                       if(car instanceof Cons)
-                       {
-                               Cons classSpec = (Cons)car;
-                               if(classSpec.cdr != null)
-                               {
-                                       throw new FactorRuntimeException(
-                                               "Bad class spec: " + car);
-                               }
-                               Class clazz = (Class)classSpec.car(Class.class);
-                               if(clazz.isPrimitive())
-                               {
-                                       _classes[i] = getClass("["
-                                               + javaClassToVMClass(clazz));
-                               }
-                               else
-                               {
-                                       _classes[i] = getClass("[L"
-                                               + clazz.getName() + ";");
-                               }
-                       }
-                       else
-                               _classes[i] = (Class)classes.car(Class.class);
-
+                       _classes[i] = toClass(classes.car);
                        i++;
                        classes = classes.next();
                }
@@ -278,6 +255,24 @@ public class FactorJava
        {
                if(arg instanceof Class)
                        return (Class)arg;
+               else if(arg instanceof Cons)
+               {
+                       Cons classSpec = (Cons)arg;
+                       if(classSpec.cdr != null)
+                       {
+                               throw new FactorException(
+                                       "Bad class spec: " + classSpec);
+                       }
+                       Class clazz = toClass(classSpec.car);
+                       if(clazz.isPrimitive())
+                       {
+                               return getClass("[" + javaClassToVMClass(clazz));
+                       }
+                       else
+                       {
+                               return getClass("[L" + clazz.getName() + ";");
+                       }
+               }
                else
                {
                        return getClass((String)
diff --git a/factor/jedit/EvalListener.java b/factor/jedit/EvalListener.java
deleted file mode 100644 (file)
index 745146e..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* :folding=explicit: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.
- */
-
-package factor.jedit;
-
-import factor.Cons;
-import java.util.EventListener;
-
-public interface EvalListener extends EventListener
-{
-       public void eval(Cons code);
-}
diff --git a/factor/jedit/FactorListener.java b/factor/jedit/FactorListener.java
deleted file mode 100644 (file)
index ca792ce..0000000
+++ /dev/null
@@ -1,424 +0,0 @@
-/* :folding=explicit: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.
- */
-
-package factor.jedit;
-
-import factor.*;
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-
-public class FactorListener extends JTextPane
-{
-       private static final Cursor MoveCursor
-               = Cursor.getPredefinedCursor
-               (Cursor.HAND_CURSOR);
-       private static final Cursor DefaultCursor
-               = Cursor.getPredefinedCursor
-               (Cursor.TEXT_CURSOR);
-       private static final Cursor WaitCursor
-               = Cursor.getPredefinedCursor
-               (Cursor.WAIT_CURSOR);
-
-       public static final Object Input = new Object();
-       public static final Object Actions = new Object();
-
-       private EventListenerList listenerList;
-
-       private Cons readLineContinuation;
-       private int cmdStart = -1;
-       private ListenerHistoryText history;
-
-       //{{{ FactorListener constructor
-       public FactorListener()
-       {
-               MouseHandler mouse = new MouseHandler();
-               addMouseListener(mouse);
-               addMouseMotionListener(mouse);
-
-               history = new ListenerHistoryText(this,"factor");
-
-               listenerList = new EventListenerList();
-
-               InputMap inputMap = getInputMap();
-               
-               /* Press enter to evaluate the input */
-               inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
-                       new EnterAction());
-
-               /* Press backspace to stop backspacing over the prompt */
-               inputMap.put(KeyStroke.getKeyStroke('\b'),
-                       new BackspaceAction());
-
-               inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME,0),
-                       new HomeAction());
-
-               /* Press Up/Down to access history */
-               inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,0),
-                       new HistoryUpAction());
-
-               inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0),
-                       new HistoryDownAction());
-
-               /* Workaround */
-               inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE,0),
-                       new DummyAction());
-
-               getDocument().addDocumentListener(new DocumentHandler());
-       } //}}}
-
-       //{{{ insertWithAttrs() method
-       public void insertWithAttrs(String text, AttributeSet attrs)
-               throws BadLocationException
-       {
-               if(text == null)
-                       throw new NullPointerException();
-
-               StyledDocument doc = (StyledDocument)getDocument();
-               int offset1 = doc.getLength();
-               doc.insertString(offset1,text,null);
-               int offset2 = offset1 + text.length();
-               doc.setCharacterAttributes(offset1,offset2,attrs,true);
-               setCaretPosition(offset2);
-       } //}}}
-
-       //{{{ readLine() method
-       public void readLine(Cons continuation)
-               throws BadLocationException
-       {
-               StyledDocument doc = (StyledDocument)getDocument();
-               cmdStart = doc.getLength();
-               setCursor(DefaultCursor);
-               this.readLineContinuation = continuation;
-               setCaretPosition(cmdStart);
-       } //}}}
-
-       //{{{ addEvalListener() method
-       public void addEvalListener(EvalListener l)
-       {
-               listenerList.add(EvalListener.class,l);
-       } //}}}
-
-       //{{{ removeEvalListener() method
-       public void removeEvalListener(EvalListener l)
-       {
-               listenerList.remove(EvalListener.class,l);
-       } //}}}
-
-       //{{{ eval() method
-       public void eval(String eval)
-       {
-               if(eval == null)
-                       return;
-
-               try
-               {
-                       StyledDocument doc = (StyledDocument)getDocument();
-                       setCaretPosition(doc.getLength());
-                       doc.insertString(doc.getLength(),eval + "\n",
-                               getCharacterAttributes());
-               }
-               catch(BadLocationException ble)
-               {
-                       ble.printStackTrace();
-               }
-               fireEvalEvent(eval);
-       } //}}}
-
-       //{{{ fireEvalEvent() method
-       public void fireEvalEvent(String code)
-       {
-               setCursor(WaitCursor);
-
-               Cons quot = new Cons(code,readLineContinuation);
-               //readLineContinuation = null;
-
-               Object[] listeners = listenerList.getListenerList();
-               for(int i = 0; i < listeners.length; i++)
-               {
-                       if(listeners[i] == EvalListener.class)
-                       {
-                               EvalListener l = (EvalListener)listeners[i+1];
-                               l.eval(quot);
-                       }
-               }
-       } //}}}
-
-       //{{{ getAttributes() method
-       private AttributeSet getAttributes(int pos)
-       {
-               StyledDocument doc = (StyledDocument)getDocument();
-               Element e = doc.getCharacterElement(pos);
-               return e.getAttributes();
-       } //}}}
-
-       //{{{ getActions() method
-       private Cons getActions(int pos)
-       {
-               AttributeSet a = getAttributes(pos);
-               if(a == null)
-                       return null;
-               else
-                       return (Cons)a.getAttribute(Actions);
-       } //}}}
-
-       //{{{ getActionsPopup() method
-       private JPopupMenu getActionsPopup(int pos)
-       {
-               Cons actions = getActions(pos);
-               if(actions == null)
-                       return null;
-
-               JPopupMenu popup = new JPopupMenu();
-               while(actions != null)
-               {
-                       Cons action = (Cons)actions.car;
-                       JMenuItem item = new JMenuItem((String)action.cdr);
-                       item.setActionCommand((String)action.car);
-                       item.addActionListener(new EvalAction());
-                       popup.add(item);
-                       actions = actions.next();
-               }
-
-               return popup;
-       } //}}}
-
-       //{{{ showPopupMenu() method
-       private void showPopupMenu(int pos)
-       {
-               JPopupMenu actions = getActionsPopup(pos);
-               if(actions == null)
-                       return;
-
-               try
-               {
-                       StyledDocument doc = (StyledDocument)getDocument();
-                       Element e = doc.getCharacterElement(pos);
-                       Point pt = modelToView(e.getStartOffset())
-                               .getLocation();
-                       FontMetrics fm = getFontMetrics(getFont());
-
-                       actions.show(this,pt.x,pt.y + fm.getHeight());
-               }
-               catch(Exception e)
-               {
-                       e.printStackTrace();
-               }
-       } //}}}
-
-       //{{{ getInput() method
-       public String getInput()
-       {
-               try
-               {
-                       Document doc = getDocument();
-                       String line = doc.getText(cmdStart,doc.getLength() - cmdStart);
-                       if(line.endsWith("\n"))
-                               return line.substring(0,line.length() - 1);
-                       else
-                               return line;
-               }
-               catch(BadLocationException e)
-               {
-                       throw new RuntimeException(e);
-               }
-       } //}}}
-
-       //{{{ setInput() method
-       public void setInput(String line)
-       {
-               System.err.println("Set input: " + line + ", " + cmdStart);
-               try
-               {
-                       Document doc = getDocument();
-                       doc.remove(cmdStart,doc.getLength() - cmdStart);
-                       doc.insertString(cmdStart,line,null);
-               }
-               catch(BadLocationException e)
-               {
-                       throw new RuntimeException(e);
-               }
-       } //}}}
-
-       /**
-        * Subclasses can override this to provide funky history behavior,
-        * for JTextPanes and such.
-        */
-       public int getInputStart()
-       {
-               return cmdStart;
-       }
-
-       //{{{ MouseHandler class
-       class MouseHandler extends MouseInputAdapter
-       {
-               public void mousePressed(MouseEvent e)
-               {
-                       Point pt = new Point(e.getX(), e.getY());
-                       int pos = viewToModel(pt);
-                       if(pos >= 0)
-                               showPopupMenu(pos);
-               }
-
-               public void mouseMoved(MouseEvent e)
-               {
-                       Point pt = new Point(e.getX(), e.getY());
-                       int pos = viewToModel(pt);
-                       if(pos >= 0)
-                       {
-                               Cursor cursor;
-                               if(getActions(pos) != null)
-                                       cursor = MoveCursor;
-                               else
-                                       cursor = DefaultCursor;
-
-                               if(getCursor() != cursor)
-                                       setCursor(cursor);
-                       }
-               }
-       } //}}}
-
-       //{{{ EvalAction class
-       class EvalAction extends AbstractAction
-       {
-               public void actionPerformed(ActionEvent evt)
-               {
-                       eval(evt.getActionCommand());
-               }
-       } //}}}
-
-       //{{{ EnterAction class
-       class EnterAction extends AbstractAction
-       {
-               public void actionPerformed(ActionEvent evt)
-               {
-                       setCaretPosition(getDocument().getLength());
-                       replaceSelection("\n");
-
-                       history.addCurrentToHistory();
-                       history.setIndex(-1);
-                       fireEvalEvent(getInput());
-               }
-       } //}}}
-
-       //{{{ BackspaceAction class
-       class BackspaceAction extends AbstractAction
-       {
-               public void actionPerformed(ActionEvent evt)
-               {
-                       if(getSelectionStart() != getSelectionEnd())
-                       {
-                               replaceSelection("");
-                               return;
-                       }
-
-                       int caret = getCaretPosition();
-                       if(caret == cmdStart)
-                       {
-                               getToolkit().beep();
-                               return;
-                       }
-
-                       try
-                       {
-                               getDocument().remove(caret - 1,1);
-                       }
-                       catch(BadLocationException e)
-                       {
-                               e.printStackTrace();
-                       }
-               }
-       } //}}}
-
-       //{{{ HomeAction class
-       class HomeAction extends AbstractAction
-       {
-               public void actionPerformed(ActionEvent evt)
-               {
-                       setCaretPosition(cmdStart);
-               }
-       } //}}}
-
-       //{{{ HistoryUpAction class
-       class HistoryUpAction extends AbstractAction
-       {
-               public void actionPerformed(ActionEvent evt)
-               {
-                       history.historyPrevious();
-               }
-       } //}}}
-
-       //{{{ HistoryDownAction class
-       class HistoryDownAction extends AbstractAction
-       {
-               public void actionPerformed(ActionEvent evt)
-               {
-                       history.historyNext();
-               }
-       } //}}}
-
-       //{{{ DummyAction class
-       class DummyAction extends AbstractAction
-       {
-               public void actionPerformed(ActionEvent evt)
-               {
-               }
-       } //}}}
-
-       //{{{ DocumentHandler class
-       class DocumentHandler implements DocumentListener
-       {
-               public void insertUpdate(DocumentEvent e)
-               {
-                       int offset = e.getOffset();
-                       int length = e.getLength();
-
-                       if(offset < cmdStart)
-                               cmdStart += length;
-               }
-
-               public void removeUpdate(DocumentEvent e)
-               {
-                       int offset = e.getOffset();
-                       int length = e.getLength();
-
-                       if(offset < cmdStart)
-                       {
-                               if(offset + length > cmdStart)
-                                       cmdStart = offset;
-                               else
-                                       cmdStart -= length;
-                       }
-               }
-
-               public void changedUpdate(DocumentEvent e) {}
-       } //}}}
-}
diff --git a/factor/jedit/FactorListenerPanel.java b/factor/jedit/FactorListenerPanel.java
deleted file mode 100644 (file)
index 291b158..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/* :folding=explicit: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.
- */
-
-package factor.jedit;
-
-import factor.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import javax.swing.*;
-import javax.swing.text.*;
-import javax.swing.text.html.*;
-
-public class FactorListenerPanel extends JPanel
-{
-       private FactorInterpreter interp;
-       private FactorListener listener;
-
-       //{{{ newInterpreter() method
-       public static FactorInterpreter newInterpreter(String[] args)
-       {
-               try
-               {
-                       FactorInterpreter interp = new FactorInterpreter();
-                       interp.interactive = false;
-                       interp.init(args);
-                       return interp;
-               }
-               catch(Exception e)
-               {
-                       System.err.println("Failed to initialize interpreter:");
-                       e.printStackTrace();
-                       return null;
-               }
-       } //}}}
-
-       //{{{ FactorListenerPanel constructor
-       public FactorListenerPanel(FactorInterpreter interp)
-       {
-               setLayout(new BorderLayout());
-
-               this.interp = interp;
-
-               add(BorderLayout.CENTER,new JScrollPane(
-                       listener = newListener()));
-       } //}}}
-
-       //{{{ getListener() method
-       public FactorListener getListener()
-       {
-               return listener;
-       } //}}}
-
-       //{{{ newListener() method
-       private FactorListener newListener()
-       {
-               final FactorListener listener = new FactorListener();
-               listener.addEvalListener(new EvalHandler());
-
-               eval(new Cons(listener,
-                       new Cons(interp.searchVocabulary(
-                               "listener","new-listener-hook"),
-                       null)));
-
-               return listener;
-       } //}}}
-
-       //{{{ requestDefaultFocus() method
-       public boolean requestDefaultFocus()
-       {
-               listener.requestFocus();
-               return true;
-       } //}}}
-
-       //{{{ getInterpreter() method
-       public FactorInterpreter getInterpreter()
-       {
-               return interp;
-       } //}}}
-
-       //{{{ eval() method
-       private void eval(Cons cmd)
-       {
-               try
-               {
-                       interp.call(cmd);
-                       interp.run();
-               }
-               catch(Exception e)
-               {
-                       System.err.println("Failed to eval " + cmd + ":");
-                       e.printStackTrace();
-               }
-       } //}}}
-
-       //{{{ EvalHandler class
-       class EvalHandler implements EvalListener
-       {
-               public void eval(Cons cmd)
-               {
-                       FactorListenerPanel.this.eval(cmd);
-               }
-       } //}}}
-}
index d6a173a089219e3b37b0bb47838e935267b7192d..89345e9e111159fb2792ec0d8e474c2bd3b6c338 100644 (file)
@@ -35,12 +35,11 @@ import java.util.*;
 import org.gjt.sp.jedit.gui.*;
 import org.gjt.sp.jedit.textarea.*;
 import org.gjt.sp.jedit.*;
+import console.*;
 import sidekick.*;
 
 public class FactorPlugin extends EditPlugin
 {
-       private static final String DOCKABLE_NAME = "factor";
-
        private static FactorInterpreter interp;
 
        //{{{ start() method
@@ -50,6 +49,24 @@ public class FactorPlugin extends EditPlugin
                        "import factor.*;\nimport factor.jedit.*;\n");
        } //}}}
        
+       //{{{ newInterpreter() method
+       private static FactorInterpreter newInterpreter(String[] args)
+       {
+               try
+               {
+                       FactorInterpreter interp = new FactorInterpreter();
+                       interp.interactive = false;
+                       interp.init(args);
+                       return interp;
+               }
+               catch(Exception e)
+               {
+                       System.err.println("Failed to initialize interpreter:");
+                       e.printStackTrace();
+                       return null;
+               }
+       } //}}}
+
        //{{{ getInterpreter() method
        /**
         * This can be called from the SideKick thread and must be thread safe.
@@ -58,8 +75,7 @@ public class FactorPlugin extends EditPlugin
        {
                if(interp == null)
                {
-                       interp = FactorListenerPanel.newInterpreter(
-                               new String[] { "-jedit" });
+                       interp = newInterpreter(new String[] { "-jedit" });
                }
 
                return interp;
@@ -76,10 +92,9 @@ public class FactorPlugin extends EditPlugin
        public static void eval(View view, String cmd)
        {
                DockableWindowManager wm = view.getDockableWindowManager();
-               wm.addDockableWindow(DOCKABLE_NAME);
-               FactorListenerPanel panel = (FactorListenerPanel)
-                       wm.getDockableWindow(DOCKABLE_NAME);
-               panel.getListener().eval(cmd);
+               wm.addDockableWindow("console");
+               Console console = (Console)wm.getDockableWindow("console");
+               console.run(Shell.getShell("Factor"),console,cmd);
        } //}}}
 
        //{{{ factorWord() method
index c80a99d69855936d775400456c692cf28bb0d0dd..a9143db2aa4f1ba2a02bb30e61c18d3d0dd3993c 100644 (file)
@@ -7,13 +7,12 @@ plugin.factor.jedit.FactorPlugin.version=0.68
 plugin.factor.jedit.FactorPlugin.author=Slava Pestov
 plugin.factor.jedit.FactorPlugin.docs=/doc/jedit/index.html
 
-plugin.factor.jedit.FactorPlugin.depend.0=jedit 04.03.01.00
+plugin.factor.jedit.FactorPlugin.depend.0=jedit 04.02.99.00
 plugin.factor.jedit.FactorPlugin.depend.1=plugin errorlist.ErrorListPlugin 1.3.2
 plugin.factor.jedit.FactorPlugin.depend.2=plugin sidekick.SideKickPlugin 0.3.1
+plugin.factor.jedit.FactorPlugin.depend.3=plugin console.ConsolePlugin 4.0.1
 
-plugin.factor.jedit.FactorPlugin.menu=factor \
-       - \
-       factor-run-file \
+plugin.factor.jedit.FactorPlugin.menu=factor-run-file \
        factor-eval-selection \
        - \
        factor-apropos \
@@ -26,7 +25,6 @@ plugin.factor.jedit.FactorPlugin.menu=factor \
        - \
        factor-extract-word
 
-factor.label=Factor Listener
 factor-run-file.label=Run current file
 factor-eval-selection.label=Evaluate selection
 factor-apropos.label=Apropos at caret
@@ -37,8 +35,6 @@ factor-edit-dialog.label=Edit word...
 factor-usages.label=Word usages at caret
 factor-extract-word.label=Extract word...
 
-factor.title=Factor
-
 sidekick.parser.factor.label=Factor
 mode.factor.sidekick.parser=factor
 
diff --git a/factor/jedit/FactorShell.java b/factor/jedit/FactorShell.java
new file mode 100644 (file)
index 0000000..32c5064
--- /dev/null
@@ -0,0 +1,158 @@
+/* :folding=explicit: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.
+ */
+
+package factor.jedit;
+
+import console.*;
+import factor.*;
+import javax.swing.text.AttributeSet;
+import java.util.WeakHashMap;
+import org.gjt.sp.jedit.ServiceManager;
+
+public class FactorShell extends Shell
+{
+       //{{{ readLine() method
+       /**
+        * Helper static method to simplify Factor code.
+        */
+       public static void readLine(Cons continuation, Console console)
+       {
+               FactorShell shell = (FactorShell)ServiceManager.getService(
+                       "console.Shell","Factor");
+               ConsoleState state = shell.getConsoleState(console);
+               state.readLineContinuation = continuation;
+       } //}}}
+       
+       //{{{ FactorShell constructor
+       public FactorShell()
+       {
+               super("Factor");
+               interp = FactorPlugin.getInterpreter();
+               consoles = new WeakHashMap();
+       } //}}}
+
+       //{{{ printInfoMessage() method
+       /**
+        * Prints a 'info' message to the specified console.
+        * @param output The output
+        */
+       public void printInfoMessage(Output output)
+       {
+       } //}}}
+
+       //{{{ printPrompt() method
+       /**
+        * Prints a prompt to the specified console.
+        * @param console The console instance
+        * @param output The output
+        * @since Console 3.6
+        */
+       public void printPrompt(Console console, Output output)
+       {
+               getConsoleState(console);
+       } //}}}
+
+       //{{{ execute() method
+       /**
+        * Executes a command.
+        * @param console The console
+        * @param input Standard input
+        * @param output Standard output
+        * @param error Standard error
+        * @param command The command
+        * @since Console 3.5
+        */
+       public void execute(Console console, String input,
+               Output output, Output error, String command)
+       {
+               ConsoleState state = getConsoleState(console);
+               Cons quot = new Cons(command,state.readLineContinuation);
+               eval(quot);
+               output.commandDone();
+               error.commandDone();
+       } //}}}
+       
+       //{{{ stop() method
+       /**
+        * Stops the currently executing command, if any.
+        */
+       public void stop(Console console)
+       {
+       } //}}}
+       
+       //{{{ Private members
+       private FactorInterpreter interp;
+       private WeakHashMap consoles;
+       
+       //{{{ getConsoleState() method
+       private ConsoleState getConsoleState(Console console)
+       {
+               ConsoleState state = (ConsoleState)consoles.get(console);
+               if(state == null)
+               {
+                       state = new ConsoleState(console);
+                       consoles.put(console,state);
+
+                       eval(new Cons(console,
+                               new Cons(interp.searchVocabulary(
+                                       "console","console-hook"),
+                                       null)));
+               }
+               return state;
+       } //}}}
+
+       //{{{ eval() method
+       private void eval(Cons cmd)
+       {
+               try
+               {
+                       interp.call(cmd);
+                       interp.run();
+               }
+               catch(Exception e)
+               {
+                       System.err.println("Failed to eval " + cmd + ":");
+                       e.printStackTrace();
+               }
+       } //}}}
+
+       //}}}
+
+       //{{{ ConsoleState class
+       class ConsoleState
+       {
+               private Console console;
+               Cons readLineContinuation;
+               
+               ConsoleState(Console console)
+               {
+                       this.console = console;
+               }
+       } //}}}
+}
diff --git a/factor/jedit/ListenerHistoryText.java b/factor/jedit/ListenerHistoryText.java
deleted file mode 100644 (file)
index edccdcc..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/* :folding=explicit: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.
- */
-
-package factor.jedit;
-
-import javax.swing.text.JTextComponent;
-import org.gjt.sp.jedit.gui.HistoryText;
-
-public class ListenerHistoryText extends HistoryText
-{
-       private FactorListener listener;
-
-       public ListenerHistoryText(FactorListener listener, String model)
-       {
-               super(listener,model);
-               this.listener = listener;
-       }
-
-       public int getInputStart()
-       {
-               return listener.getInputStart();
-       }
-       
-       public String getText()
-       {
-               return listener.getInput();
-       }
-       
-       public void setText(String text)
-       {
-               setIndex(-1);
-               listener.setInput(text);
-       }
-}
index c2ae15c10e8df2222c23cfad55999826283c3e53..8944d9115a8958949084b0f8fbdc06d557e3ab01 100644 (file)
@@ -92,8 +92,16 @@ public class WordPreview implements ActionListener, CaretListener
                        textArea.getBuffer().markTokens(line,h);
                        Token tokens = h.getTokens();
 
-                       Token token = TextUtilities.getTokenAtOffset(tokens,
-                               caret - textArea.getLineStartOffset(line));
+                       int offset = caret - textArea.getLineStartOffset(line);
+
+                       int len = textArea.getLineLength(line);
+                       if(len == 0)
+                               return;
+
+                       if(offset == len)
+                               offset--;
+
+                       Token token = TextUtilities.getTokenAtOffset(tokens,offset);
 
                        String name = token.rules.getName();
 
diff --git a/library/jedit/console.factor b/library/jedit/console.factor
new file mode 100644 (file)
index 0000000..4cd58fa
--- /dev/null
@@ -0,0 +1,188 @@
+! :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: console
+USE: combinators
+USE: continuations
+USE: init
+USE: interpreter
+USE: kernel
+USE: lists
+USE: namespaces
+USE: stack
+USE: stdio
+USE: styles
+USE: streams
+USE: strings
+USE: unparser
+
+: <attribute-set> ( -- attribute-set )
+    [ ] "javax.swing.text.SimpleAttributeSet" jnew ;
+
+: attribute+ ( attribute-set value key -- )
+    transp
+    [ "java.lang.Object" "java.lang.Object" ]
+    "javax.swing.text.SimpleAttributeSet"
+    "addAttribute" jinvoke ;
+
+: style-constant ( name -- key )
+    #! javax.swing.text.StyleConstants contains static variables
+    #! which key in an AttributeSet.
+    "javax.swing.text.StyleConstants" swap jvar-static-get
+    ; inline
+
+: set-icon-style ( attribute-set icon -- )
+    [
+        "javax.swing.text.MutableAttributeSet"
+        "javax.swing.Icon"
+    ] "javax.swing.text.StyleConstants"
+    "setIcon" jinvoke-static ;
+
+: <icon> ( resource -- icon )
+    resource
+    [ "java.net.URL" ]
+    "javax.swing.ImageIcon" jnew ;
+
+: swing-attribute+ ( attribute-set value key -- )
+    style-constant attribute+ ;
+
+: >color ( triplet -- hex )
+    uncons uncons uncons drop
+    [ "int" "int" "int" ]
+    "java.awt.Color"
+    jnew ;
+
+: actions-key ( -- attr )
+    "console.ConsolePane" "Actions" jvar-static-get ; inline
+
+: <eval-action> ( label cmd -- action )
+    "console" get [
+        "java.lang.String"
+        "java.lang.String"
+        "console.Console"
+    ] "console.Console$EvalAction" jnew ;
+
+: <action-menu-item> ( path pair -- action )
+    uncons swapd " " swap cat3 <eval-action> ;
+
+: >action-array ( list -- array )
+    [ "javax.swing.Action" ] coerce ;
+
+: <actions-menu> ( path actions -- array )
+    [ dupd <action-menu-item> ] map nip >action-array ;
+
+: object-actions ( -- list )
+    [
+        [ "Describe" | "describe-path"  ]
+        [ "Push"     | "lookup"         ]
+        [ "Execute"  | "lookup execute" ]
+        [ "jEdit"    | "lookup jedit"   ]
+        [ "Usages"   | "lookup usages." ]
+    ] ;
+
+: <object-actions-menu> ( path -- alist )
+    unparse object-actions <actions-menu> ;
+
+: file-actions ( -- list )
+    [
+        [ "Push"             | ""           ]
+        [ "Run file"         | "run-file"   ]
+        [ "List directory"   | "directory." ]
+        [ "Change directory" | "cd"         ]
+    ] ;
+
+: <file-actions-menu> ( path -- alist )
+    unparse file-actions <actions-menu> ;
+
+: underline-attribute ( attribute-set -- )
+    t "Underline" swing-attribute+ ;
+
+: object-link-attribute ( attribute-set target -- )
+    over underline-attribute
+    <object-actions-menu> actions-key attribute+ ;
+
+: file-link-attribute ( attribute-set target -- )
+    over underline-attribute
+    <file-actions-menu> actions-key attribute+ ;
+
+: icon-attribute ( string style value -- )
+    dupd <icon> set-icon-style
+    >r drop " " r> ;
+
+: style>attribute-set ( string style -- string attribute-set )
+    #! We need the string, since outputting an icon changes the
+    #! string to " ".
+    <attribute-set> swap [
+        [ "object-link" dupd object-link-attribute ]
+        [ "file-link"   dupd file-link-attribute ]
+        [ "bold"        drop dup t "Bold" swing-attribute+ ]
+        [ "italics"     drop dup t "Italic" swing-attribute+ ]
+        [ "underline"   drop dup t "Underline" swing-attribute+ ]
+        [ "fg"          dupd >color "Foreground" swing-attribute+ ]
+        [ "bg"          dupd >color "Background" swing-attribute+ ]
+        [ "font"        dupd "FontFamily" swing-attribute+ ]
+        [ "size"        dupd "FontSize" swing-attribute+ ]
+        [ "icon"        icon-attribute ]
+    ] assoc-apply ;
+
+: console-readln* ( continuation -- )
+    "console" get [ "factor.Cons" "console.Console" ]
+       "factor.jedit.FactorShell" "readLine" jinvoke-static ;
+
+: console-readln ( -- line )
+    [ console-readln* toplevel ] callcc1 ;
+
+: console-write-attr ( string style -- )
+    style>attribute-set swap "console" get
+    [ "javax.swing.text.AttributeSet" "java.lang.String" ]
+    "console.Output" "writeAttrs" jinvoke ;
+
+: <console-stream> ( console -- stream )
+    #! Creates a stream for reading/writing to the given
+    #! console instance.
+    <stream> [
+        "console" set
+        ( -- string )
+        [ console-readln ] "freadln" set
+        ( string -- )
+        [ default-style console-write-attr ] "fwrite" set
+        ( string style -- )
+        [ console-write-attr ] "fwrite-attr" set
+        ( -- )
+        [ ] "fflush" set
+        ( -- )
+        [ ] "fclose" set
+        ( string -- )
+        [ this fwrite "\n" this fwrite ] "fprint" set
+    ] extend ;
+
+: console-hook ( console -- )
+    [
+        dup "console" set
+        <console-stream> "stdio" set
+        init-interpreter
+    ] with-scope ;
diff --git a/library/jedit/listener.factor b/library/jedit/listener.factor
deleted file mode 100644 (file)
index ec8e0ef..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-! :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: listener
-USE: combinators
-USE: continuations
-USE: init
-USE: interpreter
-USE: kernel
-USE: lists
-USE: namespaces
-USE: stack
-USE: stdio
-USE: styles
-USE: streams
-USE: strings
-USE: unparser
-
-: <attribute-set> ( -- attribute-set )
-    [ ] "javax.swing.text.SimpleAttributeSet" jnew ;
-
-: attribute+ ( attribute-set value key -- )
-    transp
-    [ "java.lang.Object" "java.lang.Object" ]
-    "javax.swing.text.SimpleAttributeSet"
-    "addAttribute" jinvoke ;
-
-: style-constant ( name -- key )
-    #! javax.swing.text.StyleConstants contains static variables
-    #! which key in an AttributeSet.
-    "javax.swing.text.StyleConstants" swap jvar-static-get
-    ; inline
-
-: set-icon-style ( attribute-set icon -- )
-    [
-        "javax.swing.text.MutableAttributeSet"
-        "javax.swing.Icon"
-    ] "javax.swing.text.StyleConstants"
-    "setIcon" jinvoke-static ;
-
-: <icon> ( resource -- icon )
-    resource
-    [ "java.net.URL" ]
-    "javax.swing.ImageIcon" jnew ;
-
-: swing-attribute+ ( attribute-set value key -- )
-    style-constant attribute+ ;
-
-: >color ( triplet -- hex )
-    uncons uncons uncons drop
-    [ "int" "int" "int" ]
-    "java.awt.Color"
-    jnew ;
-
-: actions-key ( -- attr )
-    "factor.jedit.FactorListener" "Actions" jvar-static-get
-    ; inline
-
-: <action-menu-item> ( path pair -- pair )
-    uncons >r " " swap cat3 r> cons ;
-
-: <actions-menu> ( path actions -- alist )
-    [ dupd <action-menu-item> ] map nip ;
-
-: object-actions ( -- list )
-    [
-        [ "describe-path"  | "Describe" ]
-        [ "lookup"         | "Push" ]
-        [ "lookup execute" | "Execute" ]
-        [ "lookup jedit"   | "jEdit" ]
-        [ "lookup usages." | "Usages" ]
-    ] ;
-
-: <object-actions-menu> ( path -- alist )
-    unparse object-actions <actions-menu> ;
-
-: file-actions ( -- list )
-    [
-        [ ""           | "Push" ]
-        [ "run-file"   | "Run file" ]
-        [ "directory." | "List directory" ]
-        [ "cd"         | "Change directory" ]
-    ] ;
-
-: <file-actions-menu> ( path -- alist )
-    unparse file-actions <actions-menu> ;
-
-: underline-attribute ( attribute-set -- )
-    t "Underline" swing-attribute+ ;
-
-: object-link-attribute ( attribute-set target -- )
-    over underline-attribute
-    <object-actions-menu> actions-key attribute+ ;
-
-: file-link-attribute ( attribute-set target -- )
-    over underline-attribute
-    <file-actions-menu> actions-key attribute+ ;
-
-: icon-attribute ( string style value -- )
-    dupd <icon> set-icon-style
-    >r drop " " r> ;
-
-: style>attribute-set ( string style -- string attribute-set )
-    #! We need the string, since outputting an icon changes the
-    #! string to " ".
-    <attribute-set> swap [
-        [ "object-link" dupd object-link-attribute ]
-        [ "file-link"   dupd file-link-attribute ]
-        [ "bold"        drop dup t "Bold" swing-attribute+ ]
-        [ "italics"     drop dup t "Italic" swing-attribute+ ]
-        [ "underline"   drop dup t "Underline" swing-attribute+ ]
-        [ "fg"          dupd >color "Foreground" swing-attribute+ ]
-        [ "bg"          dupd >color "Background" swing-attribute+ ]
-        [ "font"        dupd "FontFamily" swing-attribute+ ]
-        [ "size"        dupd "FontSize" swing-attribute+ ]
-        [ "icon"        icon-attribute ]
-    ] assoc-apply ;
-
-: set-character-attrs ( attrs -- )
-    t "listener" get
-    [ "javax.swing.text.AttributeSet" "boolean" ]
-    "javax.swing.JTextPane"
-    "setCharacterAttributes"
-    jinvoke ;
-
-: set-paragraph-attrs ( attrs -- )
-    t "listener" get
-    [ "javax.swing.text.AttributeSet" "boolean" ]
-    "javax.swing.JTextPane"
-    "setCharacterAttributes"
-    jinvoke ;
-
-: reset-attrs ( -- )
-    f default-style style>attribute-set set-character-attrs
-    drop ;
-
-: listener-readln* ( continuation -- )
-    "listener" get
-       [ "factor.Cons" ]
-       "factor.jedit.FactorListener"
-       "readLine" jinvoke ;
-
-: listener-readln ( -- line )
-    reset-attrs [ listener-readln* toplevel ] callcc1 ;
-
-: listener-write-attr ( string style -- )
-    style>attribute-set "listener" get
-    [ "java.lang.String" "javax.swing.text.AttributeSet" ]
-    "factor.jedit.FactorListener"
-    "insertWithAttrs"
-    jinvoke ;
-
-!: listener-edit ( string -- )
-!    "listener" get
-!    [ "java.lang.String" ]
-!    "factor.jedit.FactorListener"
-!    "editLine" jinvoke ;
-
-: <listener-stream> ( listener -- stream )
-    #! Creates a stream for reading/writing to the given
-    #! listener instance.
-    <stream> [
-        "listener" set
-        ( -- string )
-        [ listener-readln ] "freadln" set
-        ( string -- )
-        [ default-style listener-write-attr ] "fwrite" set
-        ( string style -- )
-        [ listener-write-attr ] "fwrite-attr" set
-        ( string -- )
-        ![ listener-edit ] "fedit" set
-        ( -- )
-        [ ] "fflush" set
-        ( -- )
-        [ ] "fclose" set
-        ( string -- )
-        [ this fwrite "\n" this fwrite ] "fprint" set
-    ] extend ;
-
-: new-listener-hook ( listener -- )
-    #! Called when user opens a new listener
-    [
-        dup "listener" set
-        <listener-stream> "stdio" set
-        init-interpreter
-    ] with-scope ;
index 18246ce06895012fcb34dced0723c8ac56727240..2a8833da226d5de914d98688f0d117d9a218d7fc 100644 (file)
@@ -130,4 +130,4 @@ USE: parser
 "/library/jedit/jedit-local.factor"  run-resource ! jedit
 "/library/jedit/jedit-remote.factor" run-resource ! jedit
 "/library/jedit/jedit.factor"        run-resource ! jedit
-"/library/jedit/listener.factor"     run-resource ! listener
+"/library/jedit/console.factor"      run-resource ! console
index 637f6328d9573c18a5bc41ee75f9115bb6089773..9d8ce95af00984be9940e275af99531f4b626e42 100644 (file)
@@ -73,6 +73,7 @@ IN: kernel
 : toplevel ( -- )
     interpreter
     [ ] "factor.FactorInterpreter" "topLevel" jinvoke ;
+    interpret-only
 
 : exit* ( code -- )
     [ "int" ] "java.lang.System" "exit" jinvoke-static ;
index a5b455a9813f42f4edfddb90bb6b3afc457c367e..348761d599c390074c927bd3ffd940608cc5b476 100644 (file)
@@ -6,4 +6,7 @@
        <SERVICE CLASS="sidekick.SideKickParser" NAME="factor">
                new factor.jedit.FactorSideKickParser();
        </SERVICE>
+       <SERVICE CLASS="console.Shell" NAME="Factor">
+               new factor.jedit.FactorShell();
+       </SERVICE>
 </SERVICES>