[snow-cvs] r17 - in trunk/src/java/snow: . swing

Alessio Stalla astalla at common-lisp.net
Wed Nov 18 20:36:13 UTC 2009


Author: astalla
Date: Wed Nov 18 15:36:12 2009
New Revision: 17

Log:
Fixed non-GUI main() with original ABCL repl.
Fixed ConsoleDocument: on Windows it was completely broken (it handled line
separators incorrectly, preventing any input to go to the interpreter); on
all platforms it didn't handle the caret correctly when editing in the middle
of text.


Modified:
   trunk/src/java/snow/Snow.java
   trunk/src/java/snow/swing/ConsoleDocument.java

Modified: trunk/src/java/snow/Snow.java
==============================================================================
--- trunk/src/java/snow/Snow.java	(original)
+++ trunk/src/java/snow/Snow.java	Wed Nov 18 15:36:12 2009
@@ -49,6 +49,8 @@
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
 
+import org.armedbear.lisp.Interpreter;
+
 public abstract class Snow {
 
     private static boolean init = false;
@@ -235,14 +237,27 @@
 	return (Invocable) lispEngine;
     }
     
-    public static void main(String[] args) {
+    public static void main(final String[] args) {
 	try {
-	    Snow.init();
 	    if(args.length == 0) { //Launch GUI REPL
-		evalResource(Snow.class, "/snow/start.lisp", true);
+		evalResource(Snow.class, "/snow/start.lisp", false);
 	    } else { //Launch regular ABCL
-		lispEngine.eval("(LET ((*PACKAGE* (FIND-PACKAGE :SNOW-USER))) (TOP-LEVEL::TOP-LEVEL-LOOP))");
-		//org.armedbear.lisp.Main.main(args);
+		//Copied from org.armedbear.lisp.Main.main()
+		Runnable r = new Runnable() {
+			public void run() {
+			    try {
+				Interpreter interpreter = Interpreter.createDefaultInstance(args);
+				Snow.init();
+				interpreter.eval("(in-package :snow-user)");
+				interpreter.run();
+			    } catch(Throwable t) {
+				System.err.println("Caught error, exiting: " + t);
+				t.printStackTrace();
+				System.exit(1);
+			    }
+			}
+		    };
+		new Thread(null, r, "interpreter", 4194304L).start();
 	    }
 	} catch (Exception e) {
 	    e.printStackTrace();

Modified: trunk/src/java/snow/swing/ConsoleDocument.java
==============================================================================
--- trunk/src/java/snow/swing/ConsoleDocument.java	(original)
+++ trunk/src/java/snow/swing/ConsoleDocument.java	Wed Nov 18 15:36:12 2009
@@ -167,7 +167,7 @@
 	 * @return
 	 */
 	protected boolean processInputP(StringBuffer sb, String str) {
-		if(str.indexOf(System.getProperty("line.separator", "\n")) == -1) {
+		if(str.indexOf("\n") == -1) {
 			return false;
 		}
 		int parenCount = 0;
@@ -222,17 +222,18 @@
 
 			@Override
 			public void changedUpdate(DocumentEvent e) {
-				txt.setCaretPosition(getLength());
 			}
 
 			@Override
 			public void insertUpdate(DocumentEvent e) {
-				txt.setCaretPosition(getLength());
+				int len = getLength();
+				if(len - e.getLength() == e.getOffset()) { //The insert was at the end of the document
+					txt.setCaretPosition(getLength());
+				}
 			}
 
 			@Override
 			public void removeUpdate(DocumentEvent e) {
-				txt.setCaretPosition(getLength());
 			}
 		});
 		txt.setCaretPosition(getLength());




More information about the snow-cvs mailing list