[Expand package change notification, and ensure that Emacs always receives strings to identify packages, never symbols, in these notifications.
Taylor R Campbell <campbell@mumble.net>**20070201193904] {
hunk ./packages.scm 45
-        (subset string-i/o (read-from-string))
+        string-i/o
hunk ./packages.scm 54
+        packages
+        packages-internal
hunk ./repl.scm 179
-                  (list id (hybrid-write-to-string
-                            (or name
-                                (package-uid package)))))))
+                  (list (hybrid-write-to-string id)
+                        (hybrid-write-to-string
+                         (or name
+                             (package-uid package)))))))
hunk ./session.scm 349
-              (receive (value new-env)
-                       (**swank-eval form env session)
-                (if (not (eq? new-env env))
-                    (set-interaction-environment! new-env))
-                (cell-set! result-cell `(:OK ,value)))))
+              (cell-set! result-cell
+                         `(:OK ,(with-interaction-environment* env
+                                    (lambda (env*)
+                                      (report-package-change session env*))
+                                  (lambda ()
+                                    (eval-in-rpc-env form session)))))))
hunk ./session.scm 364
-(define (**swank-eval form env session)
-  (with-interaction-environment env
-    (lambda ()
-      (let ((value (eval-in-rpc-env form session)))
-        ;** Don't beta-reduce!  INTERACTION-ENVIRONMENT must be called
-        ;** _after_ the form is evaluated.
-        (values value (interaction-environment))))))
+(define (with-interaction-environment* env if-change thunk)
+  ;** Notice the doubled bracket here.
+  ((with-interaction-environment env
+     (lambda ()
+       (receive results (thunk)
+         ;; Check for any changes THUNK effected upon the interaction
+         ;; environment.
+         (let ((env* (interaction-environment)))
+           (if (eq? env env*)
+               (lambda ()
+                 ;; If there were no changes, let it be reverted by
+                 ;; WITH-INTERACTION-ENVIRONMENT to the original.
+                 (apply values results))
+               (lambda ()
+                 ;; But if THUNK did change it, then reflect the change
+                 ;; past the WITH-INTERACTION-ENVIRONMENT.
+                 (set-interaction-environment! env*)
+                 (if-change env*)
+                 (apply values results)))))))))
+
+(define (report-package-change session package)
+  (send-outgoing-swank-message (current-swank-session)
+    (let ((name
+           (hybrid-write-to-string
+            (or (package-name package)
+                (package-uid package)))))
+      ;; No package nicknames in Scheme48, so just use the full name
+      ;; for the identifier and the prompt string.
+      `(:NEW-PACKAGE ,name ,name))))
}
