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

XDG support? #51

Open
favonia opened this issue Jan 12, 2021 · 2 comments
Open

XDG support? #51

favonia opened this issue Jan 12, 2021 · 2 comments

Comments

@favonia
Copy link

favonia commented Jan 12, 2021

Recent Emacs will also check ~/.config/emacs/init.el and opam user-setup should emulate the main logic used by Emacs. That is, perhaps this function needs to be changed:

let dotemacs =
let ( / ) = Filename.concat in
let dotemacs = ".emacs" in
let dotemacsdinit = ".emacs.d" / "init.el" in
if not (Sys.file_exists (home/dotemacs)) &&
Sys.file_exists (home/dotemacsdinit)
then dotemacsdinit
else dotemacs

It might also be useful to have an option to specify the location of configuration files that will somehow work with --editors.

@shonfeder
Copy link

I hit some bad behavior due to this, reported (incorrectly) to ocaml/opam#6346

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.

@shonfeder
Copy link

Maybe we should just use emacs --batch --eval '(print user-emacs-directory)', and let emacs tell us where it wants configs to go?

In the meantime, the fix to make use of user-setup while using the XDG-compatible configuration may be to just follow the linked docs' advice for older emacs compat:

(make-symbolic-link ".config/emacs" "~/.emacs.d")

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