branch: elpa/sly
commit 5bdc3c9a6c247f6927b17da261d638bb1d562b8e
Author: João Távora <[email protected]>
Commit: João Távora <[email protected]>

    Fix #382: allow REPLs to keep different working directories
    
    * contrib/sly-mrepl.el (sly-mrepl-set-directory): Use
    sly-mrepl--eval-for-repl.
    (sly-cd): Advise with warning.
    
    * contrib/slynk-mrepl.lisp (mrepl-eval-1): Also allow
    *DEFAULT-PATHNAME-DEFAULTS* to be clobbered.
    (mrepl): Keep a binding for *DEFAULT-PATHNAME-DEFAULTS*.
---
 contrib/sly-mrepl.el     | 23 ++++++++++++++++++++---
 contrib/slynk-mrepl.lisp | 15 ++++++++++-----
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/contrib/sly-mrepl.el b/contrib/sly-mrepl.el
index 74af7d8..46eb891 100644
--- a/contrib/sly-mrepl.el
+++ b/contrib/sly-mrepl.el
@@ -1312,11 +1312,28 @@ When setting this variable outside of the Customize 
interface,
   (interactive)
   (let ((directory (read-directory-name "New directory: "
                                         default-directory nil t)))
-    (sly-mrepl--save-and-copy-for-repl
-     `(slynk:set-default-directory ,directory)
-     :before (format "Setting directory to %s" directory))
+    (sly-mrepl--eval-for-repl
+     `(slynk:set-default-directory ,directory))
+    (sly-mrepl--insert-note (format "Setting directory to %s" directory))
     (cd directory)))
 
+(advice-add
+ 'sly-cd :around
+ (lambda (oldfun r)
+   (interactive (lambda (oldspec)
+                  (if (or (not (eq major-mode 'sly-mrepl-mode))
+                          (sly-y-or-n-p
+                           (substitute-command-keys
+                            "This won't set the REPL's directory (use \
+ \\[sly-mrepl-set-directory] for that).  Proceed?")))
+                      (list (advice-eval-interactive-spec oldspec))
+                    (keyboard-quit))))
+   (apply oldfun r))
+ '((name . sly-mrepl--be-aware-of-sly-cd)))
+
+
+
+
 (defun sly-mrepl-shortcut ()
   (interactive)
   (let* ((string (sly-completing-read "Command: "
diff --git a/contrib/slynk-mrepl.lisp b/contrib/slynk-mrepl.lisp
index 32282f6..71d853c 100644
--- a/contrib/slynk-mrepl.lisp
+++ b/contrib/slynk-mrepl.lisp
@@ -31,6 +31,8 @@
   (:documentation "A listener implemented in terms of a channel.")
   (:default-initargs
    :initial-env `((cl:*package* . ,cl:*package*)
+                  (cl:*default-pathname-defaults*
+                   . ,cl:*default-pathname-defaults*)
                   (*) (**) (***)
                   (/) (//) (///)
                   (+) (++) (+++)
@@ -265,11 +267,13 @@ Set this to NIL to turn this feature off.")
     ;; *HISTORY* will get incorrectly clobbered to their pre-debugger
     ;; values, whereas we want to serialize this history.
     ;;
-    ;; However, as an exception, we /do/ want *PACKAGE* to be
-    ;; clobbered if the evaluation of STRING eventually completes.
+    ;; However, as an exception, we /do/ want /some/ special symbols
+    ;; to be clobbered if the evaluation of STRING eventually
+    ;; completes.  Currently, those are *PACKAGE* and
+    ;; *DEFAULT-PATHNAME-DEFAULTS*.
     ;;
     ;; Another way to see this is: the forms that the user inputs can
-    ;; only change the *PACKAGE* binding of the listener's
+    ;; only change binding of those special symbols in the listener's
     ;; environment. Everything else in there is handled automatically.
     ;;
     (with-listener-bindings repl
@@ -294,8 +298,9 @@ Set this to NIL to turn this feature off.")
                                           (setq +++ ++ ++ + + form))))))
                     finally
                     (return values))))
-        (setf (cdr (assoc '*package* (slot-value repl 'slynk::env)))
-              *package*)))))
+        (dolist (special-sym '(*package* *default-pathname-defaults*))
+          (setf (cdr (assoc special-sym (slot-value repl 'slynk::env)))
+                (symbol-value special-sym)))))))
 
 (defun set-external-mode (repl new-mode)
   (with-slots (mode remote-id) repl

Reply via email to