2017-01-16 23:15:48 -05:00
|
|
|
;;; core-packages.el
|
2017-02-19 06:59:55 -05:00
|
|
|
|
2017-03-01 21:42:51 -05:00
|
|
|
;; Emacs package management is opinionated. Unfortunately, so am I. With the
|
|
|
|
;; help of `use-package', `quelpa' and package.el, DOOM Emacs manages its
|
|
|
|
;; plugins and their dependencies through `doom/packages-install',
|
|
|
|
;; `doom/packages-update' and `doom/packages-autoremove', which can be called
|
|
|
|
;; via `make' on the command line (make {install,update,autoremove}).
|
2017-02-11 06:00:08 -05:00
|
|
|
;;
|
2017-03-01 21:42:51 -05:00
|
|
|
;; My config is divided into two parts: configuration and packages.el files.
|
|
|
|
;; You'll find packages.el files in each DOOM module (in `doom-modules-dir') and
|
|
|
|
;; one in `doom-core-dir'. When executed, they fill `doom-packages' and
|
|
|
|
;; `doom-modules', which are necessary for DOOM to extrapolate all kinds of
|
|
|
|
;; information about plugins.
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
2017-01-28 02:02:16 -05:00
|
|
|
;; Why all the trouble? Because:
|
2017-03-01 21:42:51 -05:00
|
|
|
;; 1. Scriptability: I want an alternative to package.el's list-packages
|
|
|
|
;; interface for updating and installing packages.
|
|
|
|
;; 2. Flexibility: I sometimes want packages from sources other than ELPA. Like
|
|
|
|
;; github or the Emacs wiki, because certain plugins are out-of-date through
|
|
|
|
;; official channels, have changed hands unofficially, or simply haven't been
|
2017-02-11 06:00:08 -05:00
|
|
|
;; submitted to an ELPA repo yet.
|
2017-02-01 00:29:39 -05:00
|
|
|
;; 3. Stability: I don't want to worry that each time I use my package
|
2017-03-01 21:42:51 -05:00
|
|
|
;; manager something might inexplicably go wrong. Cask, I'm looking at you.
|
2017-02-11 06:00:08 -05:00
|
|
|
;; 4. Performance: A minor point, but it helps startup performance not to do
|
|
|
|
;; package.el initialization and package installation checks at startup.
|
|
|
|
;; 5. Simplicity: Without Cask, I have no external dependencies to worry about
|
2017-03-01 21:42:51 -05:00
|
|
|
;; (unless you count make). DOOM handles itself. Arguably, my emacs.d is
|
2017-02-11 06:00:08 -05:00
|
|
|
;; overcomplicated, but configuring is simpler as a result (well, for me
|
|
|
|
;; anyway :P).
|
2017-02-06 00:13:24 -05:00
|
|
|
;;
|
2017-02-11 06:00:08 -05:00
|
|
|
;; It should be safe to use package.el functionality, however, avoid
|
2017-03-01 21:42:51 -05:00
|
|
|
;; `package-autoremove' as it will not reliably select the correct packages to
|
2017-02-11 06:00:08 -05:00
|
|
|
;; delete.
|
2017-02-09 04:25:32 -05:00
|
|
|
;;
|
2017-02-11 06:00:08 -05:00
|
|
|
;; For complete certainty, I've provided DOOM alternatives of package commands,
|
2017-03-01 21:42:51 -05:00
|
|
|
;; like `doom/install-package', `doom/delete-package' & `doom/update-packages'.
|
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-02-20 09:47:27 -05:00
|
|
|
"Non-nil if doom's package system has been initialized (by `doom-initialize').
|
|
|
|
This will be nil if you have byte-compiled your configuration (as intended).")
|
2017-02-11 06:00:08 -05:00
|
|
|
|
|
|
|
(defvar doom-modules nil
|
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
|
|
|
|
2017-02-11 06:00:08 -05:00
|
|
|
(defvar doom-packages nil
|
|
|
|
"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-02-20 21:57:39 +10:30
|
|
|
'(persistent-soft quelpa use-package)
|
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-04-11 08:43:26 -04:00
|
|
|
(defvar doom-protected-packages nil
|
|
|
|
"A list of packages that shouldn't be deleted by `doom/packages-autoremove'.")
|
|
|
|
|
2017-02-20 16:42:07 -05:00
|
|
|
(defvar doom-init-time nil
|
|
|
|
"The time it took, in seconds, for DOOM Emacs to initialize.")
|
|
|
|
|
2017-04-12 08:52:57 -04:00
|
|
|
(defvar doom-inhibit-reload nil
|
|
|
|
"If non-nil, remote reload calls (via the server) will be ignored.")
|
|
|
|
|
2017-03-05 13:32:12 -05:00
|
|
|
(defvar doom--site-load-path load-path
|
|
|
|
"The load path of built in Emacs libraries.")
|
|
|
|
|
|
|
|
(defvar doom--package-load-path nil
|
|
|
|
"The load path of package libraries installed via ELPA or QUELPA.")
|
|
|
|
|
2017-02-11 06:00:08 -05:00
|
|
|
(defvar doom--base-load-path
|
|
|
|
(append (list doom-core-dir doom-modules-dir)
|
2017-03-05 13:32:12 -05:00
|
|
|
doom--site-load-path)
|
2017-02-11 06:00:08 -05:00
|
|
|
"A backup of `load-path' before it was altered by `doom-initialize'. Used as a
|
2017-03-05 13:32:12 -05:00
|
|
|
base by `doom!' and for calculating how many packages exist.")
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-03-20 23:01:02 -04:00
|
|
|
(setq load-prefer-newer noninteractive
|
2017-01-16 23:15:48 -05:00
|
|
|
package--init-file-ensured t
|
|
|
|
package-user-dir (expand-file-name "elpa" doom-packages-dir)
|
|
|
|
package-enable-at-startup nil
|
|
|
|
package-archives
|
|
|
|
'(("gnu" . "http://elpa.gnu.org/packages/")
|
|
|
|
("melpa" . "http://melpa.org/packages/")
|
|
|
|
("org" . "http://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
|
|
|
|
|
|
|
use-package-always-defer t
|
2017-01-28 02:02:16 -05:00
|
|
|
use-package-always-ensure nil
|
2017-03-01 19:16:49 -05:00
|
|
|
use-package-expand-minimally (not doom-debug-mode)
|
2017-02-02 21:54:47 -05:00
|
|
|
use-package-debug nil
|
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-02-19 06:59:55 -05:00
|
|
|
;; Don't use MELPA, we'll use package.el for those
|
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-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-02-06 01:23:24 -05:00
|
|
|
byte-compile-warnings '(not mapcar free-vars unresolved noruntime lexical make-local))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2017-01-31 04:31:14 -05:00
|
|
|
;; Bootstrap function
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
(defun doom-initialize (&optional force-p)
|
2017-02-02 04:37:59 -05:00
|
|
|
"Initialize installed packages (using package.el) and ensure the core packages
|
2017-02-13 04:49:53 -05:00
|
|
|
are installed. If you byte-compile core/core.el, this function will be avoided
|
2017-02-11 05:59:16 -05:00
|
|
|
to speed up startup."
|
2017-02-13 04:49:53 -05:00
|
|
|
;; Called early during initialization; only use native functions!
|
2017-03-05 15:50:05 -05:00
|
|
|
(when (or (not doom-init-p) force-p)
|
2017-02-28 18:19:23 -05:00
|
|
|
(unless noninteractive
|
|
|
|
(message "Doom initialized"))
|
2017-02-21 00:47:34 -05:00
|
|
|
|
2017-02-03 07:58:16 -05:00
|
|
|
(setq load-path doom--base-load-path
|
2017-01-31 04:31:14 -05:00
|
|
|
package-activated-list nil)
|
2017-02-11 05:59:16 -05:00
|
|
|
|
2017-02-20 12:00:45 -05:00
|
|
|
;; Ensure core folders exist
|
2017-03-16 23:38:22 -04:00
|
|
|
(dolist (dir (list doom-local-dir doom-etc-dir doom-cache-dir package-user-dir))
|
2017-02-20 09:47:27 -05:00
|
|
|
(unless (file-directory-p dir)
|
|
|
|
(make-directory dir t)))
|
2017-02-11 05:59:16 -05:00
|
|
|
|
2017-02-03 19:20:47 -05:00
|
|
|
(package-initialize t)
|
2017-02-20 09:47:27 -05:00
|
|
|
;; Sure, we could let `package-initialize' fill `load-path', but package
|
|
|
|
;; activation costs precious milliseconds and does other stuff I don't
|
|
|
|
;; really care about (like load autoload files). My premature optimization
|
|
|
|
;; quota isn't filled yet.
|
2017-02-13 04:49:53 -05:00
|
|
|
;;
|
|
|
|
;; Also, in some edge cases involving package initialization during a
|
|
|
|
;; non-interactive session, `package-initialize' fails to fill `load-path'.
|
2017-02-20 09:47:27 -05:00
|
|
|
;; If we want something done right, do it ourselves!
|
2017-03-05 13:32:12 -05:00
|
|
|
(setq doom--package-load-path (directory-files package-user-dir t "^\\w" t)
|
|
|
|
load-path (append load-path doom--package-load-path))
|
2017-02-06 00:13:24 -05:00
|
|
|
|
2017-02-09 04:25:32 -05:00
|
|
|
;; Ensure core packages are installed
|
2017-04-17 02:17:10 -04:00
|
|
|
(let ((core-packages (cl-remove-if #'package-installed-p doom-core-packages)))
|
2017-02-20 13:05:34 -05:00
|
|
|
(when core-packages
|
|
|
|
(package-refresh-contents)
|
|
|
|
(dolist (pkg core-packages)
|
|
|
|
(let ((inhibit-message t))
|
|
|
|
(package-install pkg))
|
|
|
|
(if (package-installed-p pkg)
|
|
|
|
(message "Installed %s" pkg)
|
|
|
|
(error "Couldn't install %s" pkg)))))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
2017-04-05 19:40:34 -04:00
|
|
|
(load "quelpa" nil t)
|
|
|
|
(load "use-package" nil t)
|
2017-03-19 22:51:54 -04:00
|
|
|
|
2017-02-03 07:58:16 -05:00
|
|
|
(setq doom-init-p t)))
|
|
|
|
|
2017-02-20 13:12:24 -05:00
|
|
|
(defun doom-initialize-autoloads (&optional inhibit-reload-p)
|
2017-02-20 09:47:27 -05:00
|
|
|
"Ensures that `doom-autoload-file' exists and is loaded. Otherwise run
|
2017-02-11 06:00:08 -05:00
|
|
|
`doom/reload-autoloads' to generate it."
|
2017-02-20 13:12:24 -05:00
|
|
|
(unless (file-exists-p doom-autoload-file)
|
2017-02-23 00:06:12 -05:00
|
|
|
(quiet! (doom/reload-autoloads))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-02-13 04:49:32 -05:00
|
|
|
(defun doom-initialize-packages (&optional force-p load-p)
|
2017-02-20 09:47:27 -05:00
|
|
|
"Crawls across your emacs.d in order to fill `doom-modules' (from init.el) and
|
|
|
|
`doom-packages' (from packages.el files), if they aren't set already. If FORCE-P
|
|
|
|
is non-nil, do it even if they are. Also aggressively loads all core autoload
|
|
|
|
files."
|
2017-02-11 00:46:42 -05:00
|
|
|
(doom-initialize force-p)
|
2017-02-13 04:49:32 -05:00
|
|
|
(let ((noninteractive t)
|
|
|
|
(load-fn
|
|
|
|
(lambda (file &optional noerror)
|
|
|
|
(condition-case ex
|
|
|
|
(load file noerror :nomessage :nosuffix)
|
|
|
|
('error (message "INIT-PACKAGES ERROR (%s): %s" file ex))))))
|
|
|
|
(when (or force-p (not doom-modules))
|
|
|
|
(setq doom-modules nil)
|
2017-02-19 06:59:55 -05:00
|
|
|
(funcall load-fn (expand-file-name "init.el" doom-emacs-dir))
|
2017-02-13 04:49:32 -05:00
|
|
|
(when load-p
|
|
|
|
(mapc (lambda (file) (funcall load-fn file t))
|
2017-03-01 19:15:45 -05:00
|
|
|
(append (nreverse (file-expand-wildcards (concat doom-core-dir "core*.el")))
|
2017-02-19 06:59:55 -05:00
|
|
|
(file-expand-wildcards (concat doom-core-dir "autoload/*.el"))
|
|
|
|
(doom--module-paths "config.el")))))
|
2017-02-13 04:49:32 -05:00
|
|
|
(when (or force-p (not doom-packages))
|
|
|
|
(setq doom-packages nil)
|
2017-02-19 06:59:55 -05:00
|
|
|
(funcall load-fn (expand-file-name "packages.el" doom-core-dir))
|
2017-02-13 04:49:32 -05:00
|
|
|
(mapc (lambda (file) (funcall load-fn file t))
|
2017-02-19 06:59:55 -05:00
|
|
|
(doom--module-paths "packages.el")))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-02-13 04:47:20 -05:00
|
|
|
(defun doom-initialize-modules (modules)
|
|
|
|
"Adds MODULES to `doom-modules'. MODULES must be in mplist format.
|
|
|
|
|
|
|
|
e.g '(:feature evil :lang emacs-lisp javascript java)"
|
|
|
|
(unless doom-modules
|
2017-04-17 02:17:10 -04:00
|
|
|
(setq doom-modules (make-hash-table :test #'equal :size (+ 5 (length modules)))))
|
2017-02-13 04:47:20 -05:00
|
|
|
(let (mode)
|
|
|
|
(dolist (m modules)
|
|
|
|
(cond ((keywordp m)
|
|
|
|
(setq mode m))
|
|
|
|
((not mode)
|
2017-02-23 00:06:12 -05:00
|
|
|
(error "No namespace specified on `doom!' for %s" m))
|
2017-02-13 04:47:20 -05:00
|
|
|
((eq m '*)
|
2017-02-19 06:59:55 -05:00
|
|
|
(doom-initialize-modules
|
|
|
|
(cons mode
|
|
|
|
(mapcar
|
|
|
|
(lambda (dir) (intern (file-name-nondirectory dir)))
|
|
|
|
(cl-remove-if-not
|
2017-04-17 02:17:10 -04:00
|
|
|
#'file-directory-p
|
2017-02-19 06:59:55 -05:00
|
|
|
(directory-files (expand-file-name
|
|
|
|
(substring (symbol-name mode) 1)
|
|
|
|
doom-modules-dir)
|
|
|
|
t "^\\w"))))))
|
2017-02-13 04:47:20 -05:00
|
|
|
(t
|
|
|
|
(doom--enable-module mode m))))))
|
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
(defun doom-module-path (module submodule &optional file)
|
|
|
|
"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."
|
|
|
|
(unless (keywordp module)
|
|
|
|
(error "Expected a keyword, got %s" module))
|
|
|
|
(unless (symbolp submodule)
|
|
|
|
(error "Expected a symbol, got %s" submodule))
|
|
|
|
(let ((module-name (substring (symbol-name module) 1))
|
|
|
|
(submodule-name (symbol-name submodule)))
|
2017-02-19 06:59:55 -05:00
|
|
|
(expand-file-name (concat module-name "/" submodule-name "/" file)
|
|
|
|
doom-modules-dir)))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-02-11 06:00:08 -05:00
|
|
|
(defun doom-module-loaded-p (module submodule)
|
2017-02-13 04:47:20 -05:00
|
|
|
"Returns t if MODULE->SUBMODULE is present in `doom-modules'."
|
2017-03-03 16:51:59 -05:00
|
|
|
(and doom-modules
|
|
|
|
(gethash (cons module submodule) doom-modules)))
|
2017-02-11 06:00:08 -05:00
|
|
|
|
|
|
|
(defun doom--module-pairs ()
|
2017-02-13 04:47:20 -05:00
|
|
|
"Returns `doom-modules' as a list of (MODULE . SUBMODULE) cons cells. The list
|
|
|
|
is sorted by order of insertion."
|
2017-02-20 13:27:56 -05:00
|
|
|
(let (pairs)
|
2017-03-25 01:03:02 -04:00
|
|
|
(when (hash-table-p doom-modules)
|
|
|
|
(maphash (lambda (key value) (push (cons (car key) (cdr key)) pairs))
|
|
|
|
doom-modules)
|
|
|
|
(nreverse pairs))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-02-19 06:59:55 -05:00
|
|
|
(defun doom--module-paths (&optional append-file)
|
|
|
|
"Returns a list of absolute file paths to modules, with APPEND-FILE added, if
|
|
|
|
the file exists."
|
|
|
|
(let (paths)
|
2017-03-01 19:15:45 -05:00
|
|
|
(dolist (pair (doom--module-pairs) (nreverse paths))
|
2017-02-19 06:59:55 -05:00
|
|
|
(let ((path (doom-module-path (car pair) (cdr pair) append-file)))
|
|
|
|
(when (file-exists-p path)
|
2017-03-01 19:15:45 -05:00
|
|
|
(push path paths))))))
|
2017-02-19 06:59:55 -05:00
|
|
|
|
2017-02-11 06:00:08 -05:00
|
|
|
(defun doom--enable-module (module submodule &optional force-p)
|
|
|
|
"Adds MODULE and SUBMODULE to `doom-modules', if it isn't already there (or if
|
|
|
|
FORCE-P is non-nil). MODULE is a keyword, SUBMODULE is a symbol. e.g. :lang
|
|
|
|
'emacs-lisp.
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
Used by `require!' and `depends-on!'."
|
2017-02-11 00:46:42 -05:00
|
|
|
(unless (or force-p (doom-module-loaded-p module submodule))
|
2017-02-13 04:47:20 -05:00
|
|
|
(puthash (cons module submodule) t doom-modules)))
|
2017-02-06 00:13:24 -05:00
|
|
|
|
2017-02-19 06:59:55 -05:00
|
|
|
(defun doom--display-benchmark ()
|
|
|
|
(message "Loaded %s packages in %.03fs"
|
2017-04-05 14:26:04 -04:00
|
|
|
;; 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.
|
|
|
|
(- (length load-path) (length doom--base-load-path))
|
2017-02-20 16:42:07 -05:00
|
|
|
(setq doom-init-time (float-time (time-subtract after-init-time before-init-time)))))
|
2017-02-19 06:59:55 -05:00
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Macros
|
|
|
|
;;
|
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)
|
2017-02-11 00:46:42 -05:00
|
|
|
"DOOM Emacs bootstrap macro. List the modules to load. Benefits from
|
|
|
|
byte-compilation."
|
2017-02-13 04:47:20 -05:00
|
|
|
(doom-initialize-modules modules)
|
2017-02-19 06:59:55 -05:00
|
|
|
`(let (file-name-handler-alist)
|
|
|
|
(setq doom-modules ',doom-modules)
|
2017-02-11 06:00:08 -05:00
|
|
|
|
2017-02-19 06:59:55 -05:00
|
|
|
(unless noninteractive
|
2017-03-01 19:15:45 -05:00
|
|
|
,@(let (forms)
|
|
|
|
(dolist (module (doom--module-pairs) (nreverse forms))
|
|
|
|
(push `(require! ,(car module) ,(cdr module) t) forms)))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
|
|
|
(when (display-graphic-p)
|
|
|
|
(require 'server)
|
|
|
|
(unless (server-running-p)
|
|
|
|
(server-start)))
|
|
|
|
|
|
|
|
;; Benchmark
|
2017-04-17 02:17:10 -04:00
|
|
|
(add-hook 'after-init-hook #'doom--display-benchmark t))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-03-19 22:47:50 -04:00
|
|
|
(defalias 'def-package! 'use-package
|
|
|
|
"An alias for `use-package'. Note that packages are deferred by default.")
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro load! (filesym &optional path noerror)
|
2017-02-11 06:00:08 -05:00
|
|
|
"Loads a file relative to the current module (or PATH). FILESYM is a file path
|
|
|
|
as a symbol. PATH is a directory to prefix it with. If NOERROR is non-nil, don't
|
2017-02-19 06:59:55 -05:00
|
|
|
throw an error if the file doesn't exist."
|
|
|
|
(let ((path (or (and path
|
|
|
|
(cond ((symbolp path) (symbol-value path))
|
|
|
|
((stringp path) path)
|
|
|
|
((listp path) (eval path))))
|
|
|
|
(and load-file-name (file-name-directory load-file-name))
|
|
|
|
(and buffer-file-name (file-name-directory buffer-file-name))
|
|
|
|
(and (bound-and-true-p byte-compile-current-file)
|
|
|
|
(file-name-directory byte-compile-current-file)))))
|
2017-02-11 00:46:42 -05:00
|
|
|
(unless path
|
|
|
|
(error "Could not find %s" filesym))
|
2017-02-19 06:59:55 -05:00
|
|
|
(let ((file (expand-file-name (concat (symbol-name filesym) ".el") path)))
|
|
|
|
(if (file-exists-p file)
|
|
|
|
`(load ,(file-name-sans-extension file) ,noerror (not doom-debug-mode))
|
2017-02-11 06:00:08 -05:00
|
|
|
(unless noerror
|
2017-02-23 00:06:12 -05:00
|
|
|
(error "Could not load! file %s" file))))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro require! (module submodule &optional reload-p)
|
2017-02-11 06:00:08 -05:00
|
|
|
"Like `require', but for doom modules. Will load a module's config.el file if
|
|
|
|
it hasn't already, and if it exists."
|
2017-02-19 06:59:55 -05:00
|
|
|
(when (or (not noninteractive)
|
2017-03-20 15:57:41 -04:00
|
|
|
(bound-and-true-p byte-compile-current-file)
|
|
|
|
reload-p)
|
2017-02-11 00:46:42 -05:00
|
|
|
(let ((loaded-p (doom-module-loaded-p module submodule)))
|
|
|
|
(when (or reload-p (not loaded-p))
|
|
|
|
(unless loaded-p
|
2017-02-11 06:00:08 -05:00
|
|
|
(doom--enable-module module submodule t))
|
2017-02-23 00:06:12 -05:00
|
|
|
`(load! config ,(doom-module-path module submodule) t)))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro featurep! (module submodule)
|
2017-02-11 06:52:38 -05:00
|
|
|
"Convenience macro that wraps `doom-module-loaded-p'."
|
|
|
|
`(doom-module-loaded-p ,module ',submodule))
|
|
|
|
|
2017-02-06 00:13:24 -05:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
;;
|
|
|
|
;; Declarative macros
|
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro package! (name &rest plist)
|
2017-02-13 04:49:53 -05:00
|
|
|
"Declares a package and how to install it (if applicable). This does not load
|
|
|
|
nor install them.
|
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
|
|
|
|
2017-02-13 04:49:53 -05:00
|
|
|
:recipe RECIPE Takes a MELPA-style recipe (see `quelpa-recipe' in
|
|
|
|
`quelpa' for an example); for packages to be installed
|
|
|
|
from external sources.
|
2017-02-03 20:10:40 -05:00
|
|
|
:pin ARCHIVE-NAME Instructs ELPA to only look for this package in
|
2017-02-13 04:49:53 -05:00
|
|
|
ARCHIVE-NAME. e.g. \"org\". Ignored if RECIPE is present.
|
|
|
|
|
|
|
|
This macro serves a purely declarative purpose, and are used to fill
|
|
|
|
`doom-packages', so that functions like `doom/packages-install' can operate on
|
2017-02-19 19:00:58 -05:00
|
|
|
them."
|
2017-01-16 23:15:48 -05:00
|
|
|
(declare (indent defun))
|
2017-02-19 19:00:58 -05:00
|
|
|
(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)))))
|
2017-02-20 01:13:21 -05:00
|
|
|
(when pkg-recipe
|
2017-03-01 19:15:45 -05:00
|
|
|
(when (= 0 (% (length pkg-recipe) 2))
|
2017-02-20 01:13:21 -05:00
|
|
|
(plist-put plist :recipe (cons name pkg-recipe)))
|
|
|
|
(when pkg-pin
|
|
|
|
(plist-put plist :pin nil)))
|
2017-02-19 19:00:58 -05:00
|
|
|
`(progn
|
|
|
|
(when ,(and pkg-pin t)
|
2017-03-05 14:18:35 -05:00
|
|
|
(cl-pushnew (cons ',name ,pkg-pin) package-pinned-packages :test 'eq :key 'car))
|
2017-02-19 19:00:58 -05:00
|
|
|
(when ,(and old-plist t)
|
|
|
|
(assq-delete-all ',name doom-packages))
|
|
|
|
(push ',(cons name plist) doom-packages))))
|
2017-01-28 02:02:16 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro depends-on! (module submodule)
|
2017-02-11 00:46:42 -05:00
|
|
|
"Declares that this module depends on another. MODULE is a keyword, and
|
|
|
|
SUBMODULE is a symbol."
|
2017-02-11 06:52:29 -05:00
|
|
|
(doom--enable-module module submodule)
|
2017-02-23 00:06:12 -05:00
|
|
|
`(load! packages ,(doom-module-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-04-12 08:52:57 -04:00
|
|
|
(defun doom/reload (&optional ignorable-p)
|
2017-03-25 18:46:27 -04:00
|
|
|
"Reload `load-path' and recompile files (if necessary). Useful if you
|
|
|
|
modify/update packages outside of emacs. Automatically called (through the
|
|
|
|
server, if necessary) by `doom/packages-install', `doom/packages-update' and
|
|
|
|
`doom/packages-autoremove'. "
|
2017-03-05 16:10:01 -05:00
|
|
|
(interactive)
|
2017-03-25 01:03:40 -04:00
|
|
|
(if noninteractive
|
2017-03-30 15:15:26 -04:00
|
|
|
(progn
|
|
|
|
(message "Reloading...")
|
2017-03-25 01:44:02 -04:00
|
|
|
(require 'server)
|
2017-04-12 08:52:57 -04:00
|
|
|
(unless (ignore-errors (server-eval-at "server" '(doom/reload t)))
|
2017-03-30 15:15:26 -04:00
|
|
|
(message "Recompiling")
|
|
|
|
(doom/recompile)))
|
2017-04-12 08:52:57 -04:00
|
|
|
(if (and ignorable-p doom-inhibit-reload)
|
|
|
|
(message "Ignored a reload request from server")
|
|
|
|
(doom-initialize t)
|
|
|
|
(doom/recompile)
|
|
|
|
(message "Reloaded %d packages" (length doom--package-load-path))
|
|
|
|
(run-with-timer 1 nil 'redraw-frame))))
|
2017-03-05 16:10:01 -05:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
(defun doom/reload-autoloads ()
|
2017-02-02 04:37:59 -05:00
|
|
|
"Refreshes the autoloads.el file, which tells Emacs where to find all the
|
2017-02-13 04:49:53 -05:00
|
|
|
autoloaded functions in enabled modules or among the core libraries, e.g.
|
2017-02-06 00:12:44 -05:00
|
|
|
core/autoload/*.el.
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-06 00:12:44 -05:00
|
|
|
In modules, checks modules/*/autoload.el and modules/*/autoload/*.el.
|
2017-02-03 19:20:47 -05:00
|
|
|
|
2017-02-06 00:12:44 -05:00
|
|
|
Rerun this whenever init.el is modified. You can also use `make autoloads` from
|
|
|
|
the commandline."
|
2017-01-16 23:15:48 -05:00
|
|
|
(interactive)
|
2017-02-20 13:12:24 -05:00
|
|
|
(doom-initialize-packages (not noninteractive))
|
2017-02-06 00:12:44 -05:00
|
|
|
(let ((generated-autoload-file doom-autoload-file)
|
2017-02-13 04:50:04 -05:00
|
|
|
(autoload-files
|
2017-02-19 06:59:55 -05:00
|
|
|
(file-expand-wildcards
|
|
|
|
(expand-file-name "autoload/*.el" doom-core-dir))))
|
|
|
|
(dolist (path (doom--module-paths))
|
|
|
|
(let ((auto-dir (expand-file-name "autoload" path))
|
|
|
|
(auto-file (expand-file-name "autoload.el" path)))
|
|
|
|
(when (file-exists-p auto-file)
|
|
|
|
(push auto-file autoload-files))
|
|
|
|
(when (file-directory-p auto-dir)
|
|
|
|
(mapc (lambda (file)
|
|
|
|
;; Make evil.el autoload files a special case; don't load them
|
|
|
|
;; unless evil is enabled.
|
|
|
|
(unless (and (equal (file-name-nondirectory file) "evil.el")
|
2017-02-23 00:06:12 -05:00
|
|
|
(not (featurep! :feature evil)))
|
2017-02-19 06:59:55 -05:00
|
|
|
(push file autoload-files)))
|
|
|
|
(file-expand-wildcards (expand-file-name "*.el" auto-dir) t)))))
|
|
|
|
(when (file-exists-p generated-autoload-file)
|
|
|
|
(delete-file generated-autoload-file)
|
2017-02-04 21:07:54 -05:00
|
|
|
(message "Deleted old autoloads.el"))
|
2017-03-01 19:15:45 -05:00
|
|
|
(dolist (file (nreverse autoload-files))
|
2017-02-13 04:50:04 -05:00
|
|
|
(let ((inhibit-message t))
|
|
|
|
(update-file-autoloads file))
|
2017-02-19 06:59:55 -05:00
|
|
|
(message "Scanned %s" (file-relative-name file doom-emacs-dir)))
|
2017-02-11 00:46:42 -05:00
|
|
|
(condition-case ex
|
2017-02-20 13:12:24 -05:00
|
|
|
(let ((buf (get-file-buffer generated-autoload-file)))
|
|
|
|
(unwind-protect
|
|
|
|
(with-current-buffer buf
|
|
|
|
(save-buffer)
|
|
|
|
(eval-buffer)
|
|
|
|
(message "Finished generating autoloads.el!"))
|
|
|
|
(kill-buffer buf)))
|
|
|
|
('error
|
|
|
|
(delete-file generated-autoload-file)
|
|
|
|
(error "Couldn't evaluate autoloads.el: %s" (cadr ex))))))
|
|
|
|
|
2017-04-06 19:43:56 -04:00
|
|
|
(defun doom/compile (&optional lite-p only-recompile-p)
|
2017-03-25 01:03:02 -04:00
|
|
|
"Byte compile your emacs configuration (init.el, core/*.el &
|
|
|
|
modules/*/*/**.el). DOOM Emacs was designed to benefit from this, but it may
|
2017-04-06 19:43:56 -04:00
|
|
|
take a while.
|
|
|
|
|
|
|
|
If LITE-P is non-nil, only compile the essential, core DOOM files (init.el &
|
|
|
|
core/**/*.el).
|
|
|
|
|
|
|
|
If ONLY-RECOMPILE-P is non-nil, only recompile out-of-date files."
|
|
|
|
(interactive "P")
|
|
|
|
;; Ensure all relevant config files are loaded and up-to-date. This way we
|
|
|
|
;; don't need eval-when-compile and require blocks scattered all over.
|
2017-03-31 23:45:35 -04:00
|
|
|
(doom-initialize-packages t t)
|
2017-04-12 08:53:27 -04:00
|
|
|
(let ((targets (append (list "init.el" doom-core-dir)
|
|
|
|
(unless lite-p (doom--module-paths))))
|
|
|
|
(total-success 0)
|
|
|
|
(total-fail 0)
|
|
|
|
(total-nocomp 0)
|
|
|
|
el-files)
|
|
|
|
(mapc (lambda (file)
|
|
|
|
(when (or (not only-recompile-p)
|
|
|
|
(let ((elc-file (byte-compile-dest-file file)))
|
|
|
|
(and (file-exists-p elc-file)
|
|
|
|
(file-newer-than-file-p file elc-file))))
|
|
|
|
(let ((result (quiet! (byte-compile-file file)))
|
|
|
|
(short-name (file-relative-name file doom-emacs-dir)))
|
|
|
|
(cl-incf
|
|
|
|
(cond ((eq result 'no-byte-compile)
|
2017-04-15 01:29:24 -04:00
|
|
|
(message! (dark (white "Ignored %s" short-name)))
|
2017-04-12 08:53:27 -04:00
|
|
|
total-nocomp)
|
|
|
|
((null result)
|
2017-04-15 01:29:24 -04:00
|
|
|
(message! (red "Failed to compile %s" short-name))
|
2017-04-12 08:53:27 -04:00
|
|
|
total-fail)
|
|
|
|
(t
|
2017-04-15 01:29:24 -04:00
|
|
|
(message! (green "Compiled %s" short-name))
|
2017-04-12 08:53:27 -04:00
|
|
|
total-success))))))
|
|
|
|
(dolist (path targets (reverse el-files))
|
|
|
|
(let ((path (expand-file-name path doom-emacs-dir)))
|
|
|
|
(cond ((file-directory-p path)
|
|
|
|
(setq el-files (append (directory-files-recursively path "\\.el$") el-files)))
|
|
|
|
((file-exists-p path)
|
|
|
|
(push path el-files))
|
|
|
|
(t
|
|
|
|
(error "Invalid path: %s" path))))))
|
2017-04-15 01:29:24 -04:00
|
|
|
(message!
|
2017-04-12 08:53:27 -04:00
|
|
|
(bold
|
2017-04-12 21:41:27 -04:00
|
|
|
(color (if (zerop total-fail) 'green 'red)
|
2017-04-16 11:54:22 -04:00
|
|
|
"%s %s file(s) %s"
|
2017-04-12 21:41:27 -04:00
|
|
|
(if only-recompile-p "Recompiled" "Compiled")
|
|
|
|
(format (if el-files "%d/%d" "%d")
|
|
|
|
total-success
|
|
|
|
(- (length el-files) total-nocomp))
|
|
|
|
(format "(%s not compiled)" total-nocomp))))))
|
2017-03-25 01:03:02 -04:00
|
|
|
|
2017-03-28 15:53:47 -04:00
|
|
|
(defun doom/recompile ()
|
|
|
|
"Recompile any compiled *.el files in your Emacs configuration."
|
|
|
|
(interactive)
|
2017-04-08 23:27:39 -04:00
|
|
|
(doom/compile nil :recompile)
|
|
|
|
;; In case `load-path' has changed (e.g. after an update)
|
|
|
|
(byte-recompile-file (expand-file-name "core.el" doom-core-dir) t))
|
2017-03-28 15:53:47 -04:00
|
|
|
|
2017-03-27 23:22:53 -04:00
|
|
|
(defun doom/compile-lite ()
|
2017-03-25 01:06:40 -04:00
|
|
|
"A light-weight version of `doom/compile' which only compiles core files in
|
|
|
|
your emacs configuration (init.el and core/**/*.el)."
|
2017-03-25 01:03:02 -04:00
|
|
|
(interactive)
|
2017-03-27 23:22:53 -04:00
|
|
|
(doom/compile t))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-03-19 23:48:43 -04:00
|
|
|
(defun doom/clean-cache ()
|
2017-03-16 23:38:22 -04:00
|
|
|
"Clear local cache (`doom-cache-dir'). You may need to restart Emacs for some
|
|
|
|
components to feel its effects."
|
|
|
|
(delete-directory doom-cache-dir t)
|
|
|
|
(make-directory doom-cache-dir t))
|
|
|
|
|
2017-03-19 23:48:43 -04:00
|
|
|
(defun doom/clean-compiled ()
|
2017-03-16 23:38:22 -04:00
|
|
|
"Delete all compiled elc files in DOOM emacs, excluding compiled ELPA/QUELPA
|
|
|
|
package files."
|
|
|
|
(interactive)
|
|
|
|
(when-let (elc-files (cl-remove-if (lambda (file) (file-in-directory-p file doom-local-dir))
|
|
|
|
(directory-files-recursively doom-emacs-dir "\\.elc$")))
|
|
|
|
(dolist (file elc-files)
|
|
|
|
(delete-file file)
|
2017-04-12 08:53:27 -04:00
|
|
|
(message "Deleting %s" (file-relative-name file doom-emacs-dir)))))
|
2017-03-16 23:38:22 -04:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Package.el modifications
|
|
|
|
;;
|
|
|
|
|
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
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(provide 'core-packages)
|
|
|
|
;;; core-packages.el ends here
|