plexus / chemacs2

Emacs version switcher, improved
779 stars 47 forks source link

Add support for environment variables in profiles.el #52

Closed pperanich closed 1 year ago

pperanich commented 1 year ago

This change adds support for using environment variables in the emacs profiles defined in profiles.el.

e.g. this allows a user to specify profile install locations to comply with XDG specfication:

(
 ("spacemacs" . (
                 (user-emacs-directory . "$XDG_CONFIG_HOME/emacs-spacemacs/")
                 (env . (("SPACEMACSDIR" . "$XDG_CONFIG_HOME/spacemacs/")))
                 )
  )
 ("doom" . (
            (user-emacs-directory . "$XDG_CONFIG_HOME/emacs-doom")
            )
  )
 )
plexus commented 1 year ago

I understand the desire for this, but there are a few issues with this PR. substitute-in-file-name assumes that its argument is a file name. Not every env value supplied will be a file name, and if they contain a tilde or double slash the additional munging in substitute-in-file-name will cause problems.

This highlights that this is a breaking change, which I'm reluctant to allow. Alternatives would be to introduce a new key like env-expand, and leave the existing behavior as is. Alternatively a flag like env-substitute-p can be introduced to opt-in to this behavior.

For user-emacs-directory I can see fewer instances of it causing trouble, people don't generally have dollar signs in their emacs dir path, although there's always someone... but introducing this as a start for user-emacs-directory I would be ok with.

Introducing this does open the door to other questions, like can I use an env var in a subsequent value? e.g. does this work.

(env . (
("FOO" . "123")
("BAR" . "$FOO/456")))

People might also expect the ${FOO} syntax to work, which it seems substitute-in-filename doesn't do, so that needs to be documented.

In general a change like this should come with README updates.

thanks!

AnweshGangula commented 3 months ago

I found a related question in stackoverflow which suggests using lexical programming to acheive this.