From 78df5e469c7f748a81baec860024a40613b959a6 Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Thu, 1 Oct 2020 11:17:18 +0200 Subject: [PATCH] Use a chemacs-early-init var This way people could still symlink .emacs -> chemacs.el, if they don't have a need for early-init support. --- chemacs-common.el => chemacs.el | 24 +++++++++++++----------- early-init.el | 5 +++-- init.el | 4 ++-- 3 files changed, 18 insertions(+), 15 deletions(-) rename chemacs-common.el => chemacs.el (92%) diff --git a/chemacs-common.el b/chemacs.el similarity index 92% rename from chemacs-common.el rename to chemacs.el index b8ff805..cbfee23 100644 --- a/chemacs-common.el +++ b/chemacs.el @@ -16,7 +16,7 @@ ;; ;; :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;; -;; Chemacs - Emacs Profile Switcher v0.1 +;; Chemacs - Emacs Profile Switcher ;; ;; INSTALLATION ;; @@ -91,7 +91,7 @@ (alist-get key (chemacs-get-emacs-profile chemacs-current-emacs-profile) default)) -(defun chemacs-load-profile (profile early-init-p) +(defun chemacs-load-profile (profile) (when (not (chemacs-get-emacs-profile profile)) (error "No profile `%s' in %s" profile chemacs-profiles-path)) (setq chemacs-current-emacs-profile profile) @@ -100,8 +100,7 @@ (init-file (expand-file-name "init.el" emacs-directory)) (custom-file- (chemacs-emacs-profile-key 'custom-file init-file)) (server-name- (chemacs-emacs-profile-key 'server-name)) - (early-init-file (expand-file-name "early-init.el" emacs-directory)) - ) + (early-init-file (expand-file-name "early-init.el" emacs-directory))) (setq user-emacs-directory emacs-directory) ;; Allow multiple profiles to each run their server @@ -114,9 +113,10 @@ (setenv (car env) (cdr env))) (chemacs-emacs-profile-key 'env)) - (if early-init-p + (if (and (boundp 'chemacs-early-init) chemacs-early-init) (when (file-exists-p early-init-file) - (load early-init-file)) + (load early-init-file) + (setq chemacs-early-init nil)) (when (chemacs-emacs-profile-key 'straight-p) (chemacs-load-straight)) @@ -130,7 +130,7 @@ (unless (equal custom-file init-file) (load custom-file)))))) -(defun chemacs-check-command-line-args (args early-init-p) +(defun chemacs-check-command-line-args (args) (if args ;; Handle either `--with-profile profilename' or ;; `--with-profile=profilename' @@ -144,14 +144,16 @@ '("--with-profile" . (lambda (_) (pop command-line-args-left)))) ;; Load the profile - (chemacs-load-profile (cadr args) early-init-p)) + (chemacs-load-profile (cadr args))) ;; Similar handling for `--with-profile=profilename' ((equal (car s) "--with-profile") (add-to-list 'command-switch-alist `(,(car args) . (lambda (_)))) - (chemacs-load-profile (mapconcat 'identity (cdr s) "=") early-init-p)) + (chemacs-load-profile (mapconcat 'identity (cdr s) "="))) - (t (chemacs-check-command-line-args (cdr args) early-init-p)))) + (t (chemacs-check-command-line-args (cdr args))))) ;; If no profile given, load the "default" profile - (chemacs-load-profile (chemacs-detect-default-profile) early-init-p))) + (chemacs-load-profile (chemacs-detect-default-profile)))) + +(chemacs-check-command-line-args command-line-args) diff --git a/early-init.el b/early-init.el index 3af7be8..35f23e9 100644 --- a/early-init.el +++ b/early-init.el @@ -2,8 +2,9 @@ (let ((chemacs-directory (file-name-directory (file-truename load-file-name)))) - (load (expand-file-name "chemacs-common.el" chemacs-directory))) + (load (expand-file-name "chemacs.el" chemacs-directory))) ;; Check for a --with-profile flag and honor it; otherwise load the ;; default profile. -(chemacs-check-command-line-args command-line-args 'early-init) +(defvar chemacs-early-init t) +(chemacs-check-command-line-args command-line-args) diff --git a/init.el b/init.el index a52cd00..55a678e 100644 --- a/init.el +++ b/init.el @@ -2,8 +2,8 @@ (let ((chemacs-directory (file-name-directory (file-truename load-file-name)))) - (load (expand-file-name "chemacs-common.el" chemacs-directory))) + (load (expand-file-name "chemacs.el" chemacs-directory))) ;; Check for a --with-profile flag and honor it; otherwise load the ;; default profile. -(chemacs-check-command-line-args command-line-args nil) +(chemacs-check-command-line-args command-line-args)