plexus / chemacs2

Emacs version switcher, improved
769 stars 46 forks source link

Spacemacs does not load its configuration file outside my home directory #23

Open mavilar opened 3 years ago

mavilar commented 3 years ago

I was trying to use Chemacs 2 for having different Spacemacs configurations, so I cloned this repo and created an .emacs-profiles.el that looks like this:

(("default" . ((user-emacs-directory . "~/.emacs.my.configs/spacemacs/master/.spacemacs.d")))
              (env . (("SPACEMACSDIR" . "~/.emacs.my.configs/spacemacs/master/.spacemacs.conf"))))

The directory .spacemacs.d contains the Spacemacs installation and the directory .spacemacs.conf contains the .spacemacs configuration file and the .spacemacs.env file, but when I start Emacs, it loads Spacemacs correctly but not the configuration. If I keep the .spacemacs file in my home directory it works fine. Maybe I'm doing something wrong?

Lockszmith-GH commented 2 years ago

I'm doing something similar - it's less about multiple spacemacs configs, and more about wanting to have my spacemacs config in a separate git repo.

@mavilar - Did you figure this out?

mavilar commented 2 years ago

I did, but forgot this issue.

First of all, that code has some wrong parentheses. This is the one I am using now:

(("default" . ((user-emacs-directory . "~/.config/emacs/spacemacs/master/.emacs.d")
               (env . (("SPACEMACSDIR" . "~/.config/emacs/spacemacs/master/.spacemacs.d"))))))

In addition, if you want Spacemacs to save its configuration and environment variables in the .spaecmacs.d directory, the configuration file must be named init.el, otherwise it won't find it.

Lockszmith-GH commented 2 years ago

Thanks for the update. I just tried that and it worked for me as well.

Hope someone else will find it useful in the future.

nc10 commented 6 months ago

I had the same issue and found this in /core/core-dotspacemacs.el

(defconst dotspacemacs-filepath
(let* ((spacemacs-dir-env (getenv "SPACEMACSDIR"))
        (spacemacs-init (if spacemacs-dir-env
                            (expand-file-name "init.el" spacemacs-dir-env)
                         (expand-file-name ".spacemacs" user-home-directory))))
     (if (file-regular-p spacemacs-init)
         spacemacs-init
       (let ((fallback-init (expand-file-name ".spacemacs.d/init.el"
                                              user-home-directory)))
         (if (file-regular-p fallback-init)
             fallback-init
           spacemacs-init))))
 "Filepath to Spacemacs configuration file (defaults to ~/.spacemacs).
- If environment variable SPACEMACSDIR is set and SPACEMACSDIR/init.el
 exists, use that value.
- Otherwise use ~/.spacemacs if it exists.
- Otherwise use $HOME/.spacemacs.d/init.el if it exists.")
plexus commented 6 months ago

Would a clarification in the chemacs2 README help? We do have a Spacemacs section, improvements or additions to that are most welcome.

nc10 commented 6 months ago

Updating the README can help. However, when you search for the issue, this post is the first hit in Google. So it should be easy for folks to find out how it can be fixed.

The part that was confusing on my side was that spacemacs has an init file in its root folder (.spacemacs.d). The instruction from mavilar was not clear about whether we should replace this file with the user's .spacemacs (when renamed to init) or it should be renamed and put in a different folder so that it does not clash with this file.

I ended up putting it under .spacemacs.d/private folder in a separate directory since updating the spacemacs does not touch what is in .spacemacs.d/private folder. Here is what I currently have in my .emacs-profiles.el

(("default" . ((user-emacs-directory . "~/spacemacs.d")
               (env . (("SPACEMACSDIR" . "~/spacemacs.d/private/user-config")))))
 ("customized" . ((user-emacs-directory . "~/emacs.d")))
 ("spacemacs-core" . ((user-emacs-directory . "~/spacemacs-core.d")
                      (env . (("SPACEMACSDIR" . "~/spacemacs-core.d/private/user-config")))))
 )