From unknown Fri Jun 13 10:16:41 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#75748] [emacs-guix] elisp: Change guix-set-emacs-environment to use local variables. Resent-From: Janneke Nieuwenhuizen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 22 Jan 2025 08:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 75748 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 75748@debbugs.gnu.org Cc: ludo@gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17375346889390 (code B ref -1); Wed, 22 Jan 2025 08:32:02 +0000 Received: (at submit) by debbugs.gnu.org; 22 Jan 2025 08:31:28 +0000 Received: from localhost ([127.0.0.1]:59663 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1taW91-0002RN-3R for submit@debbugs.gnu.org; Wed, 22 Jan 2025 03:31:27 -0500 Received: from lists.gnu.org ([2001:470:142::17]:55968) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1taW8x-0002R7-Kh for submit@debbugs.gnu.org; Wed, 22 Jan 2025 03:31:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1taW8o-0004tp-SG for guix-patches@gnu.org; Wed, 22 Jan 2025 03:31:15 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1taW8n-0007Um-0h; Wed, 22 Jan 2025 03:31:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=+Fdp6GpSctU0wjgZ307MHrCtqtr4Bsz9eUTSYs/hnDU=; b=eFkhmxY/H9gNmm UeGO6nujMHAm6Ehj4hPUrnditNWrSwPeiFRCJ8igo4e0DyOJFntm96x1JFugSmzyYJnEdbvp93aFI T0BdN/54bB/WlfDwr1kIBxPuXt2zWIePF+to1fYdLOg7lPJMAwzXotBCUGjTpQFMJH0kVovxtBz34 WXmKyMY53x+TRs3AMRnwx2oLHODhBpACbZ1Eag8yubTZVY2I/nbPZg4RkRU8h8dKNxsMnb1EGXAVq JYdKAr9k0Rcw3w/sBA8MrlTkG8dxGPgl/RShzrpfYDH2CSJp1XvwLfS+wna+l+1LPI/FvsAASRmZM bwv8s0MBiWrI6WORrOgw==; From: Janneke Nieuwenhuizen Date: Wed, 22 Jan 2025 09:30:58 +0100 Message-ID: <20250122083100.32018-1-janneke@gnu.org> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) This changes the semantics of "guix-set-emacs-environment" and that's probably what one would expect. Keeping old functionality as "guix-set-emacs-environment-global". * elisp/guix-misc.el (guix-set-emacs-environment): Rename to...: (guix-set-emacs-environment-global): ...this. (guix-set-emacs-environment): New procedure setting a buffer-local environment. * doc/emacs-guix.texi (Miscellaneous Commands): Update accordingly. Add hint about "emacs-envrc". --- doc/emacs-guix.texi | 17 +++++++++++++---- elisp/guix-misc.el | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/doc/emacs-guix.texi b/doc/emacs-guix.texi index 3219354..d073cb8 100644 --- a/doc/emacs-guix.texi +++ b/doc/emacs-guix.texi @@ -11,6 +11,7 @@ This document describes Emacs-Guix, the Emacs interface for the @quotation Copyright @copyright{} 2014-2019, 2021 Alex Kost@* Copyright @copyright{} 2018 Oleg Pykhalov +Copyright @copyright{} 2018, 2025 Janneke Nieuwenhuizen Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 @@ -1764,10 +1765,18 @@ Open a mail buffer to report a bug for GNU Guix similarly to @kbd{M-x@tie{}report-emacs-bug} command. @findex guix-set-emacs-environment -@item M-x guix-set-emacs-environment -Set current Emacs environment according to a specified profile. Note -that there is no way to restore the original environment (you have to -restart Emacs if you wish to do it). +@item M-x guix-set-emacs-environment-global +Buffer-locally set Emacs environment according to a specified profile. +Note that there is no way to restore the original environment for this +buffer (you have to kill the buffer and re-create it if you wish to do +it). If you find yourself using this command often, you may want to +look at the @file{emacs-envrc} package. + +@findex guix-set-emacs-environment-global +@item M-x guix-set-emacs-environment-global +Globalally set current Emacs environment according to a specified +profile. Note that there is no way to restore the original +environment (you have to restart Emacs if you wish to do it). @findex guix-pull @item M-x guix-pull diff --git a/elisp/guix-misc.el b/elisp/guix-misc.el index f4a7aaa..0cc0dfc 100644 --- a/elisp/guix-misc.el +++ b/elisp/guix-misc.el @@ -1,7 +1,7 @@ ;;; guix-misc.el --- Miscellaneous definitions -*- lexical-binding: t -*- ;; Copyright © 2014–2018 Alex Kost -;; Copyright © 2018, 2020, 2023 Janneke Nieuwenhuizen +;; Copyright © 2018, 2020, 2023, 2025 Janneke Nieuwenhuizen ;; This file is part of Emacs-Guix. @@ -223,8 +223,8 @@ FILE. With a prefix argument, also prompt for PROFILE." (guix-display-buffer guix-search-paths-buffer-name))) ;;;###autoload -(defun guix-set-emacs-environment (&optional profile) - "Set Emacs environment to match PROFILE. +(defun guix-set-emacs-environment-global (&optional profile) + "Set global Emacs environment to match PROFILE. PROFILE can be a named profile (like '~/.guix-profile', '~/.config/guix/work') or a direct link to profile from the store, like GUIX_ENVIRONMENT variable (see Info node `(guix) @@ -248,6 +248,33 @@ If PROFILE is nil, use `guix-current-profile'." (when (equal variable "INFOPATH") (setq Info-directory-list (split-string value ":"))))))) +;;;###autoload +(defun guix-set-emacs-environment (&optional profile) + "Set Emacs environment to match PROFILE. +PROFILE can be a named profile (like '~/.guix-profile', +'~/.config/guix/work') or a direct link to profile from the +store, like GUIX_ENVIRONMENT variable (see Info node `(guix) +Invoking guix environment' for details). + +If PROFILE is nil, use `guix-current-profile'." + (interactive (list (guix-read-profile))) + (let ((specs (guix-eval-read + (guix-make-guile-expression + 'search-paths-specifications + (guix-file-name profile))))) + (dolist (spec specs) + (-let* (((variable separator path) spec) + (current-value (getenv variable)) + (value (if (and separator current-value) + (concat path separator current-value) + path))) + (setq-local process-environment + (cons (concat variable "=" value) process-environment)) + (when (equal variable "PATH") + (setq-local exec-path (split-string value ":"))) + (when (equal variable "INFOPATH") + (setq-local Info-directory-list (split-string value ":"))))))) + ;;; Executing guix commands -- 2.46.0