From b77b475469540a18a175d5042bcf45b12954ac75 Mon Sep 17 00:00:00 2001 From: "Anton I. Sipos" Date: Sun, 8 Aug 2021 11:22:33 -0700 Subject: [PATCH] Allow specifying profile in CHEMACS_PROFILE environment variable. --- README.org | 9 ++++++--- chemacs.el | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.org b/README.org index ad6244b..c79ad17 100644 --- a/README.org +++ b/README.org @@ -99,7 +99,9 @@ below. Chemacs adds an extra command line option to Emacs, =--with-profile=. Profiles are configured in =~/.emacs-profiles.el=. -If no profile is given at the command line then the =default= profile is used. +If no profile is given at the command line then the environment variable +CHEMACS_PROFILE is used. If this environment variables isn't set then the +=default= profile is used. #+BEGIN_SRC shell $ emacs --with-profile my-profile @@ -146,8 +148,9 @@ for a helpful script to do that. ** Changing the default profile (e.g. for GUI editors) -Where it is not possible to use the =--with-profile= flag, the default profile -can be set using a =~/.emacs-profile= file. +Where it is not possible to use the =--with-profile= flag or the CHEMACS_PROFILE +environment variable, the default profile can be set using a =~/.emacs-profile= +file. If your =~/.emacs-profiles.el= file contains the following: diff --git a/chemacs.el b/chemacs.el index 0af2b77..efc160a 100644 --- a/chemacs.el +++ b/chemacs.el @@ -30,6 +30,7 @@ (defvar config-home (or (getenv "XDG_CONFIG_HOME") "~/.config")) (defvar chemacs-profiles-paths (list "~/.emacs-profiles.el" (format "%s/%s" config-home "chemacs/profiles.el" ))) (defvar chemacs-default-profile-paths (list "~/.emacs-profile" (format "%s/%s" config-home "chemacs/profile"))) +(defvar chemacs-profile-env-var "CHEMACS_PROFILE") ;; Copy `seq' library's `seq-filter' to avoid requiring it, see note above. (defun chemacs--seq-filter (pred sequence) @@ -95,10 +96,12 @@ (defvar chemacs-profile-name - (if (and chemacs--with-profile-value - (stringp chemacs--with-profile-value)) - chemacs--with-profile-value - chemacs-default-profile-name)) + (let ((env-profile-value (getenv chemacs-profile-env-var))) + (cond ((and chemacs--with-profile-value + (stringp chemacs--with-profile-value)) + chemacs--with-profile-value) + (env-profile-value env-profile-value) + (t chemacs-default-profile-name)))) (defvar chemacs-profile (if (and chemacs--with-profile-value