SystemCrafters / crafted-emacs

A sensible base Emacs configuration.
MIT License
739 stars 116 forks source link

Find the user's configuration file doesn't work for Chemacs 2 users #17

Closed harryfrogfather closed 2 years ago

harryfrogfather commented 2 years ago

The code in init.el checks for the two usual locations of emacs configs , but not if you are using Chemacs 2. Sorry my emacs lisp-FU is extreme novice level, and have no idea how to correct it.

sdaaish commented 2 years ago

I have Chemacs2 working on Windows, but only if I edit early-init.el. And that is because I didn't install it in the folder that the documentation recommends. Which is either ~/.rational-emacs or ~/.config/rational-emacs.

So I edited early-init-el from:


(defvar rational-config-path
  (let ((home-dir (getenv "HOME")))
    (if (file-exists-p (expand-file-name ".rational-emacs" home-dir))
      (expand-file-name ".rational-emacs" home-dir)
    (expand-file-name ".config/rational-emacs" home-dir)))
  "The user's rational-emacs configuration path.")

to:


(defvar rational-config-path user-emacs-directory)

and that makes it work for me.

I'm not sure why rational Emacs has to be installed to a specific location and not just use the built in variable user-emacs-directory. And on Windows there is no HOME variable by default, so that could also cause problems.

You don't say what OS you're on but if you try to change early-init.el as above it might work for you.

harryfrogfather commented 2 years ago

I'm on MacOS (m1) and Linux , though I only tested it on the Mac. Thanks

jeffbowman commented 2 years ago

This is an interesting conundrum. The reason is due to the fact we are looking for the rational-emacs-path in the early-init.el file, and we need to know fairly explicitly where to find that path. Initially, we used the ~ alias for the HOME folder, but as was mentioned in #19 that may not exist on Windows. I have a patch for that implementation in #32, but that only barely alleviates the problem here.

I can think of a couple of improvements:

  1. Use an environment variable, ala RATIONAL_EMACS_HOME, the fall back will be the APPDATA/HOME implementation in #32.
  2. Use something relative to the users emacs configuration folder like this: (let ((home-dir (expand-file-name "../.rational-emacs" (file-name-directory (locate-user-emacs-file "init.el"))))) ...) and fallback to the current implementation which looks in ~/.rational-emacs or ~/.config/rational-emacs if the path doesn't exist.
jeffbowman commented 2 years ago

PR #38 created for this issue, @harryfrogfather or possibly @sdaaish , could you review please and/or test? Let me know your feedback and I'll update the PR as necessary.

sdaaish commented 2 years ago

@jeffbowman So I tested this both with and without Chemacs, and it seems to work. I submitted a PR in your repo for a typo in early-init.el But with that change it works.

So:

And that worked for me. Tested in Windows with a clean setup (sandbox) where HOME is in $env:APPDATA, the default.

The only thing is the personal config-files needs the same structure with ~/rational-config/.config/rational-emacs so this might be mentioned in the README.

I set the environment-variable in the shell, but have not tested the variant with it set in .emacs-profiles.el.

bild

jeffbowman commented 2 years ago

@sdaaish Thanks!! I have installed chemacs to try to figure out the issue. It should not create an additional .config/ structure in your rational config folder. I have completely rewritten the logic now, it seems to work for me and my neophyte/naive usage of chemacs, seems to also continue to work without chemacs. I'd appreciate it if you could pull the changes from my branch and test one more time. And thanks for the PR to fix the spelling error I had!

sdaaish commented 2 years ago

Sure thing.

The number of test-cases increases with the options, so it's hard to keep track of them now… But I tested two of them anyway. Long story below.

The short story: It worked as expected what I can see.

Testing

Two tests, both with Chemacs2 and custom installation of rational_emacs. The second one with custom config path. Both cases with Windows 11 in a sandbox. Use of emacs built in $HOME variable wich is the same as ${env:AppData} in Windows.

test 1

Chemacs, custom installation of rational-emacs.

Installation

# Clone emacs repositories
& git clone https://github.com/plexus/chemacs2.git $env:AppData/.emacs.d
& git clone -b more-friendly-for-chemacs https://github.com/jeffbowman/rational-emacs.git $env:AppData/rational-test

rational-config-path

rational-config-path is a variable defined in ‘early-init.el’.
Its value is
"c:/Users/WDAGUtilityAccount/AppData/Roaming/rational-test/rational-emacs"

Documentation:
The user’s rational-emacs configuration path.

rational-config-file

rational-config-file is a variable defined in ‘init.el’.
Its value is
"c:/Users/WDAGUtilityAccount/AppData/Roaming/rational-test/rational-emacs/config.el"

Documentation:
The user’s configuration file.

Result

By adding a local config to $HOME/rational-test/rational-emacs/config.el the setup works with Chemacs2. $HOME is in this case the same as $env:Appdata.

So the test was successful.

test2

chemacs, custom installation and custom config-path.

Installation

# Clone emacs repositories
& git clone https://github.com/plexus/chemacs2.git $env:AppData/.emacs.d
& git clone -b more-friendly-for-chemacs https://github.com/jeffbowman/rational-emacs.git $env:AppData/rational-test

rational-config-path

rational-config-path is a variable defined in ‘early-init.el’.
Its value is
"c:/Users/WDAGUtilityAccount/AppData/Roaming/my-rational-emacs-config"

Documentation:
The user’s rational-emacs configuration path.

rational-config-file

rational-config-file is a variable defined in ‘init.el’.
Its value is
"c:/Users/WDAGUtilityAccount/AppData/Roaming/my-rational-emacs-config/config.el"

Documentation:
The user’s configuration file.

user-emacs-directory

user-emacs-directory is a variable defined in subr.el.

Value
"~/rational-test/"

Result

The test was successful, rational-emacs found config.el in the correct directory and loaded it without any errors.

Output

From test2.

jeffbowman commented 2 years ago

Fantastic!! Thanks for the help!! I'm going to update the docs then see if @daviwil will merge the update.

jeffbowman commented 2 years ago

With the merge of #38 can this issue be closed?

@harryfrogfather @daviwil

harryfrogfather commented 2 years ago

yes it looks ok from my perspective