+\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
<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">
+++ /dev/null
-<?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>
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;
} //}}}
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();
}
{
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)
+++ /dev/null
-/* :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);
-}
+++ /dev/null
-/* :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) {}
- } //}}}
-}
+++ /dev/null
-/* :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);
- }
- } //}}}
-}
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
"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.
{
if(interp == null)
{
- interp = FactorListenerPanel.newInterpreter(
- new String[] { "-jedit" });
+ interp = newInterpreter(new String[] { "-jedit" });
}
return interp;
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
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 \
- \
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
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
--- /dev/null
+/* :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;
+ }
+ } //}}}
+}
+++ /dev/null
-/* :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);
- }
-}
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();
--- /dev/null
+! :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 ;
+++ /dev/null
-! :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 ;
"/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
: toplevel ( -- )
interpreter
[ ] "factor.FactorInterpreter" "topLevel" jinvoke ;
+ interpret-only
: exit* ( code -- )
[ "int" ] "java.lang.System" "exit" jinvoke-static ;
<SERVICE CLASS="sidekick.SideKickParser" NAME="factor">
new factor.jedit.FactorSideKickParser();
</SERVICE>
+ <SERVICE CLASS="console.Shell" NAME="Factor">
+ new factor.jedit.FactorShell();
+ </SERVICE>
</SERVICES>