From 5beeac2d82af1171d6dadf12c7ad12da0b9e93a6 Mon Sep 17 00:00:00 2001
From: pw <pw>
Date: Mon, 30 Oct 2000 15:45:04 +0000
Subject: [PATCH] Fix edit-source-location to not signal an error when editing
 a file that has read-time evaluation (sharp-dot). The editor lisp doesn't
 have the slave lisp environment and doesn't know packages and functions that
 might be in the slave. This needs more testing and may prove to need some
 improvement.

---
 hemlock/debug.lisp | 42 ++++++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/hemlock/debug.lisp b/hemlock/debug.lisp
index 576f212af..079b944d6 100644
--- a/hemlock/debug.lisp
+++ b/hemlock/debug.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/hemlock/debug.lisp,v 1.7 1994/10/31 04:50:12 ram Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/hemlock/debug.lisp,v 1.8 2000/10/30 15:45:04 pw Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -208,15 +208,37 @@
 	;;
 	;; Read our form, get form-number translations, get the source-path,
 	;; and make it usable.
-	(let ((path (nreverse
-		     (butlast
-		      (cdr
-		       (svref (di:form-number-translations
-			       (with-input-from-region
-				   (s (region point (buffer-end-mark buffer)))
-				 (read s))
-			       tlf-offset)
-			      form-number))))))
+	;;
+	;; NOTE: Here READ is used in the editor lisp to look at a form
+	;; that the compiler has digested in the slave lisp. The editor
+	;; does not have the same environment at the slave so bad things
+	;; can happen if READ hits a #. reader macro (like unknown package
+	;; or undefined function errors) which can break the editor. This
+	;; code basically inhibits the read-time eval. This doesn't always
+	;; work right as the compiler may be seeing a different form structure
+	;; and the compiler's version of PATH may not match the editor's.
+	;; The main trouble seen in testing is that the 'form-number'
+	;; supplied by the compiler was one more than what the vector
+	;; returned by form-number-translations contained. For lack of a
+	;; better solution, I (pw) just limit the form-number to legal range.
+	;; This has worked ok on test code but may be off for some 
+	;; forms. At least the editor won't break.
+
+	(let* ((vector (di:form-number-translations
+			(with-input-from-region
+			    (s (region point (buffer-end-mark buffer)))
+			  (let ((*readtable* (copy-readtable)))
+			    (set-dispatch-macro-character
+			     #\# #\. (lambda(stream char arg)
+				       (declare (ignore char arg))
+				       (read stream)))
+			    (read s)))
+			tlf-offset))
+	       ;; Don't signal error on index overrun.It may be due
+	       ;; to read-time eval getting form editing blind to
+	       ;; editor
+	       (index (min form-number (1- (length vector))))
+	       (path (nreverse (butlast (cdr (svref vector index))))))
 	  ;;
 	  ;; Walk down to the form.  Change to buffer in case we get an error
 	  ;; while finding the form.
-- 
GitLab