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

Notional configuration to be more friendly for chemacs2 users #38

Merged
merged 4 commits into from
Feb 18, 2022

Conversation

jeffbowman
Copy link
Contributor

This is an attempt at making the early init use values more friendly for chemacs2 users. I don't use chemacs2, so maybe someone who does can review and/or test this approach.

Updated the README as well to explain usage.

Fix for #17

@harryfrogfather
Copy link

Im a Chemacs 2 user , ( but my emacs lisp knowledge is at 1% or lower) I have tried this and it doesn't work. but it may be because I have my Chemacs folders set up weird.
I have a folder for multiple configurations called ~/emacs-configs and then each variation has its own folder inside it.
So my rational emacs folder is at. ~/emacs-configs/rational-emacs
and emacs from scratch is just ~/emacs-configs/emacs-from-scratch

When I run your code and query the variable "rational-config-path" (using C-h v) I get this
~/emacs-configs/rational-emacs/.config/rational-emacs
I didn't see the point of having a .config as a folder inl my configs as they are just tucked away in one folder and I could never remember the macOS magic keys to unhide dotfolders. Is it normal to put .config on the folder path when using Chemacs 2???

@harryfrogfather
Copy link

Just Looked at my Folder structure, to see if I Should maybe change my folder structure. and noticed this code has inserted folders into my folder structure
~/emacs-configs/rational-emacs/.config/rational-emacs/
etc
var

@harryfrogfather
Copy link

@daviwil ,
May I suggest one of your excellent videos on how you would go about using git/github to test these branches . I know you did some vids on git and Magit. but maybe a refresher in a part of a live stream could help. Oh and this the most fun I have had in ages, thanks for all the vids.

@jeffbowman
Copy link
Contributor Author

@harryfrogfather Thanks for testing. Here is the explanation:

I set the rational-config-path based on the following order

  1. Is there an environment variable called RATIONAL_EMACS_HOME, if so, use that if not then...
  2. Are we using chemacs? If so, use the profile directory (aka user-emacs-directory). If not, then...
  3. Try to use the value from the HOME environment variable.

Having set the initial path (call it home-dir), then I look for the following in this order to complete setting the rational-config-path

  1. Does the home-dir/.rational-emacs path exist? If so, use it, otherwise...
  2. Are we using chemacs and does the home-dir/rational-emacs path exist? If so, use it, otherwise...
  3. Fallback to using home-dir/.config/rational-emacs

The important part of that last bit is if the folder already exists. So, you might try making that folder in your profile (ie profile-dir/rational-emacs) and try again. Let me know because clearly I need to update the docs.

As for your question on using git branches to test, you can just add my fork as another remote, and pull the branch from there:

  1. git remote add jeffbowman https://github.com/jeffbowman/rational-emacs -- adds my repo as an additional remote to pull from
  2. git fetch -a jeffbowman -- fetches branches from my repo
  3. git checkout more-friendly-for-chemacs -- checkout a branch from my repo
  4. start emacs

Hope that helps.

@harryfrogfather
Copy link

Thanks ,i will check this out when i get home, and respond then

The earlier rewrite depended on things existing, which is fine if the
user knows to create them, or if this is the second time emacs is
run. However, for the first run, the wrong path was almost always
created.

The logic now just identifies the path, and only if it does not exist
is it created.
@jeffbowman
Copy link
Contributor Author

@daviwil This PR should be ready to merge. Let me know if there are changes still needed.

@harryfrogfather
Copy link

@jeffbowman
followed your git instructions ( thanks for that)
ran your latest amendments and rational-config-path is now set to
~/emacs-configs/rational-emacs/rational-emacs
So config is still not loaded

by the way the value of the variable user-emacs-directory is
"~/emacs-configs/rational-emacs/"
in step 2 of your explanation you said you were setting rational-config-path to user-emacs-directory

@harryfrogfather
Copy link

I may be wrong , but is the issue in line 53 . it is adding rational-emacs to the user-emacs-directory and it is already in that variable??

@jeffbowman
Copy link
Contributor Author

jeffbowman commented Feb 17, 2022

@harryfrogfather I am assuming you have something like this in your emacs-profiles.el: (("rational" . ((user-emacs-directory . "~/emacs-configs/rational-emacs")))) in which case the additional rational-emacs folder is "correct". The value of the user-emacs-directory is where the rational emacs configuration is (ie this repo). The subfolder which is (in this case) confusingly called rational-emacs is the configuration folder which should have as contents, a var/ directory, a etc/ directory and possibly a config.el and early-config.el files.

So, I'm not exactly sure where things are going wrong for you. You should have something like this:

in:
~/emacs-configs/rational-emacs/

  • early-init.el
  • example-config.el
  • init.el
  • LICENSE
  • manifest.scm
  • modules/
  • projects
  • rational-emacs/
  • README.org
  • straight/

in
~/emacs-configs/rational-emacs/rational-emacs/

  • etc/
  • var/
  • early-config.el (maybe, if you created such a file)
  • config.el (maybe if you created such a file)

Does this help? (N.B. you might also read through #17 and see if there is anything there that might help)

@harryfrogfather
Copy link

My emacs profile.el is exactly as you describe, but folder is as follows
~/emacs-configs/rational-emacs/

early-init.el
example-config.el
init.el
LICENSE
manifest.scm
modules/
README.org
straight/
var/
etc/
config.el

i.e. no rational-emacs inside rational-emacs
I have checked my 3 over emacs configs I use with Chemacs and they all have this flatter structure.

@harryfrogfather
Copy link

ok I'm watching @daviwil Chemacs vid to see where I have gone wrong. But Chemacs has been absolutely perfect for me like this??

@jeffbowman
Copy link
Contributor Author

Humm... well... shucks... I'm stumped. lol. Have you tried starting from a clean slate? (You shouldn't need to, but... dunno...). Something is gong wrong though, it's almost as if the code in early-init.el isn't running or something. Weird.

@jeffbowman
Copy link
Contributor Author

jeffbowman commented Feb 17, 2022

I tried replicating as much of your environment as I can:

  • mkdir ~/emacs-configs
  • cd emacs-configs
  • git clone -b more-friendly-for-chemacs https://github.com/jeffbowman/rational-emacs.git rational-emacs
  • add (("rational" . ((user-emacs-directory . "~/emacs-configs/rational-emacs")))) to ~/.emacs-profiles.el
  • emacs --with-profile rational

and I get the directory structure I described in #38 (comment).

You could try:

  • mkdir -p ~/emacs-configs/rational-emacs/rational-emacs
  • cd ~/emacs-configs/rational-emacs
  • mv var rational-emacs
  • mv etc rational-emacs
  • mv config.el rational-emacs
  • emacs --with-profile rational

and see if things work out? I'm stumped as to why it wouldn't have created the nested rational-emacs folder for you though, unless your version of early-init.el doesn't have the rewrite for the rational-config-path... (You might need to do a git pull to get the latest code from my branch if you haven't).

@harryfrogfather
Copy link

I did try an awful hack earlier
(defvar rational-config-path user-emacs-directory)
and commented all the other code out that computes for windows etc.
and it works. so Iknow early-init is running.
I have watched @daviwil vid on Chemacs, and I don't see where this rational folder inside rational folder is coming from ?? is it an emacs 28 change as I upgraded from 27 very recently.

@jeffbowman
Copy link
Contributor Author

jeffbowman commented Feb 18, 2022

Ah, well, if you commented out all the code, then I don't know what to tell you.

The first rational-emacs directory is your chemacs profile (ie ~/emacs-configs/rational-emacs), so you would have made this directory manually likely by a git clone command.

The sub-folder of that, also called rational-emacs is the result of computing the rational-config-path. In my rewrite, I first figure out where it "should" be by a series of best guesses. Then, once I've decided what the value of that variable should be, I check to see if it exists in the filesystem. If it doesn't, I try to make it.

Neither of those have anything to do with what emacs version you are running, though. Not sure what I can suggest... real head scratcher.

This is the code that should be running to determine the value of the rational-config-path:

;; Find the user configuration path
;; In order do these checks:
;; * using chemacs?
;; ** yes, and have specified a location with the RATIONAL_EMACS_HOME
;;    environment variable
;; ** yes, but no environment variable, assume the rational-emacs
;;    folder in the profile
;; * use RATIONAL_EMACS_HOME environment variable
;; * XDG_CONFIG_HOME or the path .config/rational-emacs
;;   exists. XDG_CONFIG_HOME usually defaults to $HOME/.config/, so
;;   these are the same thing
;; * use HOME environment variable
(defvar rational-config-path
  (cond
   ((featurep 'chemacs)
    (if (getenv  "RATIONAL_EMACS_HOME")
        (expand-file-name (getenv "RATIONAL_EMACS_HOME"))
      (expand-file-name "rational-emacs" user-emacs-directory)))
   ((getenv "RATTIONAL_EMACS_HOME") (expand-file-name (getenv "RATIONAL_EMACS_HOME")))
   ((or (getenv "XDG_CONFIG_HOME") (file-exists-p (expand-file-name ".config/rational-emacs" (getenv "HOME"))))
    (if (getenv "XDG_CONFIG_HOME")
	(expand-file-name "rational-emacs" (getenv "XDG_CONFIG_HOME"))
      (expand-file-name ".config/rational-emacs" (getenv "HOME"))))
   ((getenv "HOME") (expand-file-name ".rational-emacs" (getenv "HOME"))))
  "The user's rational-emacs configuration path.")

And this is the code that should be running to see if the path exists, and if not, to create it:

(unless (file-exists-p rational-config-path)
  (mkdir rational-config-path t))

If yours doesn't look like this, I cannot predict the results. Does this help?

@harryfrogfather
Copy link

The hack I did was a clutching at straws to see if it would run early init after I had tried all your code. I'm going to set up the structure manually as you have suggested. ok having read your comments I see where the inner rational folder is coming from , I think I pulled early or something. ill try the manual and see. may have to come back tomorrow as its late here :)

@harryfrogfather
Copy link

ok preliminary success . Doing all them manual moves seems to make it work . Iwill test more thoroughly and report back. I have no idea what went off. Maybe because I already had a config file in the outer rational folder???!?!?!?! I am clutching at straws again I know LOLz

Copy link
Member

@daviwil daviwil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton for putting this together, the extra documentation you added is super helpful! Just a couple of tweaks and we can get this merged.

README.org Outdated Show resolved Hide resolved
README.org Show resolved Hide resolved
early-init.el Outdated Show resolved Hide resolved
* Fix spelling mistake again (d'oh!).
* Add additional wording around the idea the personal configuration
folder doesn't have to be called `rational-emacs' and how to put it
where you want.
@daviwil daviwil merged commit 976d54d into SystemCrafters:master Feb 18, 2022
@jeffbowman jeffbowman deleted the more-friendly-for-chemacs branch February 19, 2022 02:37
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

Successfully merging this pull request may close these issues.

3 participants