mirror of
https://github.com/plexus/chemacs2.git
synced 2026-09-10 07:26:27 -04:00
Enable the loading a profile via CLI
Currently a profile must first be specified in `~/.emacs-profiles.el` in order to be used. In most day-to-day usage this is adequate, but on occasion it is nice to have a 'throw-away' profile. The rationale for such a profile is trying someone else's config out for a day / hour or some such, but it's not something you're committed to. This change enables the following to work: ```bash emacs --with-profile '((user-emacs-directory . "/tmp/throw-away-config"))' ```
This commit is contained in:
parent
e4f27b1156
commit
c69d929538
|
|
@ -3,6 +3,7 @@
|
|||
- Add support for early-init.el
|
||||
- Change installation from `~/.emacs` to `~/.emacs.d`
|
||||
- Allow .emacs-profiles and .emacs-profile to be stored in $XDG\_CONFIG\_HOME/chemacs
|
||||
- Allow loading a literal profile from the cli (e.g. `emacs --with-profile '((user-emacs-directory . "/path/to/config"))'` works)
|
||||
|
||||
# 1.0 (2020-10-01 / 4dad0684)
|
||||
|
||||
|
|
|
|||
|
|
@ -95,6 +95,12 @@ If no profile is given at the command line then the =default= profile is used.
|
|||
$ emacs --with-profile my-profile
|
||||
#+END_SRC
|
||||
|
||||
There is an option for using profile that is not preconfigured in =~/.emacs-profiles.el=. To accomplish that you can directly provide the profile via the command line, like so
|
||||
#+BEGIN_SRC shell
|
||||
$ emacs --with-profile '((user-emacs-directory . "/path/to/config"))'
|
||||
#+END_SRC
|
||||
This method supports all the profile options given below.
|
||||
|
||||
** .emacs-profiles.el
|
||||
|
||||
This file contains an association list, with the keys/cars being the profile
|
||||
|
|
|
|||
54
chemacs.el
54
chemacs.el
|
|
@ -31,18 +31,6 @@
|
|||
(defvar chemacs-profiles-path (or (car (seq-filter 'file-exists-p chemacs-profiles-paths)) (car chemacs-profiles-paths)))
|
||||
(defvar chemacs-default-profile-path (or (car (seq-filter 'file-exists-p chemacs-default-profile-paths)) (car chemacs-default-profile-paths)))
|
||||
|
||||
(when (not (file-exists-p chemacs-profiles-path))
|
||||
(error "[chemacs] %s does not exist." chemacs-profiles-path))
|
||||
|
||||
(defvar chemacs-default-profile-name
|
||||
(if (file-exists-p chemacs-default-profile-path)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents chemacs-default-profile-path)
|
||||
(goto-char (point-min))
|
||||
;; (buffer-string))
|
||||
(symbol-name (read (current-buffer)) ))
|
||||
"default"))
|
||||
|
||||
(defun chemacs-handle-command-line (args)
|
||||
(when args
|
||||
;; Handle either --with-profile profilename or
|
||||
|
|
@ -65,20 +53,52 @@
|
|||
|
||||
(t (chemacs-handle-command-line (cdr args)))))))
|
||||
|
||||
(defvar chemacs--with-profile-value
|
||||
(let* ((value (chemacs-handle-command-line command-line-args))
|
||||
(read-value (read value)))
|
||||
(when value
|
||||
(if (listp read-value)
|
||||
read-value
|
||||
value))))
|
||||
|
||||
(defvar chemacs-literal-profile-provided
|
||||
(and chemacs--with-profile-value
|
||||
(listp chemacs--with-profile-value)))
|
||||
|
||||
(unless (or (file-exists-p chemacs-profiles-path)
|
||||
(and chemacs--with-profile-value
|
||||
(listp chemacs--with-profile-value)))
|
||||
(error "[chemacs] %s does not exist." chemacs-profiles-path))
|
||||
|
||||
(defvar chemacs-default-profile-name
|
||||
(if (file-exists-p chemacs-default-profile-path)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents chemacs-default-profile-path)
|
||||
(goto-char (point-min))
|
||||
;; (buffer-string))
|
||||
(symbol-name (read (current-buffer)) ))
|
||||
"default"))
|
||||
|
||||
|
||||
(defvar chemacs-profile-name
|
||||
(let ((name (chemacs-handle-command-line command-line-args)))
|
||||
(if name name chemacs-default-profile-name)))
|
||||
(if (and chemacs--with-profile-value
|
||||
(stringp chemacs--with-profile-value))
|
||||
chemacs--with-profile-value
|
||||
chemacs-default-profile-name))
|
||||
|
||||
(defvar chemacs-profile
|
||||
(let ((profiles
|
||||
(if (and chemacs--with-profile-value
|
||||
(listp chemacs--with-profile-value))
|
||||
chemacs--with-profile-value
|
||||
(let ((profiles
|
||||
(with-temp-buffer
|
||||
(insert-file-contents chemacs-profiles-path)
|
||||
(goto-char (point-min))
|
||||
(read (current-buffer)))))
|
||||
(cdr (assoc chemacs-profile-name profiles))))
|
||||
(cdr (assoc chemacs-profile-name profiles)))))
|
||||
|
||||
(unless chemacs-profile
|
||||
(error "No profile `%s' in %s" profile chemacs-profiles-path))
|
||||
(error "No profile `%s' in %s" chemacs-profile-name chemacs-profiles-path))
|
||||
|
||||
(defun chemacs-profile-get (key &optional default)
|
||||
(alist-get key chemacs-profile default))
|
||||
|
|
|
|||
Loading…
Reference in a new issue