Skip to content

Commit

Permalink
Rename init.example.el to init.el, allow --with-mood
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrick committed Dec 4, 2020
1 parent 1a75cfa commit 3ff07a0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ Installation

3. Pick a location for your init file. It can be any of the [files
Emacs will read on startup](https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html).
Either symlink or copy `<mood root>/init.example.el` to it:
Either symlink or copy `<mood root>/init.el` to it:

```
$ ln -s ~/Dev/mood-emacs/init.example.el ~/elisp/init.el
$ ln -s ~/Dev/mood-emacs/init.el ~/elisp/
```

or

```
$ cp ~/Dev/mood-emacs/init.example.el ~/.emacs.d/init.el
$ cp ~/Dev/mood-emacs/init.el ~/.emacs.d/
```

* If you're using Chemacs, the init file **must be** `<user root>/init.el`,
Expand All @@ -179,15 +179,16 @@ Installation
* On Windows, symlinks are not well-supported, so copying is necessary


4. Start Emacs. If using Chemacs, start it with the newly created
profile:
4. Start Emacs, optionally passing in `--with-mood <mood root>`. If
using Chemacs, start it with the newly created profile:

```
emacs --with-profile mood
emacs --with-profile mood --with-mood ~/Dev/mood-emacs
```

Emacs will prompt you to enter the location of Mood checkout
(ie. `<mood root>`), and use that to create a loader stub under

If you omit `--with-mood` from the command line, Emacs will instead
prompt you to enter the location of Mood checkout (ie. `<mood
root>`). That location will be used to create a loader stub under
`<user root>/mood.el`. The stub makes it easier to make your config
machine-independent, and should not be checked into your VCS.

Expand Down
38 changes: 38 additions & 0 deletions init.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; Mostly borrowed from Chemacs
(defun handle-mood-root-command-line-args (args)
(when args
(let* ((arg (car args))
(rest (cdr args))
;; Handle both "--with-mood foo" and "--with-mood=foo"
(s (split-string arg "=")))
(cond
((string= arg "--with-mood")
;; This is just a no-op so Emacs knows --with-profile is a
;; valid option. If we wait for command-switch-alist to be
;; processed then after-init-hook has already run.
(add-to-list 'command-switch-alist
'("--with-mood" .
(lambda (_) (pop command-line-args-left))))
(car rest))
((string= (car s) "--with-mood")
(add-to-list 'command-switch-alist (cons arg #'identity))
(mapconcat #'identity (cdr s) "="))
(t (handle-mood-root-command-line-args rest))))))

(let ((mood-file (abbreviate-file-name
(expand-file-name "mood.el" user-emacs-directory)))
(mood-root (handle-mood-root-command-line-args command-line-args))
(use-dialog-box nil))
(cond
((not (file-exists-p mood-file))
(let ((mood-root (or mood-root
(read-directory-name (format "%s not found. Where is Mood checkout root? "
mood-file)
nil nil t))))
(with-temp-file mood-file
(prin1 `(load ,(abbreviate-file-name (expand-file-name "mood" mood-root)))
(current-buffer)))
(load (expand-file-name "mood.el" mood-root))))
(mood-root
(load (expand-file-name "mood.el" mood-root)))
(t (load mood-file))))
11 changes: 0 additions & 11 deletions init.example.el

This file was deleted.

0 comments on commit 3ff07a0

Please sign in to comment.