From 293197b88f8de73a2ab427c4f02c1fe2c20d07c8 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Tue, 9 Jun 2020 10:41:51 +0200 Subject: [PATCH] Emacs/Guix: Allow using M-x shell to install profiles. --- .emacs.d/lisp/init-guix.el | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/.emacs.d/lisp/init-guix.el b/.emacs.d/lisp/init-guix.el index 7025c9f4..56e06702 100644 --- a/.emacs.d/lisp/init-guix.el +++ b/.emacs.d/lisp/init-guix.el @@ -126,6 +126,22 @@ If MANIFEST is nil, it is queried from the manifests found in `ambrevar/guix-man (first (directory-files ambrevar/guix-channel-spec-directory 'full (concat pattern "-channel")))) +(defun ambrevar/run-in-eshell (command) + (let ((eshell-buffer-name "*guix*")) + (eshell) + (when (eshell-interactive-process) + (eshell t)) + (eshell-interrupt-process) + (insert command) + (eshell-send-input))) + +(defun ambrevar/run-in-shell (command) + (shell (generate-new-buffer (generate-new-buffer-name "*guix*"))) + (goto-char (point-max)) + (comint-delete-input) + (insert command) + (comint-send-input)) + (defun ambrevar/guix-install-manifest (&optional manifest channel) "Install Guix manifest to `ambrevar/guix-extra-profiles'. @@ -138,6 +154,7 @@ If CHANNEL is nil and `ambrevar/guix-always-use-channel-specs' is non-nil, then try to use a channel specification file from `ambrevar/guix-channel-spec-directory' if any." (interactive) + (require 'init-eshell) ; For `ambrevar/prefer-eshell'. (let* ((manifest-pair (ambrevar/guix-query-manifest manifest)) (manifest-name (first manifest-pair)) (manifest (second manifest-pair)) @@ -159,18 +176,16 @@ non-nil, then try to use a channel specification file from (make-directory (expand-file-name manifest-name ambrevar/guix-extra-profiles) 'parents) - (let ((eshell-buffer-name "*guix*")) - (eshell) - (when (eshell-interactive-process) - (eshell t)) - (eshell-interrupt-process) - (insert guix " package" (concat " --manifest=" manifest) - (if (string= "default" manifest-name) - "" - (concat " --profile=" (expand-file-name ambrevar/guix-extra-profiles) - "/" manifest-name - "/" manifest-name))) - (eshell-send-input)) + (funcall (if ambrevar/prefer-eshell + 'ambrevar/run-in-eshell + 'ambrevar/run-in-shell) + (string-join + (list guix " package" (concat " --manifest=" manifest) + (if (string= "default" manifest-name) + "" + (concat " --profile=" (expand-file-name ambrevar/guix-extra-profiles) + "/" manifest-name + "/" manifest-name))))) (unless channel ;; TODO: Only do this when manifest install has succeeded. (ambrevar/guix-save-channel-specs