Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating opam-user-setup.el can override an existing emacs configuration #6346

Closed
shonfeder opened this issue Jan 1, 2025 · 2 comments
Closed

Comments

@shonfeder
Copy link
Contributor

shonfeder commented Jan 1, 2025

Background

I am a doom emacs user, setting up a new PC. Doom has moved to using XDG-compatible locations its default configuration source, which means keeping all configuration data in XDG_CONFIG_HOME/emacs. So, after I had my emacs configuration all nicely reproduced and tuned up, with the config loading from XDG_CONFIG_HOME/emacs, I moved on to setting up my ocaml dev env. Running user-setup install created ~/.emacs and ~/.emacs.d/opam-user-setup.el, and I thought nothing of it.

Problem

The next time I restarted emacs, I was suddenly back into the default emacs configuration.

As per the docs, this is because the ~/.emacs.d configuration location overrides the XDG-compatible location:

Emacs can also look in an XDG-compatible location for init.el, the default is the directory ~/.config/emacs. This can be overridden by setting XDG_CONFIG_HOME in your environment, its value replaces ~/.config in the name of the default XDG init file. However ~/.emacs.d, ~/.emacs, and ~/.emacs.el are always preferred if they exist, which means that you must delete or rename them in order to use the XDG location.

From the end users perspective, it looks like opam setup has hijacked the emacs configuration! This is easy to diagnose and fix if you happen to know the minutia, but could easily open up a rabbit hole hiding a red herring.

Suggested solution

The ideal behavior, I think, would be to search for existing emacs configuration data starting from the most marginal location (meaning, the one which is most easily overridden), which would mean first checking whether an existing config is located in the XDG-compatible location, and deferring to that location if found.

A complication to consider: a user could have ended up in a situation where they are actually using config data located in ~/.emacs.d, masking an old, unused XDG_CONFIG_HOME/emacs. In this case it would be helpful to alert the user of the conflict.

When in doubt, it would be better if opam prompted for input from the user rather than making a change that can override existing configurations.

opam config report

$ opam config report
# opam config report
# opam-version         2.3.0
# self-upgrade         no
# system               arch=x86_64 os=linux os-distribution=endeavouros os-version=rolling
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 27
# repositories         1 (http), 1 (version-controlled) (default repo at bc512a2d7545dee0dc96628bd52cddc17739991c)
# pinned               3 (git)
# current-switch       default
# invariant            ["ocaml" {>= "4.05.0"}]
# compiler-packages    ocaml-base-compiler.5.2.1, ocaml-options-vanilla.1
# ocaml:native         true
# ocaml:native-tools   true
# ocaml:native-dynlink true
# ocaml:stubsdir       /home/sf/.opam/default/lib/ocaml/stublibs:/home/sf/.opam/default/lib/ocaml
# ocaml:preinstalled   false
# ocaml:compiler       5.2.1
@shonfeder
Copy link
Contributor Author

Oop, this should go to https://github.com/ocaml-opam/opam-user-setup

@dbuenzli
Copy link
Contributor

dbuenzli commented Jan 1, 2025

But thanks for informing me that I can tuck my ~/.emacs.d into ~/.config/emacs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants