2017-06-08 11:47:56 +02:00
|
|
|
;;; core-packages.el --- package management system -*- lexical-binding: t; -*-
|
2017-02-19 06:59:55 -05:00
|
|
|
|
2017-05-19 02:57:39 +02:00
|
|
|
;; Emacs package management is opinionated. Unfortunately, so am I. I've bound
|
|
|
|
;; together `use-package', `quelpa' and package.el to create my own,
|
|
|
|
;; rolling-release, lazily-loaded package management system for Emacs.
|
2017-02-11 06:00:08 -05:00
|
|
|
;;
|
2017-07-14 15:23:12 +02:00
|
|
|
;; The three key commands are:
|
|
|
|
;;
|
2017-11-13 17:58:16 +01:00
|
|
|
;; + `make install` or `doom//packages-install': Installs packages that are
|
2017-07-14 15:23:12 +02:00
|
|
|
;; wanted, but not installed.
|
2017-11-13 17:58:16 +01:00
|
|
|
;; + `make update` or `doom//packages-update': Updates packages that are
|
2017-07-14 15:23:12 +02:00
|
|
|
;; out-of-date.
|
2017-11-13 17:58:16 +01:00
|
|
|
;; + `make autoremove` or `doom//packages-autoremove': Uninstalls packages that
|
2017-07-14 15:23:12 +02:00
|
|
|
;; are no longer needed.
|
|
|
|
;;
|
|
|
|
;; This system reads packages.el files located in each activated module (and one
|
2017-11-13 18:03:36 +01:00
|
|
|
;; in `doom-core-dir'). These contain `package!' blocks that tell DOOM what
|
2017-07-14 15:23:12 +02:00
|
|
|
;; plugins to install and where from.
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
2017-01-28 02:02:16 -05:00
|
|
|
;; Why all the trouble? Because:
|
2017-05-19 02:57:39 +02:00
|
|
|
;; 1. Scriptability: I live in the command line. I want a programmable
|
|
|
|
;; alternative to `list-packages' for updating and installing packages.
|
2017-05-19 22:29:47 +02:00
|
|
|
;; 2. Flexibility: I want packages from sources other than ELPA. Primarily
|
|
|
|
;; github, because certain plugins are out-of-date through official channels,
|
2017-07-02 16:47:02 +02:00
|
|
|
;; have changed hands, have a superior fork, or simply aren't in any ELPA
|
|
|
|
;; repo.
|
2017-05-19 02:57:39 +02:00
|
|
|
;; 3. Stability: I used Cask before this. It would error out with cyrptic errors
|
|
|
|
;; depending on the version of Emacs I used and the alignment of the planets.
|
|
|
|
;; No more.
|
|
|
|
;; 4. Performance: A minor point, but this system is lazy-loaded (more so if you
|
|
|
|
;; byte-compile). Not having to initialize package.el (or check that your
|
|
|
|
;; packages are installed) every time you start up Emacs affords us precious
|
|
|
|
;; seconds.
|
2017-06-05 16:45:19 +02:00
|
|
|
;; 5. Simplicity: No Cask, no external dependencies (unless you count make),
|
|
|
|
;; just Emacs. Arguably, my config is still over-complicated, but shhh, it's
|
|
|
|
;; fine. Everything is fine.
|
2017-02-06 00:13:24 -05:00
|
|
|
;;
|
2018-03-14 18:25:22 -04:00
|
|
|
;; You should be able to use package.el commands without any conflicts.
|
2017-02-06 00:13:24 -05:00
|
|
|
;;
|
|
|
|
;; See core/autoload/packages.el for more functions.
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-03 07:58:16 -05:00
|
|
|
(defvar doom-init-p nil
|
2017-06-12 00:20:30 +02:00
|
|
|
"Non-nil if doom is done initializing (once `doom-post-init-hook' is done). If
|
|
|
|
this is nil after Emacs has started something is wrong.")
|
|
|
|
|
2017-06-05 14:21:52 +02:00
|
|
|
(defvar doom-init-time nil
|
|
|
|
"The time it took, in seconds, for DOOM Emacs to initialize.")
|
|
|
|
|
2018-01-29 16:55:23 -05:00
|
|
|
(defvar doom-modules
|
2018-03-12 12:53:51 -04:00
|
|
|
(make-hash-table :test #'equal :size 100 :rehash-threshold 1.0)
|
2017-02-20 09:47:27 -05:00
|
|
|
"A hash table of enabled modules. Set by `doom-initialize-modules'.")
|
2017-01-31 04:31:14 -05:00
|
|
|
|
2018-02-16 02:02:58 -05:00
|
|
|
(defvar doom-psuedo-module-dirs ()
|
|
|
|
"Additional paths for modules that are outside of `doom-modules-dirs'.
|
|
|
|
`doom//reload-autoloads', `doom//byte-compile' and `doom-initialize-packages'
|
|
|
|
will include the directories in this list.")
|
|
|
|
|
2017-06-05 14:21:52 +02:00
|
|
|
(defvar doom-packages ()
|
2017-02-11 06:00:08 -05:00
|
|
|
"A list of enabled packages. Each element is a sublist, whose CAR is the
|
|
|
|
package's name as a symbol, and whose CDR is the plist supplied to its
|
2017-02-23 00:06:12 -05:00
|
|
|
`package!' declaration. Set by `doom-initialize-packages'.")
|
2017-02-11 06:00:08 -05:00
|
|
|
|
2017-04-11 08:42:51 -04:00
|
|
|
(defvar doom-core-packages
|
2017-12-09 14:17:23 -05:00
|
|
|
'(persistent-soft use-package quelpa async)
|
2017-02-11 06:00:08 -05:00
|
|
|
"A list of packages that must be installed (and will be auto-installed if
|
|
|
|
missing) and shouldn't be deleted.")
|
|
|
|
|
2017-06-05 16:45:42 +02:00
|
|
|
(defvar doom-disabled-packages ()
|
|
|
|
"A list of packages that should be ignored by `def-package!'.")
|
|
|
|
|
2017-06-12 00:20:30 +02:00
|
|
|
(defvar doom-reload-hook nil
|
2017-09-19 15:07:57 +02:00
|
|
|
"A list of hooks to run when `doom/reload-load-path' is called.")
|
2017-06-12 00:20:30 +02:00
|
|
|
|
2018-02-16 02:02:58 -05:00
|
|
|
(defvar doom-site-load-path load-path
|
|
|
|
"The starting load-path, before it is altered by `doom-initialize'.")
|
2017-03-05 13:32:12 -05:00
|
|
|
|
2018-02-27 22:24:36 -05:00
|
|
|
(defvar doom-autoload-file (concat doom-local-dir "autoloads.el")
|
|
|
|
"Where `doom//reload-autoloads' will generate its autoloads file.")
|
|
|
|
|
|
|
|
(defvar doom-packages-file (concat doom-local-dir "packages.el")
|
|
|
|
"Where to cache `load-path' and `Info-directory-list'.")
|
2017-03-05 13:32:12 -05:00
|
|
|
|
2017-11-08 22:49:11 +01:00
|
|
|
(defvar doom--refreshed-p nil)
|
2018-02-16 02:02:58 -05:00
|
|
|
(defvar doom--current-module nil)
|
2018-03-02 17:45:15 -05:00
|
|
|
(defvar doom--initializing nil)
|
|
|
|
(defvar generated-autoload-load-name)
|
2017-06-06 12:01:10 +02:00
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
(setq autoload-compute-prefixes nil
|
|
|
|
package--init-file-ensured t
|
2017-01-16 23:15:48 -05:00
|
|
|
package-user-dir (expand-file-name "elpa" doom-packages-dir)
|
|
|
|
package-enable-at-startup nil
|
|
|
|
package-archives
|
2017-12-08 22:21:59 -05:00
|
|
|
'(("gnu" . "https://elpa.gnu.org/packages/")
|
2018-01-04 16:04:48 -05:00
|
|
|
("melpa" . "https://melpa.org/packages/")
|
|
|
|
("org" . "https://orgmode.org/elpa/"))
|
2017-02-11 00:46:42 -05:00
|
|
|
;; I omit Marmalade because its packages are manually submitted rather
|
|
|
|
;; than pulled, so packages are often out of date with upstream.
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-05-19 22:28:01 +02:00
|
|
|
;; security settings
|
2017-05-26 20:17:51 +02:00
|
|
|
gnutls-verify-error (not (getenv "INSECURE")) ; you shouldn't use this
|
2017-05-20 18:26:03 +02:00
|
|
|
tls-checktrust gnutls-verify-error
|
|
|
|
tls-program (list "gnutls-cli --x509cafile %t -p %p %h"
|
2017-05-26 20:17:51 +02:00
|
|
|
;; compatibility fallbacks
|
|
|
|
"gnutls-cli -p %p %h"
|
|
|
|
"openssl s_client -connect %h:%p -no_ssl2 -no_ssl3 -ign_eof")
|
2017-05-19 22:28:01 +02:00
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
use-package-verbose doom-debug-mode
|
2017-03-01 19:16:49 -05:00
|
|
|
use-package-minimum-reported-time (if doom-debug-mode 0 0.1)
|
2017-02-06 01:23:24 -05:00
|
|
|
|
2017-06-05 16:45:19 +02:00
|
|
|
;; Don't track MELPA, we'll use package.el for that
|
2017-01-16 23:15:48 -05:00
|
|
|
quelpa-checkout-melpa-p nil
|
|
|
|
quelpa-update-melpa-p nil
|
2017-02-19 06:59:55 -05:00
|
|
|
quelpa-melpa-recipe-stores nil
|
|
|
|
quelpa-self-upgrade-p nil
|
2017-05-21 13:42:06 +02:00
|
|
|
quelpa-verbose doom-debug-mode
|
2017-01-31 18:59:58 -05:00
|
|
|
quelpa-dir (expand-file-name "quelpa" doom-packages-dir)
|
2017-02-06 01:23:24 -05:00
|
|
|
|
2017-04-06 19:43:56 -04:00
|
|
|
byte-compile-dynamic nil
|
|
|
|
byte-compile-verbose doom-debug-mode
|
2017-04-17 02:17:26 -04:00
|
|
|
byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
(defun doom-packages--benchmark ()
|
|
|
|
(format "Doom loaded %s packages across %d modules in %.03fs"
|
|
|
|
;; Certainly imprecise, especially where custom additions to
|
|
|
|
;; load-path are concerned, but I don't mind a [small] margin of
|
|
|
|
;; error in the plugin count in exchange for faster startup.
|
|
|
|
(- (length load-path) (length doom-site-load-path))
|
2018-03-12 12:54:21 -04:00
|
|
|
(hash-table-count doom-modules)
|
2018-03-02 17:45:15 -05:00
|
|
|
(or doom-init-time
|
|
|
|
(setq doom-init-time (float-time (time-subtract (current-time) before-init-time))))))
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
|
|
;;
|
2018-03-02 17:45:15 -05:00
|
|
|
;; Bootstrap API
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
(defun doom-initialize (&optional force-p)
|
2018-03-02 17:45:15 -05:00
|
|
|
"Bootstrap the bare essentials to get Doom running, if it hasn't already. If
|
|
|
|
FORCE-P is non-nil, do it anyway.
|
2017-10-05 16:17:52 +02:00
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
1. Ensures all the essential directories exist,
|
|
|
|
2. Ensures core packages are installed,
|
|
|
|
3. Loads your autoloads file in `doom-autoload-file',
|
|
|
|
4. Builds and caches `load-path' and `Info-directory-list' in `doom-packages-file'"
|
2017-12-23 22:13:48 -05:00
|
|
|
;; Called early during initialization; only use native (and cl-lib) functions!
|
2018-03-26 02:57:34 -04:00
|
|
|
(let ((load-path doom-site-load-path))
|
|
|
|
(require 'subr-x)
|
|
|
|
(require 'cl-lib)
|
|
|
|
(require 'map))
|
2017-12-22 15:21:36 -05:00
|
|
|
(when (or force-p (not doom-init-p))
|
2018-02-27 22:24:36 -05:00
|
|
|
(unless (load doom-autoload-file t t t)
|
|
|
|
(unless noninteractive
|
|
|
|
(error "No autoloads file! Run make autoloads")))
|
2018-03-26 03:11:29 -04:00
|
|
|
(when (and noninteractive (file-exists-p doom-packages-file))
|
2018-03-26 03:06:06 -04:00
|
|
|
(delete-file doom-packages-file))
|
2018-03-02 17:45:15 -05:00
|
|
|
(when (or force-p (not (load doom-packages-file t t t)))
|
2017-12-23 22:13:48 -05:00
|
|
|
;; Ensure core folders exist, otherwise we get errors
|
|
|
|
(dolist (dir (list doom-local-dir doom-etc-dir doom-cache-dir doom-packages-dir))
|
|
|
|
(unless (file-directory-p dir)
|
|
|
|
(make-directory dir t)))
|
2018-02-27 22:24:36 -05:00
|
|
|
;; Ensure packages have been initialized
|
|
|
|
(require 'package)
|
2018-03-20 21:12:49 -04:00
|
|
|
(setq package-activated-list nil
|
|
|
|
package--initialized nil)
|
2018-02-27 22:24:36 -05:00
|
|
|
(condition-case _ (package-initialize)
|
2017-12-23 22:13:48 -05:00
|
|
|
('error (package-refresh-contents)
|
|
|
|
(setq doom--refreshed-p t)
|
2018-02-27 22:24:36 -05:00
|
|
|
(package-initialize)))
|
|
|
|
;; Ensure core packages are installed.
|
2017-12-23 22:13:48 -05:00
|
|
|
(let ((core-packages (cl-remove-if #'package-installed-p doom-core-packages)))
|
|
|
|
(when core-packages
|
|
|
|
(message "Installing core packages")
|
|
|
|
(unless doom--refreshed-p
|
|
|
|
(package-refresh-contents))
|
|
|
|
(dolist (package core-packages)
|
|
|
|
(let ((inhibit-message t))
|
|
|
|
(package-install package))
|
|
|
|
(if (package-installed-p package)
|
|
|
|
(message "✓ Installed %s" package)
|
|
|
|
(error "✕ Couldn't install %s" package)))
|
|
|
|
(message "Installing core packages...done")))
|
2018-03-26 02:57:34 -04:00
|
|
|
(cl-pushnew doom-core-dir load-path :test #'string=)
|
2018-03-26 03:06:06 -04:00
|
|
|
(doom-initialize-packages 'internal)
|
2018-03-02 17:45:15 -05:00
|
|
|
(unless noninteractive
|
|
|
|
(with-temp-buffer
|
|
|
|
(prin1 `(setq load-path ',load-path
|
2018-03-26 02:57:34 -04:00
|
|
|
Info-directory-list ',Info-directory-list
|
|
|
|
doom-disabled-packages ',doom-disabled-packages)
|
2018-03-02 17:45:15 -05:00
|
|
|
(current-buffer))
|
|
|
|
(write-file doom-packages-file))))
|
2018-02-27 22:24:36 -05:00
|
|
|
(setq doom-init-p t)))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(defun doom-initialize-autoloads ()
|
2017-02-20 09:47:27 -05:00
|
|
|
"Ensures that `doom-autoload-file' exists and is loaded. Otherwise run
|
2018-01-30 21:26:02 -05:00
|
|
|
`doom//reload-autoloads' to generate it. Used from Doom's Makefile."
|
2017-02-20 13:12:24 -05:00
|
|
|
(unless (file-exists-p doom-autoload-file)
|
2017-11-05 01:23:36 +01:00
|
|
|
(quiet! (doom//reload-autoloads))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
(defun doom-initialize-modules ()
|
|
|
|
"Bootstraps all enabled modules by loading their config.el files."
|
|
|
|
(maphash (lambda (key plist)
|
|
|
|
(let ((doom--current-module key))
|
|
|
|
(load (expand-file-name "config" (plist-get plist :path))
|
|
|
|
'noerror (not doom-debug-mode))))
|
|
|
|
doom-modules))
|
|
|
|
|
|
|
|
(defun doom-initialize-packages (&optional force-p)
|
|
|
|
"Ensures that `doom-packages', `packages-alist' and `quelpa-cache' are
|
|
|
|
populated.
|
|
|
|
|
|
|
|
This reads modules' packages.el files, runs `package-initialize', and
|
|
|
|
initializes quelpa, if they haven't already. If FORCE-P is non-nil, do it
|
2018-03-26 02:57:34 -04:00
|
|
|
anyway. If FORCE-P is 'internal, only (re)populate `doom-packages'.
|
2018-03-02 17:45:15 -05:00
|
|
|
|
|
|
|
Use this before any of package.el, quelpa or Doom's package management's API to
|
|
|
|
ensure all the necessary package metadata is initialized and available for
|
|
|
|
them."
|
2017-11-05 01:23:36 +01:00
|
|
|
(with-temp-buffer ; prevent buffer-local settings from propagating
|
2017-12-22 15:21:53 -05:00
|
|
|
(cl-flet
|
|
|
|
((_load
|
|
|
|
(file &optional noerror interactive)
|
|
|
|
(condition-case-unless-debug ex
|
|
|
|
(let ((load-prefer-newer t)
|
|
|
|
(noninteractive (not interactive)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(load file noerror 'nomessage 'nosuffix))
|
2017-12-22 15:21:53 -05:00
|
|
|
('error
|
2017-12-23 16:24:43 -05:00
|
|
|
(lwarn 'doom-initialize-packages :warning
|
|
|
|
"%s in %s: %s"
|
|
|
|
(car ex)
|
|
|
|
(file-relative-name file doom-emacs-dir)
|
|
|
|
(error-message-string ex))))))
|
2018-03-02 17:45:15 -05:00
|
|
|
;; package.el and quelpa handle themselves if their state changes during
|
|
|
|
;; the current session, but if you change an packages.el file in a module,
|
|
|
|
;; there's no non-trivial way to detect that, so we give you a way to
|
|
|
|
;; reload only doom-packages.
|
|
|
|
;; `doom-packages'
|
2017-11-05 01:23:36 +01:00
|
|
|
(when (or force-p (not doom-packages))
|
2018-03-02 17:45:15 -05:00
|
|
|
(setq doom-packages nil)
|
2017-12-22 15:21:53 -05:00
|
|
|
(_load (expand-file-name "packages.el" doom-core-dir))
|
2018-02-16 02:02:58 -05:00
|
|
|
(cl-loop for key being the hash-keys of doom-modules
|
2018-03-02 17:45:15 -05:00
|
|
|
for path = (doom-module-expand-file (car key) (cdr key) "packages.el")
|
|
|
|
if (file-exists-p path)
|
|
|
|
do (let ((doom--current-module key)) (_load path)))
|
2018-02-16 02:02:58 -05:00
|
|
|
(cl-loop for dir in doom-psuedo-module-dirs
|
|
|
|
for path = (expand-file-name "packages.el" dir)
|
|
|
|
if (file-exists-p path)
|
2018-03-02 17:45:15 -05:00
|
|
|
do (_load path)))
|
|
|
|
|
|
|
|
;; `package-alist'
|
2018-03-26 02:57:34 -04:00
|
|
|
(when (or (eq force-p t) (not (bound-and-true-p package-alist)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(setq load-path doom-site-load-path)
|
|
|
|
(require 'package)
|
|
|
|
(setq package-activated-list nil)
|
|
|
|
(package-initialize))
|
|
|
|
|
|
|
|
;; `quelpa-cache'
|
2018-03-26 02:57:34 -04:00
|
|
|
(when (or (eq force-p t) (not (bound-and-true-p quelpa-cache)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(require 'quelpa)
|
|
|
|
(setq quelpa-initialized-p nil)
|
|
|
|
(or (quelpa-setup-p)
|
|
|
|
(error "Could not initialize quelpa"))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Module API
|
|
|
|
;;
|
|
|
|
|
|
|
|
(defun doom-module-p (module submodule)
|
|
|
|
"Returns t if MODULE SUBMODULE is enabled (ie. present in `doom-modules')."
|
|
|
|
(and (hash-table-p doom-modules)
|
|
|
|
(gethash (cons module submodule) doom-modules)
|
|
|
|
t))
|
|
|
|
|
|
|
|
(defun doom-module-get (module submodule &optional property)
|
|
|
|
"Returns the plist for MODULE/SUBMODULE. If PROPERTY is set, get its property."
|
|
|
|
(when-let* ((plist (gethash (cons module submodule) doom-modules)))
|
|
|
|
(if property
|
|
|
|
(plist-get plist property)
|
|
|
|
plist)))
|
|
|
|
|
|
|
|
(defun doom-module-put (module submodule property value)
|
2018-03-26 02:58:11 -04:00
|
|
|
"Set a PROPERTY for MODULE SUBMODULE to VALUE."
|
2018-03-02 17:45:15 -05:00
|
|
|
(when-let* ((plist (doom-module-get module submodule)))
|
|
|
|
(puthash (cons module submodule)
|
|
|
|
(plist-put plist property value)
|
|
|
|
doom-modules)))
|
|
|
|
|
|
|
|
(defun doom-module-set (module submodule &rest plist)
|
|
|
|
"Adds MODULE and SUBMODULE to `doom-modules' and sets its plist to PLIST,
|
|
|
|
which should contain a minimum of :flags and :path.
|
|
|
|
|
|
|
|
MODULE is a keyword, SUBMODULE is a symbol, PLIST is a plist that accepts the
|
|
|
|
following properties:
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
:flags [SYMBOL LIST] list of enabled module flags
|
|
|
|
:path [STRING] path to module root directory
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
(doom-module-set :lang 'haskell :flags '(+intero))
|
|
|
|
|
|
|
|
Used by `require!'."
|
|
|
|
(when plist
|
|
|
|
(let ((old-plist (doom-module-get module submodule)))
|
|
|
|
(unless (plist-member plist :flags)
|
|
|
|
(plist-put plist :flags (plist-get old-plist :flags)))
|
|
|
|
(unless (plist-member plist :path)
|
|
|
|
(plist-put plist :path (or (plist-get old-plist :path)
|
|
|
|
(doom-module-find-path module submodule))))))
|
|
|
|
(let ((key (cons module submodule)))
|
|
|
|
(puthash key plist doom-modules)))
|
|
|
|
|
|
|
|
(defun doom-module-find-path (module submodule &optional file)
|
2017-02-11 00:46:42 -05:00
|
|
|
"Get the full path to a module: e.g. :lang emacs-lisp maps to
|
|
|
|
~/.emacs.d/modules/lang/emacs-lisp/ and will append FILE if non-nil."
|
2017-06-05 00:47:56 +02:00
|
|
|
(when (keywordp module)
|
|
|
|
(setq module (substring (symbol-name module) 1)))
|
|
|
|
(when (symbolp submodule)
|
|
|
|
(setq submodule (symbol-name submodule)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(cl-loop for default-directory in doom-modules-dirs
|
|
|
|
for path = (concat module "/" submodule "/" file)
|
|
|
|
if (file-exists-p path)
|
|
|
|
return (expand-file-name path)))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-02-16 02:02:58 -05:00
|
|
|
(defun doom-module-from-path (&optional path)
|
2017-09-15 13:47:05 +02:00
|
|
|
"Get module cons cell (MODULE . SUBMODULE) for PATH, if possible."
|
2018-02-16 02:02:58 -05:00
|
|
|
(or doom--current-module
|
|
|
|
(save-match-data
|
|
|
|
(setq path (file-truename path))
|
|
|
|
(when (string-match "/modules/\\([^/]+\\)/\\([^/]+\\)/.*$" path)
|
|
|
|
(when-let* ((module (match-string 1 path))
|
|
|
|
(submodule (match-string 2 path)))
|
|
|
|
(cons (intern (concat ":" module))
|
|
|
|
(intern submodule)))))))
|
2017-09-15 13:47:05 +02:00
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
(defun doom-module-expand-file (module submodule &optional file)
|
|
|
|
"Like `expand-file-name', but expands FILE relative to MODULE (keywordp) and
|
|
|
|
SUBMODULE (symbol)"
|
|
|
|
(let ((path (doom-module-get module submodule :path)))
|
|
|
|
(if file
|
|
|
|
(expand-file-name file path)
|
|
|
|
path)))
|
|
|
|
|
|
|
|
(defun doom-module-load-path ()
|
2017-11-08 22:47:06 +01:00
|
|
|
"Returns a list of absolute file paths to activated modules, with APPEND-FILE
|
|
|
|
added, if the file exists."
|
2018-03-02 17:45:15 -05:00
|
|
|
(append (cl-loop for plist being the hash-values of doom-modules
|
|
|
|
collect (plist-get plist :path))
|
2018-02-16 02:02:58 -05:00
|
|
|
(cl-remove-if-not #'file-directory-p doom-psuedo-module-dirs)))
|
2017-11-08 22:47:06 +01:00
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
|
|
|
|
;;
|
2018-03-02 17:45:15 -05:00
|
|
|
;; Module config macros
|
2017-01-31 04:31:14 -05:00
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
(autoload 'use-package "use-package" nil nil 'macro)
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro doom! (&rest modules)
|
2018-01-30 21:26:02 -05:00
|
|
|
"Bootstraps DOOM Emacs and its modules.
|
2017-07-02 16:47:02 +02:00
|
|
|
|
|
|
|
MODULES is an malformed plist of modules to load."
|
2018-03-02 17:45:15 -05:00
|
|
|
(let (load-forms module file-name-handler-alist)
|
2018-03-12 13:07:17 -04:00
|
|
|
(dolist (m modules)
|
|
|
|
(cond ((keywordp m) (setq module m))
|
|
|
|
((not module) (error "No namespace specified in `doom!' for %s" m))
|
|
|
|
((let ((submodule (if (listp m) (car m) m))
|
|
|
|
(flags (if (listp m) (cdr m))))
|
|
|
|
(let ((path (doom-module-find-path module submodule)))
|
2018-03-24 04:38:05 -04:00
|
|
|
(if (not path)
|
|
|
|
(when doom-debug-mode
|
|
|
|
(message "Couldn't find the %s %s module" module submodule))
|
2018-03-14 21:21:58 -04:00
|
|
|
(doom-module-set module submodule :flags flags :path path)
|
|
|
|
(push `(let ((doom--current-module ',(cons module submodule)))
|
|
|
|
(load! init ,path t))
|
|
|
|
load-forms)))))))
|
2018-03-12 13:07:17 -04:00
|
|
|
`(let (file-name-handler-alist)
|
|
|
|
(setq doom-modules ',doom-modules)
|
|
|
|
(let ((doom--initializing t))
|
|
|
|
,@(nreverse load-forms))
|
|
|
|
,(unless doom--initializing
|
|
|
|
'(unless noninteractive
|
|
|
|
(doom-initialize-modules))))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-06-05 16:45:42 +02:00
|
|
|
(defmacro def-package! (name &rest plist)
|
2017-12-10 14:50:43 -05:00
|
|
|
"A thin wrapper around `use-package'."
|
|
|
|
;; Ignore package if NAME is in `doom-disabled-packages'
|
2017-06-05 16:45:42 +02:00
|
|
|
(when (and (memq name doom-disabled-packages)
|
|
|
|
(not (memq :disabled plist)))
|
2017-12-28 19:15:50 -05:00
|
|
|
(setq plist `(:disabled t ,@plist)))
|
2017-12-10 14:50:43 -05:00
|
|
|
;; If byte-compiling, ignore this package if it doesn't meet the condition.
|
|
|
|
;; This avoids false-positive load errors.
|
|
|
|
(unless (and (bound-and-true-p byte-compile-current-file)
|
|
|
|
(or (and (plist-member plist :if) (not (eval (plist-get plist :if))))
|
|
|
|
(and (plist-member plist :when) (not (eval (plist-get plist :when))))
|
|
|
|
(and (plist-member plist :unless) (eval (plist-get plist :unless)))))
|
|
|
|
`(use-package ,name ,@plist)))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-06-05 14:22:30 +02:00
|
|
|
(defmacro def-package-hook! (package when &rest body)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Reconfigures a package's `def-package!' block.
|
2017-06-05 14:22:30 +02:00
|
|
|
|
2018-03-12 13:12:31 -04:00
|
|
|
Only use this macro in a module's init.el file.
|
|
|
|
|
2017-07-02 16:47:02 +02:00
|
|
|
Under the hood, this uses use-package's `use-package-inject-hooks'.
|
|
|
|
|
|
|
|
PACKAGE is a symbol; the package's name.
|
2017-06-05 16:45:42 +02:00
|
|
|
WHEN should be one of the following:
|
2017-07-02 16:47:02 +02:00
|
|
|
:pre-init :post-init :pre-config :post-config :disable
|
|
|
|
|
|
|
|
If WHEN is :disable then BODY is ignored, and DOOM will be instructed to ignore
|
|
|
|
all `def-package!' blocks for PACKAGE.
|
2017-06-05 14:22:30 +02:00
|
|
|
|
2017-07-02 16:47:02 +02:00
|
|
|
WARNING: If :pre-init or :pre-config hooks return nil, the original
|
|
|
|
`def-package!''s :init/:config block (respectively) is overwritten, so remember
|
|
|
|
to have them return non-nil (or exploit that to overwrite Doom's config)."
|
2017-06-05 14:22:30 +02:00
|
|
|
(declare (indent defun))
|
2017-06-05 16:45:42 +02:00
|
|
|
(cond ((eq when :disable)
|
2018-03-26 02:57:34 -04:00
|
|
|
(message "Using :disable with `def-package-hook!' is deprecated. Use :disable in `package!' instead.")
|
|
|
|
(ignore (push package doom-disabled-packages)))
|
2017-06-05 16:45:42 +02:00
|
|
|
((memq when '(:pre-init :post-init :pre-config :post-config))
|
|
|
|
`(progn
|
|
|
|
(setq use-package-inject-hooks t)
|
|
|
|
(add-hook!
|
|
|
|
',(intern (format "use-package--%s--%s-hook"
|
|
|
|
package
|
|
|
|
(substring (symbol-name when) 1)))
|
|
|
|
,@body)))
|
|
|
|
(t
|
|
|
|
(error "'%s' isn't a valid hook for def-package-hook!" when))))
|
2017-06-05 14:22:30 +02:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro load! (filesym &optional path noerror)
|
2017-07-02 16:38:28 +02:00
|
|
|
"Load a file relative to the current executing file (`load-file-name').
|
|
|
|
|
|
|
|
FILESYM is either a symbol or string representing the file to load. PATH is
|
2017-12-28 19:15:50 -05:00
|
|
|
where to look for the file (a string representing a directory path). If omitted,
|
|
|
|
the lookup is relative to `load-file-name', `byte-compile-current-file' or
|
2017-07-02 16:38:28 +02:00
|
|
|
`buffer-file-name' (in that order).
|
|
|
|
|
|
|
|
If NOERROR is non-nil, don't throw an error if the file doesn't exist."
|
2018-02-27 22:24:36 -05:00
|
|
|
(or (symbolp filesym)
|
|
|
|
(signal 'wrong-type-argument (list 'symbolp filesym)))
|
2017-12-28 19:15:50 -05:00
|
|
|
(let ((path (or path
|
2017-06-11 00:59:02 +02:00
|
|
|
(and load-file-name (file-name-directory load-file-name))
|
2017-02-19 06:59:55 -05:00
|
|
|
(and (bound-and-true-p byte-compile-current-file)
|
2017-05-01 14:52:29 -04:00
|
|
|
(file-name-directory byte-compile-current-file))
|
2017-07-29 00:30:13 +02:00
|
|
|
(and buffer-file-name
|
2017-12-28 19:15:50 -05:00
|
|
|
(file-name-directory buffer-file-name))
|
|
|
|
(error "Could not detect path to look for '%s' in" filesym)))
|
|
|
|
(filename (symbol-name filesym)))
|
2017-07-02 16:38:28 +02:00
|
|
|
(let ((file (expand-file-name (concat filename ".el") path)))
|
2017-02-19 06:59:55 -05:00
|
|
|
(if (file-exists-p file)
|
2017-07-29 00:11:07 +02:00
|
|
|
`(load ,(file-name-sans-extension file) ,noerror
|
|
|
|
,(not doom-debug-mode))
|
2017-02-11 06:00:08 -05:00
|
|
|
(unless noerror
|
2017-12-28 19:15:50 -05:00
|
|
|
(error "Could not load file '%s' from '%s'" file path))))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-03-02 20:45:37 -05:00
|
|
|
(defmacro require! (module submodule &optional reload-p &rest plist)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Loads the module specified by MODULE (a property) and SUBMODULE (a symbol).
|
|
|
|
|
|
|
|
The module is only loaded once. If RELOAD-P is non-nil, load it again."
|
2018-03-02 17:45:15 -05:00
|
|
|
(let ((enabled-p (doom-module-p module submodule)))
|
2018-03-02 20:45:37 -05:00
|
|
|
(when (or (not enabled-p) plist)
|
|
|
|
(apply #'doom-module-set module submodule
|
|
|
|
(mapcar #'eval plist)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(when (or reload-p (not enabled-p))
|
2018-03-02 20:45:37 -05:00
|
|
|
(let ((module-path (doom-module-find-path module submodule)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(if (file-directory-p module-path)
|
|
|
|
`(condition-case-unless-debug ex
|
|
|
|
(let ((doom--current-module ',(cons module submodule)))
|
2018-03-02 20:45:37 -05:00
|
|
|
;; ,(if plist `(doom-module-set ,module ',submodule ,@plist))
|
2018-03-02 17:45:15 -05:00
|
|
|
(load! init ,module-path :noerror)
|
|
|
|
(load! config ,module-path :noerror))
|
|
|
|
('error
|
|
|
|
(lwarn 'doom-modules :error
|
|
|
|
"%s in '%s %s' -> %s"
|
|
|
|
(car ex) ,module ',submodule
|
|
|
|
(error-message-string ex))))
|
|
|
|
(warn 'doom-modules :warning "Couldn't find module '%s %s'"
|
|
|
|
module submodule))))))
|
2017-07-29 00:11:07 +02:00
|
|
|
|
|
|
|
(defmacro featurep! (module &optional submodule flag)
|
2018-01-30 21:26:02 -05:00
|
|
|
"Returns t if MODULE SUBMODULE is enabled. If FLAG is provided, returns t if
|
|
|
|
MODULE SUBMODULE has FLAG enabled.
|
|
|
|
|
|
|
|
(featurep! :private default)
|
|
|
|
|
|
|
|
Module FLAGs are set in your config's `doom!' block, typically in
|
|
|
|
~/.emacs.d/init.el. Like so:
|
|
|
|
|
|
|
|
:private (default +flag1 -flag2)
|
|
|
|
|
|
|
|
When this macro is used from inside a module, MODULE and SUBMODULE can be
|
|
|
|
omitted. eg. (featurep! +flag1)"
|
2017-07-29 00:11:07 +02:00
|
|
|
(unless submodule
|
2017-09-15 13:47:05 +02:00
|
|
|
(let* ((path (or load-file-name byte-compile-current-file))
|
|
|
|
(module-pair (doom-module-from-path path)))
|
|
|
|
(unless module-pair
|
|
|
|
(error "featurep! couldn't detect what module I'm in! (in %s)" path))
|
|
|
|
(setq flag module
|
|
|
|
module (car module-pair)
|
|
|
|
submodule (cdr module-pair))))
|
2017-07-29 00:11:07 +02:00
|
|
|
(if flag
|
2018-03-02 17:45:15 -05:00
|
|
|
(and (memq flag (doom-module-get module submodule :flags)) t)
|
|
|
|
(doom-module-p module submodule)))
|
2017-02-11 06:52:38 -05:00
|
|
|
|
2017-02-06 00:13:24 -05:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
;;
|
2018-03-02 17:45:15 -05:00
|
|
|
;; Module package macros
|
2017-02-11 00:46:42 -05:00
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro package! (name &rest plist)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Declares a package and how to install it (if applicable).
|
|
|
|
|
|
|
|
This macro is declarative and does not load nor install packages. It is used to
|
|
|
|
populate `doom-packages' with metadata about the packages Doom needs to keep
|
|
|
|
track of.
|
|
|
|
|
2018-03-26 02:57:34 -04:00
|
|
|
Only use this macro in a module's init.el or packages.el file.
|
2017-02-04 21:07:54 -05:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
Accepts the following properties:
|
2017-02-03 20:10:40 -05:00
|
|
|
|
2018-03-26 02:57:34 -04:00
|
|
|
:recipe RECIPE Takes a MELPA-style recipe (see `quelpa-recipe' in
|
|
|
|
`quelpa' for an example); for packages to be installed
|
|
|
|
from external sources.
|
|
|
|
:pin ARCHIVE-NAME Instructs ELPA to only look for this package in
|
|
|
|
ARCHIVE-NAME. e.g. \"org\". Ignored if RECIPE is present.
|
|
|
|
:disable BOOL Do not install this package AND disable its `def-package!' blocks.
|
|
|
|
:freeze FORM Do not update this package if FORM is non-nil."
|
2017-01-16 23:15:48 -05:00
|
|
|
(declare (indent defun))
|
2018-03-26 02:57:34 -04:00
|
|
|
(cond ((memq name doom-disabled-packages) nil)
|
|
|
|
((let ((disable (plist-get plist :disable)))
|
|
|
|
(and disable (eval disable)))
|
|
|
|
(push name doom-disabled-packages)
|
|
|
|
(setq doom-packages (map-delete doom-packages name))
|
|
|
|
nil)
|
|
|
|
((let* ((old-plist (assq name doom-packages))
|
|
|
|
(pkg-recipe (or (plist-get plist :recipe)
|
|
|
|
(and old-plist (plist-get old-plist :recipe))))
|
|
|
|
(pkg-pin (or (plist-get plist :pin)
|
|
|
|
(and old-plist (plist-get old-plist :pin)))))
|
|
|
|
(when pkg-recipe
|
|
|
|
(when (= 0 (% (length pkg-recipe) 2))
|
|
|
|
(plist-put plist :recipe (cons name pkg-recipe)))
|
|
|
|
(when pkg-pin
|
|
|
|
(plist-put plist :pin nil)))
|
|
|
|
(let ((val (plist-get plist :freeze)))
|
|
|
|
(when val
|
|
|
|
(plist-put plist :freeze (eval val))))
|
|
|
|
`(progn
|
|
|
|
,(when (and pkg-pin t)
|
|
|
|
`(map-put package-pinned-packages ',name ,pkg-pin))
|
|
|
|
(map-put doom-packages ',name ',plist))))))
|
2017-01-28 02:02:16 -05:00
|
|
|
|
2018-03-26 02:58:22 -04:00
|
|
|
(defmacro packages! (&rest packages)
|
|
|
|
"A convenience macro like `package!', but allows you to declare multiple
|
|
|
|
packages at once."
|
|
|
|
`(progn ,@(cl-loop for desc in packages collect `(package! ,@desc))))
|
|
|
|
|
|
|
|
(defmacro disable-packages! (&rest packages)
|
|
|
|
"A convenience macro like `package!', but allows you to disable multiple
|
|
|
|
packages at once."
|
|
|
|
`(setq doom-disabled-packages (append ',packages doom-disabled-packages)))
|
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
(defmacro depends-on! (module submodule &optional flags)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Declares that this module depends on another.
|
|
|
|
|
|
|
|
Only use this macro in a module's packages.el file.
|
|
|
|
|
|
|
|
MODULE is a keyword, and SUBMODULE is a symbol. Under the hood, this simply
|
|
|
|
loads MODULE SUBMODULE's packages.el file."
|
2018-03-02 17:45:15 -05:00
|
|
|
`(let ((doom-modules ,doom-modules)
|
|
|
|
(flags ,flags))
|
|
|
|
(when flags
|
|
|
|
(doom-module-put ,module ',submodule :flags flags))
|
|
|
|
(load! packages ,(doom-module-find-path module submodule) t)))
|
2017-01-31 19:42:11 -05:00
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
|
|
|
|
;;
|
2017-02-03 07:58:16 -05:00
|
|
|
;; Commands
|
2017-01-31 04:31:14 -05:00
|
|
|
;;
|
|
|
|
|
2017-11-08 22:49:11 +01:00
|
|
|
(defun doom-packages--read-if-cookies (file)
|
2017-11-05 01:23:36 +01:00
|
|
|
"Returns the value of the ;;;###if predicate form in FILE."
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents-literally file nil 0 256)
|
2017-11-16 16:34:42 +01:00
|
|
|
(if (and (re-search-forward "^;;;###if " nil t)
|
|
|
|
(<= (line-number-at-pos) 3))
|
|
|
|
(let ((load-file-name file))
|
|
|
|
(eval (sexp-at-point)))
|
2017-11-05 01:23:36 +01:00
|
|
|
t)))
|
|
|
|
|
2017-11-08 22:49:11 +01:00
|
|
|
(defun doom-packages--async-run (fn)
|
2018-03-14 18:28:25 -04:00
|
|
|
(let* ((default-directory doom-emacs-dir))
|
2017-11-08 22:49:11 +01:00
|
|
|
(compile (format "%s --quick --batch -l core/core.el -f %s"
|
|
|
|
(executable-find "emacs")
|
|
|
|
(symbol-name fn)))
|
|
|
|
(while compilation-in-progress
|
|
|
|
(sit-for 1))))
|
|
|
|
|
2018-01-29 23:04:27 -05:00
|
|
|
(defun doom-packages--files (dir pattern)
|
|
|
|
"Like `directory-files-recursively', but traverses symlinks."
|
|
|
|
(cl-letf (((symbol-function #'file-symlink-p) #'ignore))
|
|
|
|
(directory-files-recursively dir pattern)))
|
|
|
|
|
2017-11-05 01:23:36 +01:00
|
|
|
(defun doom//reload-load-path ()
|
2017-07-02 16:47:02 +02:00
|
|
|
"Reload `load-path' and recompile files (if necessary).
|
|
|
|
|
|
|
|
Use this when `load-path' is out of sync with your plugins. This should only
|
|
|
|
happen if you manually modify/update/install packages from outside Emacs, while
|
|
|
|
an Emacs session is running.
|
|
|
|
|
|
|
|
This isn't necessary if you use Doom's package management commands because they
|
2018-02-08 02:15:41 -05:00
|
|
|
call `doom//reload-load-path' remotely (through emacsclient)."
|
2017-03-05 16:10:01 -05:00
|
|
|
(interactive)
|
2018-03-02 20:52:30 -05:00
|
|
|
(when (file-exists-p doom-packages-file)
|
|
|
|
(delete-file doom-packages-file))
|
2018-02-08 02:15:41 -05:00
|
|
|
(cond ((and noninteractive (not (daemonp)))
|
2017-06-03 21:00:53 +02:00
|
|
|
(require 'server)
|
2017-11-14 15:32:11 +01:00
|
|
|
(when (server-running-p)
|
2017-12-22 15:23:48 -05:00
|
|
|
(message "Reloading active Emacs session...")
|
2017-11-14 15:32:11 +01:00
|
|
|
(server-eval-at server-name '(doom//reload-load-path))))
|
2018-03-02 21:59:10 -05:00
|
|
|
(t
|
|
|
|
(doom-initialize t)
|
|
|
|
(message "%d packages reloaded" (length package-alist))
|
|
|
|
(run-hooks 'doom-reload-hook))))
|
2017-03-05 16:10:01 -05:00
|
|
|
|
2017-11-05 01:23:36 +01:00
|
|
|
(defun doom//reload-autoloads ()
|
2017-07-02 16:47:02 +02:00
|
|
|
"Refreshes the autoloads.el file, specified by `doom-autoload-file'.
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-07-02 16:47:02 +02:00
|
|
|
It scans and reads core/autoload/*.el, modules/*/*/autoload.el and
|
|
|
|
modules/*/*/autoload/*.el, and generates an autoloads file at the path specified
|
|
|
|
by `doom-autoload-file'. This file tells Emacs where to find lazy-loaded
|
|
|
|
functions.
|
2017-02-03 19:20:47 -05:00
|
|
|
|
2017-07-02 16:47:02 +02:00
|
|
|
This should be run whenever init.el or an autoload file is modified. Running
|
|
|
|
'make autoloads' from the commandline executes this command."
|
2017-01-16 23:15:48 -05:00
|
|
|
(interactive)
|
2017-06-08 11:47:56 +02:00
|
|
|
;; This function must not use autoloaded functions or external dependencies.
|
|
|
|
;; It must assume nothing is set up!
|
2017-11-08 22:49:11 +01:00
|
|
|
(if (not noninteractive)
|
2018-03-02 17:45:15 -05:00
|
|
|
;; This is done in another instance to protect the current session's state
|
|
|
|
;; in case this function has side effects.
|
2018-01-08 22:46:57 -05:00
|
|
|
(progn
|
|
|
|
(doom-packages--async-run 'doom//reload-autoloads)
|
2018-02-27 22:24:36 -05:00
|
|
|
(load doom-autoload-file t nil t))
|
2018-03-02 17:45:15 -05:00
|
|
|
(let ((default-directory doom-emacs-dir)
|
|
|
|
(targets
|
2017-11-08 22:49:11 +01:00
|
|
|
(file-expand-wildcards
|
|
|
|
(expand-file-name "autoload/*.el" doom-core-dir))))
|
2018-03-02 17:45:15 -05:00
|
|
|
(dolist (path (doom-module-load-path))
|
2017-11-08 22:49:11 +01:00
|
|
|
(let ((auto-dir (expand-file-name "autoload" path))
|
|
|
|
(auto-file (expand-file-name "autoload.el" path)))
|
2017-11-16 16:35:46 +01:00
|
|
|
(when (file-exists-p auto-file)
|
2018-03-02 17:45:15 -05:00
|
|
|
(push auto-file targets))
|
2017-11-08 22:49:11 +01:00
|
|
|
(when (file-directory-p auto-dir)
|
2018-01-29 23:04:27 -05:00
|
|
|
(dolist (file (doom-packages--files auto-dir "\\.el$"))
|
2018-03-02 17:45:15 -05:00
|
|
|
(push file targets)))))
|
2017-11-08 22:49:11 +01:00
|
|
|
(when (file-exists-p doom-autoload-file)
|
|
|
|
(delete-file doom-autoload-file)
|
|
|
|
(message "Deleted old autoloads.el"))
|
2018-03-02 17:45:15 -05:00
|
|
|
(message "Generating new autoloads.el")
|
|
|
|
(dolist (file (mapcar #'file-truename (reverse targets)))
|
|
|
|
(let ((generated-autoload-load-name file))
|
|
|
|
(message
|
|
|
|
(cond ((not (doom-packages--read-if-cookies file))
|
|
|
|
"⚠ Ignoring %s")
|
|
|
|
((update-file-autoloads file nil doom-autoload-file)
|
|
|
|
"✕ Nothing in %s")
|
|
|
|
("✓ Scanned %s"))
|
|
|
|
(if (file-in-directory-p file default-directory)
|
|
|
|
(file-relative-name file)
|
|
|
|
(abbreviate-file-name file)))))
|
2017-12-22 14:30:31 -05:00
|
|
|
(make-directory (file-name-directory doom-autoload-file) t)
|
2018-01-05 13:37:05 -05:00
|
|
|
(let ((buf (find-file-noselect doom-autoload-file t))
|
2018-02-19 01:21:47 -05:00
|
|
|
(load-path (append (list doom-emacs-dir)
|
|
|
|
doom-psuedo-module-dirs
|
2018-03-02 17:45:15 -05:00
|
|
|
doom-modules-dirs
|
|
|
|
load-path))
|
2017-11-08 22:49:11 +01:00
|
|
|
current-sexp)
|
|
|
|
(unwind-protect
|
|
|
|
(condition-case-unless-debug ex
|
|
|
|
(with-current-buffer buf
|
|
|
|
(goto-char (point-min))
|
2018-02-19 01:21:47 -05:00
|
|
|
(while (re-search-forward "^\\s-*(" nil t)
|
2018-02-19 01:31:13 -05:00
|
|
|
(unless (or (nth 4 (syntax-ppss))
|
|
|
|
(nth 3 (syntax-ppss)))
|
2018-02-27 22:24:36 -05:00
|
|
|
;; Replace autoload paths with absolute paths for faster
|
|
|
|
;; resolution during load and simpler `load-path'
|
2018-03-02 17:45:15 -05:00
|
|
|
(when (memq (sexp-at-point) '(autoload custom-autoload))
|
2018-02-19 01:21:47 -05:00
|
|
|
(save-excursion
|
|
|
|
(forward-sexp 2)
|
|
|
|
(let ((pt (point)))
|
|
|
|
(forward-sexp 1)
|
|
|
|
(when-let* ((sexp (thing-at-point 'sexp t))
|
|
|
|
(path (eval (read sexp) t)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(when (and (stringp path) (not (file-name-absolute-p path)))
|
|
|
|
(delete-region pt (point))
|
|
|
|
(if-let* ((lib (locate-library path)))
|
|
|
|
(insert " \"" (file-name-sans-extension lib) "\"")
|
|
|
|
(warn "Couldn't find absolute path for: %s" path)))))))
|
2018-02-19 01:21:47 -05:00
|
|
|
;; Run each form in autoloads to see if there are any
|
|
|
|
;; errors. We do it piecemeal because that will tell us
|
|
|
|
;; more about where the issue originated.
|
|
|
|
(save-excursion
|
|
|
|
(backward-char)
|
|
|
|
(setq current-sexp (read (thing-at-point 'sexp t)))
|
|
|
|
(eval current-sexp t))
|
|
|
|
(forward-char)))
|
|
|
|
(save-buffer)
|
2018-03-02 17:45:15 -05:00
|
|
|
(message "Done!"))
|
2017-11-08 22:49:11 +01:00
|
|
|
('error
|
|
|
|
(delete-file doom-autoload-file)
|
|
|
|
(error "Error in autoloads.el: (%s %s ...) %s -- %s"
|
|
|
|
(nth 0 current-sexp)
|
|
|
|
(nth 1 current-sexp)
|
|
|
|
(car ex) (error-message-string ex))))
|
|
|
|
(kill-buffer buf))))))
|
2017-02-20 13:12:24 -05:00
|
|
|
|
2017-11-05 01:23:36 +01:00
|
|
|
(defun doom//byte-compile (&optional modules recompile-p)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Byte compiles your emacs configuration.
|
2017-04-06 19:43:56 -04:00
|
|
|
|
2017-11-05 01:23:36 +01:00
|
|
|
init.el is always byte-compiled by this.
|
|
|
|
|
|
|
|
If MODULES is specified (a list of module strings, e.g. \"lang/php\"), those are
|
|
|
|
byte-compiled. Otherwise, all enabled modules are byte-compiled, including Doom
|
|
|
|
core. It always ignores unit tests and files with `no-byte-compile' enabled.
|
|
|
|
|
|
|
|
Doom was designed to benefit from byte-compilation, but the process may take a
|
|
|
|
while. Also, while your config files are byte-compiled, changes to them will not
|
|
|
|
take effect! Use `doom//clean-byte-compiled-files' or `make clean' to remove
|
|
|
|
these files.
|
|
|
|
|
|
|
|
If RECOMPILE-P is non-nil, only recompile out-of-date files."
|
|
|
|
(interactive
|
|
|
|
(list nil current-prefix-arg))
|
|
|
|
(let ((default-directory doom-emacs-dir)
|
2018-03-02 17:45:15 -05:00
|
|
|
(recompile-p (or recompile-p (and (member "-r" (cdr argv)) t))))
|
2017-11-05 01:23:36 +01:00
|
|
|
(if (not noninteractive)
|
2017-12-04 13:43:04 -05:00
|
|
|
;; This is done in another instance to protect the current session's
|
2018-03-02 17:45:15 -05:00
|
|
|
;; state, because this function has side effects.
|
2017-11-08 22:49:11 +01:00
|
|
|
(doom-packages--async-run 'doom//byte-compile)
|
2017-11-05 01:23:36 +01:00
|
|
|
(let ((total-ok 0)
|
|
|
|
(total-fail 0)
|
|
|
|
(total-noop 0)
|
2017-11-07 13:08:19 +01:00
|
|
|
(modules (or modules (cdr argv)))
|
2017-11-05 01:23:36 +01:00
|
|
|
compile-targets)
|
2018-03-02 17:45:15 -05:00
|
|
|
;; Ensure that Doom has been fully loaded, some of its state may be
|
|
|
|
;; pertinent to files compiled later.
|
|
|
|
(let (noninteractive)
|
|
|
|
;; Core libraries aren't fully loaded in a noninteractive session, so
|
|
|
|
;; we reload it with `noninteractive' set to nil to force them to.
|
|
|
|
(load (expand-file-name "core.el" doom-core-dir) nil t t)
|
|
|
|
;; In case autoloads.el hasn't been properly generated at this point.
|
|
|
|
(dolist (file (file-expand-wildcards (expand-file-name "autoload/*.el" doom-core-dir)))
|
|
|
|
(load file t t t)))
|
|
|
|
(doom-initialize-modules)
|
|
|
|
;; Assemble el files we want to compile; taking into account that
|
|
|
|
;; MODULES may be a list of MODULE/SUBMODULE strings from the command
|
|
|
|
;; line.
|
2017-11-05 01:23:36 +01:00
|
|
|
(setq compile-targets
|
|
|
|
(cl-loop for target
|
2018-03-02 17:45:15 -05:00
|
|
|
in (or modules (append (list doom-core-dir) (doom-module-load-path)))
|
2017-11-05 01:23:36 +01:00
|
|
|
if (equal target "core")
|
2018-01-29 23:04:27 -05:00
|
|
|
nconc (nreverse (doom-packages--files doom-core-dir "\\.el$"))
|
2017-11-05 01:23:36 +01:00
|
|
|
else if (file-directory-p target)
|
2018-01-29 23:04:27 -05:00
|
|
|
nconc (nreverse (doom-packages--files target "\\.el$"))
|
2018-02-19 01:20:53 -05:00
|
|
|
else if (cl-member target doom-psuedo-module-dirs :test #'file-in-directory-p)
|
2018-02-16 02:02:58 -05:00
|
|
|
nconc (nreverse (doom-packages--files it "\\.el$"))
|
|
|
|
else if (string-match "^\\([^/]+\\)/\\([^/]+\\)$" target)
|
|
|
|
nconc (nreverse (doom-packages--files
|
2018-03-02 17:45:15 -05:00
|
|
|
(doom-module-find-path
|
|
|
|
(intern (format ":%s" (match-string 1 target)))
|
|
|
|
(intern (match-string 2 target)))
|
2018-02-16 02:02:58 -05:00
|
|
|
"\\.el$"))
|
2017-11-05 01:23:36 +01:00
|
|
|
else if (file-exists-p target)
|
|
|
|
collect target
|
2017-11-07 13:08:19 +01:00
|
|
|
finally do (setq argv nil)))
|
2017-11-05 01:23:36 +01:00
|
|
|
(unless compile-targets
|
|
|
|
(error "No targets to compile"))
|
2018-03-02 17:45:15 -05:00
|
|
|
(condition-case ex
|
|
|
|
(let ((use-package-expand-minimally t))
|
|
|
|
(push (expand-file-name "init.el" doom-emacs-dir) compile-targets)
|
|
|
|
(dolist (target (cl-delete-duplicates (mapcar #'file-truename compile-targets) :test #'string=))
|
|
|
|
(when (or (not recompile-p)
|
|
|
|
(let ((elc-file (byte-compile-dest-file target)))
|
|
|
|
(and (file-exists-p elc-file)
|
|
|
|
(file-newer-than-file-p file elc-file))))
|
|
|
|
(let ((result (if (doom-packages--read-if-cookies target)
|
|
|
|
(byte-compile-file target)
|
|
|
|
'no-byte-compile))
|
|
|
|
(short-name (if (file-in-directory-p target doom-emacs-dir)
|
|
|
|
(file-relative-name target doom-emacs-dir)
|
|
|
|
(abbreviate-file-name target))))
|
|
|
|
(cl-incf
|
|
|
|
(cond ((eq result 'no-byte-compile)
|
|
|
|
(message! (dark (white "⚠ Ignored %s" short-name)))
|
|
|
|
total-noop)
|
|
|
|
((null result)
|
|
|
|
(message! (red "✕ Failed to compile %s" short-name))
|
|
|
|
total-fail)
|
|
|
|
(t
|
|
|
|
(message! (green "✓ Compiled %s" short-name))
|
|
|
|
(quiet! (load target t t))
|
|
|
|
total-ok))))))
|
|
|
|
(message!
|
|
|
|
(bold
|
|
|
|
(color (if (= total-fail 0) 'green 'red)
|
|
|
|
"%s %s file(s) %s"
|
|
|
|
(if recompile-p "Recompiled" "Compiled")
|
|
|
|
(format "%d/%d" total-ok (- (length compile-targets) total-noop))
|
|
|
|
(format "(%s ignored)" total-noop)))))
|
|
|
|
(error
|
|
|
|
(message! (red "\n%%s\n\n%%s\n\n%%s")
|
|
|
|
"There were breaking errors."
|
|
|
|
(error-message-string ex)
|
|
|
|
"Reverting changes...")
|
|
|
|
(doom//clean-byte-compiled-files)
|
|
|
|
(message! (green "Finished (nothing was byte-compiled)"))))))))
|
2017-11-05 01:23:36 +01:00
|
|
|
|
|
|
|
(defun doom//byte-compile-core (&optional recompile-p)
|
2017-11-08 14:42:22 +01:00
|
|
|
"Byte compile the core Doom files.
|
|
|
|
|
|
|
|
This is faster than `doom//byte-compile', still yields considerable performance
|
|
|
|
benefits, and is more reliable in an ever-changing Emacs config (since you won't
|
|
|
|
likely change core files directly).
|
|
|
|
|
|
|
|
If RECOMPILE-P is non-nil, only recompile out-of-date core files."
|
2017-04-06 19:43:56 -04:00
|
|
|
(interactive "P")
|
2017-12-31 18:28:42 -05:00
|
|
|
(if (not noninteractive)
|
|
|
|
;; This is done in another instance to protect the current session's
|
|
|
|
;; state. `doom-initialize-packages' will have side effects otherwise.
|
|
|
|
(doom-packages--async-run 'doom//byte-compile-core)
|
|
|
|
(doom//byte-compile (list "core") recompile-p)))
|
2017-03-28 15:53:47 -04:00
|
|
|
|
2017-11-05 01:23:36 +01:00
|
|
|
(defun doom//byte-recompile-plugins ()
|
|
|
|
"Recompile all installed plugins. If you're getting odd errors after upgrading
|
|
|
|
(or downgrading) Emacs, this may fix it."
|
2017-07-19 14:09:29 +02:00
|
|
|
(interactive)
|
2018-02-27 22:34:17 -05:00
|
|
|
(if (not noninteractive)
|
|
|
|
;; This is done in another instance to protect the current session's
|
|
|
|
;; state. `doom-initialize-packages' will have side effects otherwise.
|
|
|
|
(doom-packages--async-run 'doom//byte-recompile-plugins)
|
|
|
|
(byte-recompile-directory package-user-dir 0 t)))
|
2017-07-19 14:09:29 +02:00
|
|
|
|
2017-11-05 01:23:36 +01:00
|
|
|
(defun doom//clean-byte-compiled-files ()
|
2017-12-22 15:24:13 -05:00
|
|
|
"Delete all the compiled elc files in your Emacs configuration. This excludes
|
|
|
|
compiled packages.'"
|
2017-03-16 23:38:22 -04:00
|
|
|
(interactive)
|
2018-03-02 17:45:15 -05:00
|
|
|
(unless
|
|
|
|
(cl-loop with default-directory = doom-emacs-dir
|
|
|
|
for path
|
|
|
|
in (append (file-expand-wildcards "*.elc" t)
|
|
|
|
(doom-packages--files doom-core-dir "\\.elc$")
|
|
|
|
(cl-loop for dir in (doom-module-load-path)
|
|
|
|
nconc (doom-packages--files dir "\\.elc$")))
|
|
|
|
for truepath = (file-truename path)
|
|
|
|
if (file-exists-p truepath)
|
|
|
|
collect path
|
|
|
|
and do (delete-file truepath)
|
|
|
|
and do
|
|
|
|
(message "✓ Deleted %s"
|
|
|
|
(if (file-in-directory-p truepath default-directory)
|
|
|
|
(file-relative-name truepath)
|
|
|
|
(abbreviate-file-name path))))
|
|
|
|
(message "Everything is clean")))
|
2017-03-16 23:38:22 -04:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
|
|
|
|
;;
|
2018-03-14 18:25:22 -04:00
|
|
|
;; Make package.el cooperate with Doom
|
2017-02-11 00:46:42 -05:00
|
|
|
;;
|
|
|
|
|
2018-03-14 20:12:08 -04:00
|
|
|
(defun doom*initialize-packages (&rest _) (package-initialize))
|
2018-03-14 19:52:23 -04:00
|
|
|
|
2018-03-14 18:25:22 -04:00
|
|
|
(advice-add #'package-delete :before #'doom*initialize-packages)
|
2018-03-14 20:12:08 -04:00
|
|
|
(advice-add #'package-install :before #'doom*initialize-packages)
|
2018-03-14 18:25:22 -04:00
|
|
|
(advice-add #'package-refresh-contents :before #'doom*initialize-packages)
|
2018-03-14 20:12:08 -04:00
|
|
|
(advice-add #'package-reinstall :before #'doom*initialize-packages)
|
2018-03-14 18:25:22 -04:00
|
|
|
|
2017-03-27 13:05:30 -04:00
|
|
|
;; Updates QUELPA after deleting a package
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'package-delete :after #'doom*package-delete)
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-03-14 18:25:22 -04:00
|
|
|
;; Replace with Doom variants
|
2017-11-13 17:58:16 +01:00
|
|
|
(advice-add #'package-autoremove :override #'doom//packages-autoremove)
|
2018-03-14 18:25:22 -04:00
|
|
|
(advice-add #'package-install-selected-packages :override #'doom//packages-install)
|
2017-05-19 02:57:39 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(provide 'core-packages)
|
|
|
|
;;; core-packages.el ends here
|