diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-06-06 01:04:24 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-06-09 08:27:45 -0500 |
commit | 5ebfaa6e61a1cac1473da768470f1ba298c3de3a (patch) | |
tree | 59e2030394941b757e32d8c508ef5eb65d6c4c86 | |
parent | 167a7953699a7797d797a14136393086eb932857 (diff) | |
download | dotfiles-5ebfaa6e61a1cac1473da768470f1ba298c3de3a.tar.gz |
implement updating Lisp image env vars & refactor
-rw-r--r-- | .emacs.d/init.el | 34 | ||||
-rwxr-xr-x | bin/emacsclient | 5 |
2 files changed, 23 insertions, 16 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el index c7340531..7ec37796 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -2198,22 +2198,28 @@ Single prefix argument to clear." (message "C-M-v will scroll %s" (window-buffer (get-mru-window))))) (global-set-key "\C-cV" #'spw/set-other-window-to-scroll) -;; unimplemented: update values in any Lisp image we may have -(defun spw/propagate-new-environment () - "After '~/src/dotfiles/bin/emacsclient --spw/update-environment' -has updated our env vars, propagate to subenvironments. Called -by that script, which see." - (dolist (var '("DISPLAY" "WAYLAND_DISPLAY" - "SSH_ASKPASS" "SSH_AUTH_SOCK" - "SSH_AGENT_PID" "SSH_CONNECTION" - "WINDOWID" "XAUTHORITY" "I3SOCK" "SWAYSOCK" - "XDG_SESSION_TYPE" "XDG_CURRENT_SESSION")) - (when-let ((new-value (getenv var))) +(defun spw/update-environment (&rest pairs) + "Update env vars like DISPLAY, SSH_AUTH_SOCK etc. +Called by '~/src/dotfiles/bin/emacsclient --spw/update-environment'." + (cl-flet ((set-all () + (cl-loop for (var val) on pairs by #'cddr do (setenv var val)))) + (with-current-buffer (get-buffer-create "*scratch*") (set-all)) + (let ((slime-connections (and (bound-and-true-p slime-default-connection) + (list slime-default-connection))) + (cl-form `(cl:handler-case (cl:require "ASDF") + (cl:error ()) + (:no-error (r) + (cl:declare (cl:ignore r)) + . ,(cl-loop for (var val) on pairs by #'cddr collect + `(cl:setf (uiop:getenv ,var) ,val)))))) (dolist (buffer (buffer-list)) - ;; 1. Eshells (with-current-buffer buffer - (when (eq major-mode 'eshell-mode) - (setenv var new-value))))))) + (cond ((eq major-mode 'eshell-mode) (set-all)) + (slime-buffer-connection + (pushnew slime-buffer-connection slime-connections))))) + (dolist (connection slime-connections) + (let ((slime-dispatching-connection connection)) + (slime-eval cl-form)))))) ;; open a frame on a new workspace with only the relevant dired buffer open, ;; eval this form: (global-set-key "\C-cG" #'spw/grading-advance) diff --git a/bin/emacsclient b/bin/emacsclient index 91cef0aa..e11cbe9c 100755 --- a/bin/emacsclient +++ b/bin/emacsclient @@ -77,10 +77,11 @@ if [ "$update" = true \ eval isset=\${$var+x} if [ "$isset" = "x" ]; then eval val=\$$var - args="$args"' (setenv "'$var'" "'$val'")' + args="$args"' "'$var'" "'$val'"' fi done - "$emacsclient" --eval "(progn$args (spw/propagate-new-environment))" + [ -n "$args" ] \ + && "$emacsclient" --eval "(spw/update-environment$args))" fi # emacsclient(1) requires an argument. As a special case, if there are no |