Add lisp-implementation-version
[jscl.git] / src / toplevel.lisp
index 42864e6..9d6594b 100644 (file)
     (#j:jqconsole:Write prompt "jqconsole-prompt"))
   (flet ((process-input (input)
            (let* ((form (read-from-string input))
-                  (result (multiple-value-list (eval-interactive form))))
-             (dolist (x result)
-               (#j:jqconsole:Write (format nil "~S~%" x) "jqconsole-return"))
+                  (successp nil)
+                  result)
+             ;; Capture errors. We evaluate the form and set successp
+             ;; to T. However, if a non-local exist happens, we cancel
+             ;; it, so it is not propagated more.
+             (block nil
+               (unwind-protect
+                    (progn
+                      (setq result (multiple-value-list (eval-interactive form)))
+                      (setq successp t))
+                 (return)))
+
+             (if successp
+                 (dolist (x result)
+                   (#j:jqconsole:Write (format nil "~S~%" x) "jqconsole-return"))
+                 (#j:jqconsole:Write (format nil "Error occurred~%") "jqconsole-error"))
+             
              (save-history)) 
            (toplevel)))
     (#j:jqconsole:Prompt t #'process-input)))
 
 
-;;; KLUDGE: I tried
-;;; 
-;;;   (#j:document.addEventListener "load" #'topevel nil)
-;;; 
-;;; but it is not working. So I am using this temporarily to wait
-;;; until the DOM is ready before starting the REPL.
+(defun init (&rest args)
+  (#j:jqconsole:RegisterMatching "(" ")" "parents")
+  (load-history)
+  (toplevel))
 
-(#j:setTimeout (lambda ()
-                 (#j:jqconsole:RegisterMatching "(" ")" "parents")
-                 (load-history)
-                 (toplevel))
-               0)
+(#j:window:addEventListener "load" #'init)