[slime-cvs] CVS slime

CVS User trittweiler trittweiler at common-lisp.net
Mon Oct 19 10:01:51 UTC 2009


Update of /project/slime/cvsroot/slime
In directory cl-net:/tmp/cvs-serv4401

Modified Files:
	swank.lisp ChangeLog 
Log Message:
	* swank.lisp (without-printing-errors): New macro.
	(to-string): Use it.
	(to-line): Use it, too. This fixes printing error occuring during
	inspecting to prevent the inspector from displaying something
	useful.

	Reported by xristos at suspicious.org.


--- /project/slime/cvsroot/slime/swank.lisp	2009/10/09 23:05:12	1.663
+++ /project/slime/cvsroot/slime/swank.lisp	2009/10/19 10:01:50	1.664
@@ -1952,18 +1952,42 @@
         (let ((*readtable* *buffer-readtable*))
           (call-with-syntax-hooks fun)))))
 
+(defmacro without-printing-errors ((&key object stream
+                                        (msg "<<error printing object>>"))
+                                  &body body)
+  "Catches errors during evaluation of BODY and prints MSG instead."
+  `(handler-case (progn , at body) 
+     (serious-condition ()
+       ,(cond ((and stream object)
+               (let ((gstream (gensym "STREAM+")))
+                 `(let ((,gstream ,stream))
+                    (print-unreadable-object (,object ,gstream :type t :identity t)
+                      (write-string ,msg ,gstream)))))
+              (stream
+               `(write-string ,msg ,stream))
+              (object
+               `(with-output-to-string (s)
+                  (print-unreadable-object (,object s :type t :identity t)
+                    (write-string ,msg  s))))
+              (t msg)))))
+
 (defun to-string (object)
   "Write OBJECT in the *BUFFER-PACKAGE*.
 The result may not be readable. Handles problems with PRINT-OBJECT methods
 gracefully."
   (with-buffer-syntax ()
     (let ((*print-readably* nil))
-      (handler-case
-          (prin1-to-string object)
-        (error ()
-          (with-output-to-string (s)
-            (print-unreadable-object (object s :type t :identity t)
-              (princ "<<error printing object>>" s))))))))
+      (without-printing-errors (:object object :stream nil)
+        (prin1-to-string object)))))
+
+(defun to-line  (object &optional (width 75))
+  "Print OBJECT to a single line. Return the string."
+  (without-printing-errors (:object object :stream nil)
+    (call/truncated-output-to-string
+     width
+     (lambda (*standard-output*)
+       (write object :right-margin width :lines 1))
+     "..")))
 
 (defun from-string (string)
   "Read string in the *BUFFER-PACKAGE*"
@@ -2300,6 +2324,7 @@
                    (replace buffer ellipsis :start1 fill-pointer)
                    (return-from buffer-full buffer)))))
         (let ((stream (make-output-stream #'write-output)))
+          
           (funcall function stream)
           (finish-output stream)
           (subseq buffer 0 fill-pointer))))))
@@ -3374,13 +3399,7 @@
         (format nil "#~D=~A" pos string)
         string)))
 
-;; Print OBJECT to a single line. Return the string.
-(defun to-line  (object &optional (width 75))
-  (call/truncated-output-to-string
-   width
-   (lambda (*standard-output*)
-     (write object :right-margin width :lines 1))
-   ".."))
+
 
 (defun content-range (list start end)
   (typecase list
--- /project/slime/cvsroot/slime/ChangeLog	2009/10/15 16:40:37	1.1874
+++ /project/slime/cvsroot/slime/ChangeLog	2009/10/19 10:01:50	1.1875
@@ -1,3 +1,13 @@
+2009-10-19  Tobias C. Rittweiler <tcr at freebits.de>
+
+	* swank.lisp (without-printing-errors): New macro.
+	(to-string): Use it.
+	(to-line): Use it, too. This fixes printing error occuring during
+	inspecting to prevent the inspector from displaying something
+	useful.
+
+	Reported by xristos at suspicious.org.
+
 2009-10-15  Helmut Eller  <heller at common-lisp.net>
 
 	* slime.el (slime-current-package): Move REPL stuff to contrib.





More information about the slime-cvs mailing list