Skip to content

Commit

Permalink
Rewrite logic for identifying the rational config path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeffbowman committed Feb 17, 2022
1 parent bb55663 commit 4365414
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions early-init.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,34 @@
(setq initial-major-mode 'fundamental-mode)

;; 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
(let ((home-dir (if (getenv "RATTIONAL_EMACS_HOME")
(getenv "RATTIONAL_EMACS_HOME")
(if (featurep 'chemacs)
;; if we are using chemacs2, we assume we need
;; to keep the rational-config-path within the
;; current profile, so use the current
;; `user-emacs-directory' as the "HOME"
;; environment variable.
user-emacs-directory
;; Not using chemacs, and no RATIONAL_EMACS_HOME
;; environment var provided, so default to the
;; HOME environment variable.
(getenv "HOME")))))
(if (file-exists-p (expand-file-name ".rational-emacs" home-dir))
(expand-file-name ".rational-emacs" home-dir)
(if (and (featurep 'chemacs)
(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))))
(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.")

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

(defvar rational-prefer-guix-packages nil
"If t, expect packages to be installed via Guix by default.")

Expand Down

0 comments on commit 4365414

Please sign in to comment.