2019-06-08 07:13:19 +02:00
|
|
|
#!/usr/bin/env sh
|
2020-08-24 00:36:52 -04:00
|
|
|
:; set -e # -*- mode: emacs-lisp; lexical-binding: t -*-
|
2020-08-25 03:36:35 -04:00
|
|
|
:; case "$EMACS" in *term*) EMACS=emacs ;; *) EMACS="${EMACS:-emacs}" ;; esac
|
|
|
|
:; $EMACS --version >/dev/null 2>&1 || { >&2 echo "Can't find emacs in your PATH"; exit 1; }
|
2020-08-25 06:01:35 -04:00
|
|
|
:; $EMACS --no-site-file --script "$0" -- "$@" || __DOOMCODE=$?
|
2020-12-12 15:54:46 -05:00
|
|
|
:; [ "${__DOOMCODE:-0}" -eq 128 ] && { sh "`$EMACS -Q --batch --eval '(princ temporary-file-directory)'`/doom.sh" "$0" "$@" && true; __DOOMCODE=$?; }
|
2020-08-24 00:36:52 -04:00
|
|
|
:; exit $__DOOMCODE
|
2018-05-20 12:21:13 +02:00
|
|
|
|
2020-11-19 23:00:13 -05:00
|
|
|
;; The garbage collector isn't as important during CLI ops. A higher threshold
|
2021-02-21 14:43:15 -05:00
|
|
|
;; makes it 15-30% faster, but set it too high and we risk runaway memory usage
|
|
|
|
;; in longer sessions.
|
2020-05-27 02:55:14 -04:00
|
|
|
(setq gc-cons-threshold 134217728) ; 128mb
|
2021-02-21 14:43:15 -05:00
|
|
|
|
2020-08-24 00:36:52 -04:00
|
|
|
;; Prioritize non-byte-compiled source files in non-interactive sessions to
|
|
|
|
;; prevent loading stale byte-code.
|
|
|
|
(setq load-prefer-newer t)
|
2021-02-21 14:43:15 -05:00
|
|
|
|
2020-08-24 00:36:52 -04:00
|
|
|
;; Ensure Doom runs out of this file's parent directory, where Doom is
|
2020-11-19 23:00:13 -05:00
|
|
|
;; presumably installed. Use the EMACSDIR envvar to change this.
|
2020-08-24 00:36:52 -04:00
|
|
|
(setq user-emacs-directory
|
2020-11-29 14:37:32 -05:00
|
|
|
(if (getenv-internal "EMACSDIR")
|
|
|
|
(file-name-as-directory (expand-file-name (getenv-internal "EMACSDIR")))
|
2020-08-24 23:18:28 -04:00
|
|
|
(expand-file-name
|
|
|
|
"../" (file-name-directory (file-truename load-file-name)))))
|
Backport bits of CLI rewrite
The rewrite for Doom's CLI is taking a while, so I've backported a few
important changes in order to ease the transition and fix a couple bugs
sooner.
Fixes #2802, #2737, #2386
The big highlights are:
- Fix #2802: We now update recipe repos *before* updating/installing any
new packages. No more "Could not find package X in recipe repositories".
- Fix #2737: An edge case where straight couldn't reach a pinned
commit (particularly with agda).
- Doom is now smarter about what option it recommends when straight
prompts you to make a choice.
- Introduces a new init path for Doom. The old way:
- Launch in "minimal" CLI mode in non-interactive sessions
- Launch a "full" interactive mode otherwise.
The new way
- Launch in "minimal" CLI mode *only* for bin/doom
- Launch is a simple mode for non-interactive sessions that still need
access to your interactive config (like async org export/babel).
- Launch a "full" interactive mode otherwise.
This should fix compatibility issues with plugins that use the
async.el library or spawn child Emacs processes to fake
parallelization (like org's async export and babel functionality).
- Your private init.el is now loaded more reliably when running any
bin/doom command. This gives you an opportunity to configure its
settings.
- Added doom-first-{input,buffer,file}-hook hooks, which we use to queue
deferred activation of a number of packages. Users can remove these
modes from these hooks; altogether preventing them from loading,
rather than waiting for them to load to then disable them,
e.g. (after! smartparens (smartparens-global-mode -1)) -> (remove-hook
'doom-first-buffer #'smartparens-global-mode)
Hooks added to doom-first-*-hook variables will be removed once they
run.
This should also indirectly fix #2386, by preventing interactive modes
from running in non-interactive session.
- Added `doom/bump-*` commands to make bumping modules and packages
easier, and `doom/bumpify-*` commands for converting package!
statements into user/repo@sha1hash format for bump commits.
- straight.el is now commit-pinned, like all other packages. We also
more reliably install straight.el by cloning it ourselves, rather than
relying on its bootstrap.el.
This should prevent infinite "straight has diverged from master"
prompts whenever we change branches (though, you might have to put up
with it one more after this update -- see #2937 for workaround).
All the other minor changes:
- Moved core/autoload/cli.el to core/autoload/process.el
- The package manager will log attempts to check out pinned commits
- If package state is incomplete while rebuilding packages, emit a
simpler error message instead of an obscure one!
- Added -u switch to 'doom sync' to make it run 'doom update' afterwards
- Added -p switch to 'doom sync' to make it run 'doom purge' afterwards
- Replace doom-modules function with doom-modules-list
- The `with-plist!` macro was removed, since `cl-destructuring-bind`
already serves that purpose well enough.
- core/autoload/packages.el was moved into core-packages.el
- bin/doom will no longer die if DOOMDIR or DOOMLOCALDIR don't have a
trailing slash
- Introduces doom-debug-variables; a list of variables to toggle on
doom/toggle-debug-mode.
- The sandbox has been updated to reflect the above changes, also:
1. Child instances will no longer inherit the process environment of
the host instance,
2. It will no longer produce an auto-save-list directory in ~/.emacs.d
2020-05-14 15:00:23 -04:00
|
|
|
|
2021-05-09 20:47:06 -04:00
|
|
|
;; HACK Load `cl' and site files manually to prevent polluting logs and stdout
|
|
|
|
;; with deprecation and/or file load messages.
|
|
|
|
(let ((inhibit-message t))
|
|
|
|
(require 'cl)
|
|
|
|
(unless site-run-file
|
|
|
|
(setq site-run-file "site-start")
|
|
|
|
(let ((verbose (or (getenv "DEBUG") init-file-debug))
|
|
|
|
(tail load-path)
|
|
|
|
(lispdir (expand-file-name "../lisp" data-directory))
|
|
|
|
dir)
|
|
|
|
(while tail
|
|
|
|
(setq dir (car tail))
|
|
|
|
(let ((default-directory dir))
|
|
|
|
(load (expand-file-name "subdirs.el") t (not verbose) t))
|
|
|
|
(or (string-prefix-p lispdir dir)
|
|
|
|
(let ((default-directory dir))
|
|
|
|
(load (expand-file-name "leim-list.el") t (not verbose) t)))
|
|
|
|
(setq tail (cdr tail)))
|
|
|
|
(load site-run-file t (not verbose)))))
|
|
|
|
|
2021-03-12 17:55:41 -05:00
|
|
|
(kill-emacs
|
|
|
|
(pcase
|
|
|
|
(catch 'exit
|
|
|
|
;; Catch some potential issues early
|
|
|
|
(cond
|
|
|
|
((version< emacs-version "26.3")
|
|
|
|
(princ (concat "Detected Emacs " emacs-version " (at " (car command-line-args) ").\n\n"))
|
|
|
|
(princ "Doom only supports Emacs 26.3 and newer. 27.1 is highly recommended. A guide\n")
|
|
|
|
(princ "to install a newer version of Emacs can be found at:\n\n ")
|
|
|
|
(princ (format "https://doomemacs.org/docs/getting_started.org#%s"
|
|
|
|
(cond ((eq system-type 'darwin) "on-macos")
|
|
|
|
((memq system-type '(cygwin windows-nt ms-dos)) "on-windows")
|
|
|
|
("on-linux"))))
|
|
|
|
(princ "Aborting...")
|
|
|
|
1)
|
2018-05-20 12:21:13 +02:00
|
|
|
|
2021-03-12 17:55:41 -05:00
|
|
|
((not (file-readable-p (expand-file-name "core/core.el" user-emacs-directory)))
|
|
|
|
(princ (concat "Couldn't find or read '"
|
|
|
|
(abbreviate-file-name
|
|
|
|
(expand-file-name "core/core.el" user-emacs-directory))
|
|
|
|
"'.\n\n"))
|
|
|
|
(princ "Are you sure Doom Emacs is correctly installed?\n\n")
|
|
|
|
(when (file-symlink-p load-file-name)
|
|
|
|
(princ "This error can occur if you've symlinked the 'doom' script, which Doom does not\n")
|
|
|
|
(princ "support. Consider symlinking its parent directory instead or explicitly set the\n")
|
|
|
|
(princ "EMACSDIR environment variable, e.g.\n\n ")
|
|
|
|
(princ (if (string-match-p "/fish$" (getenv "SHELL"))
|
|
|
|
"env EMACSDIR=~/.emacs.d doom"
|
|
|
|
"EMACSDIR=~/.emacs.d doom sync"))
|
|
|
|
(princ "\n\n")
|
|
|
|
(princ "Aborting..."))
|
|
|
|
2)
|
2018-05-20 12:21:13 +02:00
|
|
|
|
2021-03-12 17:55:41 -05:00
|
|
|
((and (equal (user-real-uid) 0)
|
|
|
|
(/= 0 (file-attribute-user-id (file-attributes user-emacs-directory))))
|
|
|
|
(princ "Do not run this script as root. It will cause file permissions errors later.\n\n")
|
|
|
|
(princ "To carry on anyway, change the owner of your Emacs config to root:\n\n")
|
|
|
|
(princ (concat " chown root:root -R " (abbreviate-file-name user-emacs-directory) "\n\n"))
|
|
|
|
(princ "Aborting...")
|
|
|
|
3)
|
2020-12-01 19:33:55 -05:00
|
|
|
|
2021-03-12 17:55:41 -05:00
|
|
|
;; Load the heart of the beast and its CLI processing library
|
|
|
|
((load (expand-file-name "core/core.el" user-emacs-directory) nil t)
|
|
|
|
(require 'core-cli)
|
2018-06-20 02:07:20 +02:00
|
|
|
|
2021-03-12 17:55:41 -05:00
|
|
|
;; Process the arguments passed to this script. `doom-cli-execute'
|
|
|
|
;; should return a boolean, integer (error code) or throw an 'exit
|
|
|
|
;; event, which is handled specially.
|
|
|
|
(apply #'doom-cli-execute :doom (cdr (member "--" argv))))))
|
2020-08-26 22:31:46 -04:00
|
|
|
|
2020-11-19 23:00:13 -05:00
|
|
|
;; Any non-zero integer is treated as an explicit exit code.
|
2021-03-12 17:55:41 -05:00
|
|
|
((and (pred integerp) code)
|
|
|
|
code)
|
|
|
|
|
2020-11-19 23:00:13 -05:00
|
|
|
;; If, instead, we were given a string or list of strings, copy these as
|
|
|
|
;; shell script commands to a temporary script file which this script will
|
|
|
|
;; execute after this session finishes. Also accepts special keywords, like
|
2021-03-12 17:55:41 -05:00
|
|
|
;; `:restart', to rerun the current command with the same arguments.
|
2020-08-24 00:36:52 -04:00
|
|
|
((and (or (pred consp)
|
|
|
|
(pred stringp)
|
|
|
|
(pred keywordp))
|
|
|
|
command)
|
2020-08-27 00:58:03 -04:00
|
|
|
(let ((script (expand-file-name "doom.sh" temporary-file-directory))
|
2020-08-24 00:36:52 -04:00
|
|
|
(coding-system-for-write 'utf-8-unix)
|
|
|
|
(coding-system-for-read 'utf-8-unix))
|
|
|
|
(with-temp-file script
|
|
|
|
(insert "#!/usr/bin/env sh\n"
|
|
|
|
"_postscript() {\n"
|
|
|
|
" rm -f " (shell-quote-argument script) "\n "
|
2021-03-12 17:55:41 -05:00
|
|
|
(cond ((eq command :restart) "$@")
|
|
|
|
((stringp command) command)
|
2020-08-24 00:36:52 -04:00
|
|
|
((string-join
|
|
|
|
(if (listp (car-safe command))
|
|
|
|
(cl-loop for line in (doom-enlist command)
|
|
|
|
collect (mapconcat #'shell-quote-argument (remq nil line) " "))
|
|
|
|
(list (mapconcat #'shell-quote-argument (remq nil command) " ")))
|
|
|
|
"\n ")))
|
|
|
|
"\n}\n"
|
|
|
|
(save-match-data
|
2020-09-01 15:12:10 -04:00
|
|
|
(cl-loop for env
|
|
|
|
in (cl-set-difference process-environment
|
2021-05-05 15:55:44 -04:00
|
|
|
(get 'process-environment 'initial-value)
|
2020-09-01 15:12:10 -04:00
|
|
|
:test #'equal)
|
2020-08-24 00:36:52 -04:00
|
|
|
if (string-match "^\\([a-zA-Z0-9_]+\\)=\\(.+\\)$" env)
|
|
|
|
concat (format "%s=%s \\\n"
|
|
|
|
(match-string 1 env)
|
|
|
|
(shell-quote-argument (match-string 2 env)))))
|
|
|
|
(format "PATH=\"%s%s$PATH\" \\\n" (concat doom-emacs-dir "bin/") path-separator)
|
|
|
|
"_postscript $@\n"))
|
2020-12-12 15:54:46 -05:00
|
|
|
(set-file-modes script #o600))
|
2020-08-24 00:36:52 -04:00
|
|
|
;; Error code 128 is special: it means run the post-script after this
|
|
|
|
;; session ends.
|
|
|
|
128)
|
2021-03-12 17:55:41 -05:00
|
|
|
|
2020-08-24 00:36:52 -04:00
|
|
|
;; Anything else (e.g. booleans) is treated as a successful run. Yes, a `nil'
|
|
|
|
;; indicates a successful run too!
|
|
|
|
(_ 0)))
|