2017-06-08 11:47:56 +02:00
|
|
|
;;; core/autoload/packages.el -*- lexical-binding: t; -*-
|
2017-02-02 19:15:58 -05:00
|
|
|
|
2018-05-27 12:44:22 +02:00
|
|
|
(load! "cache")
|
2017-04-04 12:29:34 -04:00
|
|
|
|
2018-03-14 18:25:22 -04:00
|
|
|
;;; Private functions
|
|
|
|
(defun doom--packages-choose (prompt)
|
|
|
|
(let ((table (cl-loop for pkg in package-alist
|
|
|
|
unless (package-built-in-p (cdr pkg))
|
|
|
|
collect (cons (package-desc-full-name (cdr pkg))
|
|
|
|
(cdr pkg)))))
|
|
|
|
(cdr (assoc (completing-read prompt
|
|
|
|
(mapcar #'car table)
|
|
|
|
nil t)
|
|
|
|
table))))
|
|
|
|
|
|
|
|
(defmacro doom--condition-case! (&rest body)
|
2018-06-24 20:11:57 +02:00
|
|
|
`(condition-case-unless-debug e
|
2018-06-07 17:59:23 +02:00
|
|
|
(progn ,@body)
|
2018-03-14 18:25:22 -04:00
|
|
|
('user-error
|
2018-09-07 21:56:07 -04:00
|
|
|
(print! (bold (red " NOTICE: %s")) e))
|
2018-06-07 17:59:23 +02:00
|
|
|
('file-error
|
2018-09-07 21:56:07 -04:00
|
|
|
(print! (bold (red " FILE ERROR: %s")) (error-message-string e))
|
2018-06-07 17:59:23 +02:00
|
|
|
(print! " Trying again...")
|
|
|
|
(quiet! (doom-refresh-packages-maybe t))
|
2018-06-24 20:11:57 +02:00
|
|
|
,@body)
|
|
|
|
('error
|
2018-09-07 21:56:07 -04:00
|
|
|
(print! (bold (red " FATAL ERROR: %s\n Run again with the -d flag for details")) e))))
|
2018-03-14 18:25:22 -04:00
|
|
|
|
|
|
|
(defun doom--refresh-pkg-cache ()
|
|
|
|
"Clear the cache for `doom-refresh-packages-maybe'."
|
|
|
|
(setq doom--refreshed-p nil)
|
|
|
|
(doom-cache-set 'last-pkg-refresh nil))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Library
|
|
|
|
|
2017-02-03 07:58:16 -05:00
|
|
|
;;;###autoload
|
2018-03-14 18:25:22 -04:00
|
|
|
(defun doom-refresh-packages-maybe (&optional force-p)
|
|
|
|
"Refresh ELPA packages, if it hasn't been refreshed recently."
|
2017-05-27 18:29:32 +02:00
|
|
|
(when force-p
|
2018-03-14 18:25:22 -04:00
|
|
|
(doom--refresh-pkg-cache))
|
2018-01-06 17:00:14 -05:00
|
|
|
(unless (or (doom-cache-get 'last-pkg-refresh)
|
2017-11-08 22:49:11 +01:00
|
|
|
doom--refreshed-p)
|
2018-06-20 02:23:55 +02:00
|
|
|
(condition-case e
|
2017-05-19 22:29:47 +02:00
|
|
|
(progn
|
2017-05-27 18:29:32 +02:00
|
|
|
(message "Refreshing package archives")
|
2018-06-20 12:45:03 +02:00
|
|
|
(package-refresh-contents)
|
2018-05-24 16:41:14 +02:00
|
|
|
(doom-cache-set 'last-pkg-refresh t 1200))
|
2018-06-20 02:23:55 +02:00
|
|
|
((debug error)
|
2018-03-14 18:25:22 -04:00
|
|
|
(doom--refresh-pkg-cache)
|
2018-06-20 02:23:55 +02:00
|
|
|
(signal 'doom-error e)))))
|
2017-05-19 22:29:47 +02:00
|
|
|
|
2017-02-03 07:58:16 -05:00
|
|
|
;;;###autoload
|
2017-11-05 16:04:31 +01:00
|
|
|
(defun doom-package-backend (name &optional noerror)
|
|
|
|
"Get which backend the package NAME was installed with. Can either be elpa or
|
|
|
|
quelpa. Throws an error if NOERROR is nil and the package isn't installed."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
2018-06-11 23:21:56 +02:00
|
|
|
(cond ((assq name quelpa-cache) 'quelpa)
|
|
|
|
((assq name package-alist) 'elpa)
|
|
|
|
((package-built-in-p name) 'emacs)
|
|
|
|
((not noerror) (error "%s package is not installed" name))))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-package-outdated-p (name)
|
|
|
|
"Determine whether NAME (a symbol) is outdated or not. If outdated, returns a
|
|
|
|
list, whose car is NAME, and cdr the current version list and latest version
|
|
|
|
list of the package."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
2017-12-10 14:49:52 -05:00
|
|
|
(when-let* ((desc (cadr (assq name package-alist))))
|
2017-08-06 16:30:53 +02:00
|
|
|
(let* ((old-version (package-desc-version desc))
|
2017-02-11 00:46:42 -05:00
|
|
|
(new-version
|
|
|
|
(pcase (doom-package-backend name)
|
|
|
|
('quelpa
|
2017-06-02 22:28:14 +02:00
|
|
|
(let ((recipe (plist-get (cdr (assq name doom-packages)) :recipe))
|
2017-02-19 06:59:55 -05:00
|
|
|
(dir (expand-file-name (symbol-name name) quelpa-build-dir))
|
2017-06-03 21:29:33 +02:00
|
|
|
(inhibit-message (not doom-debug-mode))
|
|
|
|
(quelpa-upgrade-p t))
|
2017-12-10 14:49:52 -05:00
|
|
|
(if-let* ((ver (quelpa-checkout recipe dir)))
|
2017-02-11 00:46:42 -05:00
|
|
|
(version-to-list ver)
|
|
|
|
old-version)))
|
|
|
|
('elpa
|
|
|
|
(let ((desc (cadr (assq name package-archive-contents))))
|
|
|
|
(when (package-desc-p desc)
|
|
|
|
(package-desc-version desc)))))))
|
2018-04-05 02:28:42 -04:00
|
|
|
(unless (and (listp old-version) (listp new-version))
|
|
|
|
(error "Couldn't get version for %s" name))
|
|
|
|
(when (version-list-< old-version new-version)
|
2017-02-11 00:46:42 -05:00
|
|
|
(list name old-version new-version)))))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
2018-09-07 21:52:11 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom-package-installed-p (name)
|
|
|
|
"TODO"
|
|
|
|
(and (package-installed-p name)
|
|
|
|
(when-let* ((desc (cadr (assq name package-alist))))
|
|
|
|
(let ((dir (package-desc-dir desc)))
|
|
|
|
(file-directory-p dir)))))
|
|
|
|
|
2017-06-05 14:21:07 +02:00
|
|
|
;;;###autoload
|
2018-06-24 19:58:25 +02:00
|
|
|
(defun doom-package-prop (name prop &optional eval)
|
2017-06-14 12:35:31 +02:00
|
|
|
"Return PROPerty in NAME's plist."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
|
|
|
(cl-check-type prop keyword)
|
2018-06-24 19:58:25 +02:00
|
|
|
(let ((value (plist-get (cdr (assq name doom-packages)) prop)))
|
|
|
|
(if eval (eval value) value)))
|
2017-06-05 14:21:07 +02:00
|
|
|
|
2017-11-05 16:04:31 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom-package-different-backend-p (name)
|
2018-02-20 17:18:07 -05:00
|
|
|
"Return t if a package named NAME (a symbol) has a new backend than what it
|
|
|
|
was installed with. Returns nil otherwise, or if package isn't installed."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
|
|
|
(doom-initialize-packages)
|
2017-11-05 16:04:31 +01:00
|
|
|
(and (package-installed-p name)
|
|
|
|
(let* ((plist (cdr (assq name doom-packages)))
|
2017-12-22 15:25:02 -05:00
|
|
|
(old-backend (doom-package-backend name 'noerror))
|
2017-11-05 16:04:31 +01:00
|
|
|
(new-backend (if (plist-get plist :recipe) 'quelpa 'elpa)))
|
|
|
|
(not (eq old-backend new-backend)))))
|
|
|
|
|
2018-02-20 17:55:53 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom-package-different-recipe-p (name)
|
|
|
|
"Return t if a package named NAME (a symbol) has a different recipe than it
|
|
|
|
was installed with."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
2018-06-11 23:21:56 +02:00
|
|
|
(doom-initialize-packages)
|
|
|
|
(and (package-installed-p name)
|
|
|
|
(when-let* ((quelpa-recipe (assq name quelpa-cache))
|
|
|
|
(doom-recipe (assq name doom-packages)))
|
|
|
|
(not (equal (cdr quelpa-recipe)
|
|
|
|
(cdr (plist-get (cdr doom-recipe) :recipe)))))))
|
2018-02-20 17:55:53 -05:00
|
|
|
|
2017-02-03 07:58:16 -05:00
|
|
|
;;;###autoload
|
2018-06-11 23:21:56 +02:00
|
|
|
(cl-defun doom-get-packages (&key (installed 'any)
|
|
|
|
(private 'any)
|
|
|
|
(disabled 'any)
|
|
|
|
(pinned 'any)
|
|
|
|
(ignored 'any)
|
|
|
|
(sort t)
|
|
|
|
changed
|
2018-09-07 21:52:11 -04:00
|
|
|
backend
|
|
|
|
deps)
|
2018-06-10 17:07:23 +02:00
|
|
|
"Retrieves a list of primary packages (i.e. non-dependencies). Each element is
|
|
|
|
a cons cell, whose car is the package symbol and whose cdr is the quelpa recipe
|
|
|
|
(if any).
|
2017-02-03 07:58:16 -05:00
|
|
|
|
2018-06-11 23:21:56 +02:00
|
|
|
You can build a filtering criteria using one or more of the following
|
|
|
|
properties:
|
|
|
|
|
|
|
|
:backend BACKEND
|
|
|
|
Can be 'quelpa, 'elpa or 'emacs
|
|
|
|
:installed BOOL
|
|
|
|
Only return installed packages (t) or uninstalled packages (nil)
|
|
|
|
:private BOOL
|
|
|
|
Only return private packages (t) or non-private packages (nil)
|
|
|
|
:disabled BOOL
|
|
|
|
Only return packages that are disabled (t) or otherwise (nil)
|
|
|
|
:ignored BOOL
|
|
|
|
Only return packages that are ignored (t) or otherwise (nil)
|
|
|
|
:pinned BOOL|ARCHIVE
|
|
|
|
Only return packages that are pinned (t), not pinned (nil) or pinned to a
|
|
|
|
specific archive (stringp)
|
2018-09-07 21:52:11 -04:00
|
|
|
:deps BOOL
|
|
|
|
Includes the package's dependencies (t).
|
2018-06-11 23:21:56 +02:00
|
|
|
|
|
|
|
The resulting list is sorted unless :sort nil is passed to this function.
|
2018-06-10 17:07:23 +02:00
|
|
|
|
|
|
|
Warning: this function is expensive, as it re-evaluates your all packages.el
|
|
|
|
files."
|
2018-06-11 23:21:56 +02:00
|
|
|
(doom-initialize-packages)
|
2018-09-07 21:52:11 -04:00
|
|
|
(cl-remove-duplicates
|
|
|
|
(cl-loop with packages = (append (mapcar #'list doom-core-packages)
|
|
|
|
doom-packages)
|
|
|
|
for (sym . plist)
|
|
|
|
in (if sort
|
|
|
|
(cl-sort (copy-sequence packages) #'string-lessp :key #'car)
|
|
|
|
packages)
|
|
|
|
if (and (or (not backend)
|
|
|
|
(eq (doom-package-backend sym t) backend))
|
|
|
|
(or (eq ignored 'any)
|
|
|
|
(let* ((form (plist-get plist :ignore))
|
|
|
|
(value (eval form)))
|
|
|
|
(if ignored value (not value))))
|
|
|
|
(or (eq disabled 'any)
|
|
|
|
(if disabled
|
|
|
|
(plist-get plist :disable)
|
|
|
|
(not (plist-get plist :disable))))
|
|
|
|
(or (eq installed 'any)
|
|
|
|
(if installed
|
|
|
|
(doom-package-installed-p sym)
|
|
|
|
(not (doom-package-installed-p sym))))
|
|
|
|
(or (eq private 'any)
|
|
|
|
(if private
|
|
|
|
(plist-get plist :private)
|
|
|
|
(not (plist-get plist :private))))
|
|
|
|
(or (eq pinned 'any)
|
|
|
|
(cond ((eq pinned 't)
|
|
|
|
(plist-get plist :pin))
|
|
|
|
((null pinned)
|
|
|
|
(not (plist-get plist :pin)))
|
|
|
|
((equal (plist-get plist :pin) pinned)))))
|
|
|
|
collect (cons sym plist)
|
|
|
|
and if (and deps (not (package-built-in-p sym)))
|
|
|
|
nconc
|
|
|
|
(cl-loop for pkg in (doom-get-dependencies-for sym 'recursive 'noerror)
|
|
|
|
if (or (eq installed 'any)
|
|
|
|
(if installed
|
|
|
|
(doom-package-installed-p pkg)
|
|
|
|
(not (doom-package-installed-p pkg))))
|
|
|
|
collect (cons pkg (cdr (assq pkg doom-packages)))))
|
|
|
|
:key #'car))
|
2017-02-19 06:59:55 -05:00
|
|
|
|
2018-06-14 00:04:12 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom-get-package-alist ()
|
|
|
|
"Returns a list of all desired packages, their dependencies and their desc
|
|
|
|
objects, in the order of their `package! blocks.'"
|
|
|
|
(doom-initialize-packages)
|
|
|
|
(cl-remove-duplicates
|
2018-09-25 10:31:52 -04:00
|
|
|
(cl-loop for name in (append doom-core-packages (mapcar #'car doom-packages))
|
|
|
|
if (assq name package-alist)
|
|
|
|
nconc (cl-loop for dep in (package--get-deps name)
|
|
|
|
if (assq dep package-alist)
|
|
|
|
collect (cons dep (cadr it)))
|
|
|
|
and collect (cons name (cadr it)))
|
2018-06-14 00:04:12 +02:00
|
|
|
:key #'car
|
|
|
|
:from-end t))
|
|
|
|
|
2017-02-19 06:59:55 -05:00
|
|
|
;;;###autoload
|
2018-09-07 21:52:11 -04:00
|
|
|
(defun doom-get-depending-on (name &optional noerror)
|
2017-02-19 06:59:55 -05:00
|
|
|
"Return a list of packages that depend on the package named NAME."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
2018-09-07 21:52:11 -04:00
|
|
|
(unless (package-built-in-p name)
|
|
|
|
(if-let* ((desc (cadr (assq name package-alist))))
|
|
|
|
(mapcar #'package-desc-name (package--used-elsewhere-p desc nil t))
|
|
|
|
(unless noerror
|
|
|
|
(error "Couldn't find %s, is it installed?" name)))))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
2017-04-04 22:17:33 -04:00
|
|
|
;;;###autoload
|
2018-09-07 21:52:11 -04:00
|
|
|
(defun doom-get-dependencies-for (name &optional recursive noerror)
|
2017-04-04 22:17:33 -04:00
|
|
|
"Return a list of dependencies for a package."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
2018-09-07 21:52:11 -04:00
|
|
|
;; can't get dependencies for built-in packages
|
|
|
|
(unless (package-built-in-p name)
|
|
|
|
(if-let* ((desc (cadr (assq name package-alist))))
|
|
|
|
(let* ((deps (mapcar #'car (package-desc-reqs desc)))
|
|
|
|
(deps (cl-remove-if #'package-built-in-p deps)))
|
|
|
|
(if recursive
|
|
|
|
(nconc deps (mapcan (lambda (dep) (doom-get-dependencies-for dep t t))
|
|
|
|
deps))
|
|
|
|
deps))
|
|
|
|
(unless noerror
|
|
|
|
(error "Couldn't find %s, is it installed?" name)))))
|
2017-04-04 22:17:33 -04:00
|
|
|
|
2017-02-03 07:58:16 -05:00
|
|
|
;;;###autoload
|
2017-06-05 14:21:07 +02:00
|
|
|
(defun doom-get-outdated-packages (&optional include-frozen-p)
|
2017-02-11 00:46:42 -05:00
|
|
|
"Return a list of packages that are out of date. Each element is a list,
|
|
|
|
containing (PACKAGE-SYMBOL OLD-VERSION-LIST NEW-VERSION-LIST).
|
2017-02-09 04:25:32 -05:00
|
|
|
|
2017-06-05 14:21:07 +02:00
|
|
|
If INCLUDE-FROZEN-P is non-nil, check frozen packages as well.
|
|
|
|
|
2018-06-17 21:35:58 +02:00
|
|
|
Used by `doom-packages-update'."
|
2018-05-25 02:53:48 +02:00
|
|
|
(doom-initialize-packages t)
|
|
|
|
(doom-refresh-packages-maybe doom-debug-mode)
|
2018-01-06 17:02:57 -05:00
|
|
|
(require 'async)
|
2017-06-21 16:09:58 +02:00
|
|
|
(let (quelpa-pkgs elpa-pkgs)
|
2017-06-24 02:07:53 +02:00
|
|
|
;; Separate quelpa from elpa packages
|
2018-02-11 16:13:15 -05:00
|
|
|
(dolist (pkg (mapcar #'car package-alist))
|
2018-06-24 19:58:25 +02:00
|
|
|
(when (and (or (not (doom-package-prop pkg :freeze 'eval))
|
2018-02-11 16:13:15 -05:00
|
|
|
include-frozen-p)
|
2018-06-24 19:58:25 +02:00
|
|
|
(not (doom-package-prop pkg :ignore 'eval))
|
2018-02-11 16:13:15 -05:00
|
|
|
(not (doom-package-different-backend-p pkg)))
|
|
|
|
(push pkg
|
|
|
|
(if (eq (doom-package-backend pkg) 'quelpa)
|
|
|
|
quelpa-pkgs
|
|
|
|
elpa-pkgs))))
|
2017-11-05 00:57:26 +01:00
|
|
|
;; The bottleneck in this process is quelpa's version checks, so check them
|
|
|
|
;; asynchronously.
|
|
|
|
(let (futures)
|
|
|
|
(dolist (pkg quelpa-pkgs)
|
2018-03-24 04:38:05 -04:00
|
|
|
(when doom-debug-mode
|
|
|
|
(message "New thread for: %s" pkg))
|
2017-06-21 16:09:58 +02:00
|
|
|
(push (async-start
|
|
|
|
`(lambda ()
|
2018-09-07 21:53:30 -04:00
|
|
|
(let ((gc-cons-threshold ,doom-gc-cons-upper-limit)
|
|
|
|
(doom-init-p t)
|
2018-05-18 01:08:25 +02:00
|
|
|
(noninteractive t)
|
|
|
|
(load-path ',load-path)
|
2018-05-20 12:07:20 +02:00
|
|
|
(package-alist ',package-alist)
|
|
|
|
(package-archive-contents ',package-archive-contents)
|
|
|
|
(package-selected-packages ',package-selected-packages)
|
2018-05-18 01:08:25 +02:00
|
|
|
(doom-packages ',doom-packages)
|
|
|
|
(doom-modules ',doom-modules)
|
|
|
|
(quelpa-cache ',quelpa-cache)
|
|
|
|
(user-emacs-directory ,user-emacs-directory)
|
|
|
|
doom-private-dir)
|
|
|
|
(load ,(expand-file-name "core.el" doom-core-dir))
|
|
|
|
(load ,(expand-file-name "autoload/packages.el" doom-core-dir))
|
2018-05-20 12:07:20 +02:00
|
|
|
(require 'package)
|
|
|
|
(require 'quelpa)
|
2018-05-18 01:08:25 +02:00
|
|
|
(doom-package-outdated-p ',pkg))))
|
2017-06-21 16:09:58 +02:00
|
|
|
futures))
|
2017-12-22 15:25:02 -05:00
|
|
|
(delq nil
|
|
|
|
(append (mapcar #'doom-package-outdated-p elpa-pkgs)
|
|
|
|
(mapcar #'async-get (reverse futures)))))))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
2017-02-02 19:15:58 -05:00
|
|
|
;;;###autoload
|
2017-02-03 07:58:16 -05:00
|
|
|
(defun doom-get-orphaned-packages ()
|
2017-02-09 04:25:32 -05:00
|
|
|
"Return a list of symbols representing packages that are no longer needed or
|
|
|
|
depended on.
|
|
|
|
|
2018-06-17 21:35:58 +02:00
|
|
|
Used by `doom-packages-autoremove'."
|
2017-02-19 06:59:55 -05:00
|
|
|
(let ((package-selected-packages
|
2018-06-13 22:15:08 +02:00
|
|
|
(mapcar #'car (doom-get-packages :ignored nil :disabled nil))))
|
2017-11-05 16:04:31 +01:00
|
|
|
(append (package--removable-packages)
|
|
|
|
(cl-loop for pkg in package-selected-packages
|
2017-12-22 04:02:47 -05:00
|
|
|
if (and (doom-package-different-backend-p pkg)
|
|
|
|
(not (package-built-in-p pkg)))
|
2017-11-05 16:04:31 +01:00
|
|
|
collect pkg))))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2018-06-13 22:15:08 +02:00
|
|
|
(defun doom-get-missing-packages (&optional include-ignored-p)
|
2017-04-04 22:17:42 -04:00
|
|
|
"Return a list of requested packages that aren't installed or built-in, but
|
|
|
|
are enabled (with a `package!' directive). Each element is a list whose CAR is
|
|
|
|
the package symbol, and whose CDR is a plist taken from that package's
|
|
|
|
`package!' declaration.
|
2017-02-09 04:25:32 -05:00
|
|
|
|
2017-06-05 14:21:07 +02:00
|
|
|
If INCLUDE-IGNORED-P is non-nil, includes missing packages that are ignored,
|
|
|
|
i.e. they have an :ignore property.
|
|
|
|
|
2018-06-17 21:35:58 +02:00
|
|
|
Used by `doom-packages-install'."
|
2018-06-10 19:15:39 +02:00
|
|
|
(doom-initialize-packages)
|
2018-06-11 23:21:56 +02:00
|
|
|
(cl-loop for (name . plist)
|
2018-09-07 21:52:11 -04:00
|
|
|
in (doom-get-packages :ignored (if include-ignored-p 'any)
|
|
|
|
:disabled nil
|
2018-09-25 10:31:52 -04:00
|
|
|
:deps t
|
|
|
|
:sort nil)
|
2018-06-11 23:21:56 +02:00
|
|
|
if (and (or (plist-get plist :pin)
|
2018-09-07 21:52:11 -04:00
|
|
|
(not (package-built-in-p name)))
|
|
|
|
(or (not (doom-package-installed-p name))
|
2018-02-20 17:55:53 -05:00
|
|
|
(doom-package-different-backend-p name)
|
|
|
|
(doom-package-different-recipe-p name)))
|
2018-06-11 23:21:56 +02:00
|
|
|
collect (cons name plist)))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Main functions
|
|
|
|
|
2018-06-08 01:42:08 +02:00
|
|
|
(defun doom--delete-package-files (name-or-desc)
|
|
|
|
(let ((pkg-build-dir
|
|
|
|
(if (package-desc-p name-or-desc)
|
|
|
|
(package-desc-dir name-or-desc)
|
|
|
|
(expand-file-name (symbol-name name-or-desc) quelpa-build-dir))))
|
|
|
|
(when (file-directory-p pkg-build-dir)
|
|
|
|
(delete-directory pkg-build-dir t))))
|
|
|
|
|
2018-05-20 12:05:17 +02:00
|
|
|
;;;###autoload
|
2017-02-04 21:07:54 -05:00
|
|
|
(defun doom-install-package (name &optional plist)
|
2017-02-03 07:58:16 -05:00
|
|
|
"Installs package NAME with optional quelpa RECIPE (see `quelpa-recipe' for an
|
|
|
|
example; the package name can be omitted)."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
2017-02-11 00:46:42 -05:00
|
|
|
(doom-initialize-packages)
|
2018-01-04 16:09:40 -05:00
|
|
|
(when (and (package-installed-p name)
|
|
|
|
(not (package-built-in-p name)))
|
2018-02-20 17:55:53 -05:00
|
|
|
(if (or (doom-package-different-backend-p name)
|
|
|
|
(doom-package-different-recipe-p name))
|
2018-01-04 16:09:40 -05:00
|
|
|
(doom-delete-package name t)
|
|
|
|
(user-error "%s is already installed" name)))
|
2017-11-13 18:00:46 +01:00
|
|
|
(let* ((inhibit-message (not doom-debug-mode))
|
2018-05-18 01:11:20 +02:00
|
|
|
(plist (or plist (cdr (assq name doom-packages)))))
|
|
|
|
(if-let* ((recipe (plist-get plist :recipe)))
|
2018-06-08 01:42:08 +02:00
|
|
|
(condition-case e
|
|
|
|
(let (quelpa-upgrade-p)
|
|
|
|
(quelpa recipe))
|
2018-06-20 02:23:55 +02:00
|
|
|
((debug error)
|
|
|
|
(doom--delete-package-files name)
|
|
|
|
(signal (car e) (cdr e))))
|
2017-11-13 18:00:46 +01:00
|
|
|
(package-install name))
|
2018-05-18 01:11:20 +02:00
|
|
|
(if (not (package-installed-p name))
|
2018-06-08 01:42:08 +02:00
|
|
|
(doom--delete-package-files name)
|
2018-06-23 20:11:43 +02:00
|
|
|
(setf (alist-get name doom-packages) plist)
|
2018-05-18 01:11:20 +02:00
|
|
|
name)))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
2018-05-20 12:05:17 +02:00
|
|
|
;;;###autoload
|
2017-06-08 11:47:56 +02:00
|
|
|
(defun doom-update-package (name &optional force-p)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Updates package NAME (a symbol) if it is out of date, using quelpa or
|
|
|
|
package.el as appropriate."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
|
|
|
(doom-initialize-packages)
|
2017-02-03 07:58:16 -05:00
|
|
|
(unless (package-installed-p name)
|
2017-04-18 05:45:24 -04:00
|
|
|
(user-error "%s isn't installed" name))
|
2017-11-13 18:01:38 +01:00
|
|
|
(when (doom-package-different-backend-p name)
|
|
|
|
(user-error "%s's backend has changed and must be uninstalled first" name))
|
2017-06-08 11:47:56 +02:00
|
|
|
(when (or force-p (doom-package-outdated-p name))
|
2017-06-03 21:30:41 +02:00
|
|
|
(let ((inhibit-message (not doom-debug-mode))
|
|
|
|
(desc (cadr (assq name package-alist))))
|
2017-02-04 21:07:54 -05:00
|
|
|
(pcase (doom-package-backend name)
|
2018-06-07 17:59:23 +02:00
|
|
|
(`quelpa
|
2018-06-08 01:42:08 +02:00
|
|
|
(condition-case e
|
|
|
|
(let ((quelpa-upgrade-p t))
|
|
|
|
(quelpa (assq name quelpa-cache)))
|
2018-06-20 02:23:55 +02:00
|
|
|
((debug error)
|
|
|
|
(doom--delete-package-files name)
|
|
|
|
(signal (car e) (cdr e)))))
|
2018-06-07 17:59:23 +02:00
|
|
|
(`elpa
|
2017-06-03 21:30:41 +02:00
|
|
|
(let* ((archive (cadr (assq name package-archive-contents)))
|
2017-06-03 21:01:32 +02:00
|
|
|
(packages
|
|
|
|
(if (package-desc-p archive)
|
|
|
|
(package-compute-transaction (list archive) (package-desc-reqs archive))
|
|
|
|
(package-compute-transaction () (list (list archive))))))
|
2017-06-05 03:15:52 +02:00
|
|
|
(package-download-transaction packages))))
|
2017-06-08 11:47:56 +02:00
|
|
|
(unless (doom-package-outdated-p name)
|
2018-06-08 01:42:08 +02:00
|
|
|
(doom--delete-package-files desc)
|
2017-06-08 11:47:56 +02:00
|
|
|
t))))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
2018-05-20 12:05:17 +02:00
|
|
|
;;;###autoload
|
2017-05-15 22:35:57 +02:00
|
|
|
(defun doom-delete-package (name &optional force-p)
|
2017-02-03 07:58:16 -05:00
|
|
|
"Uninstalls package NAME if it exists, and clears it from `quelpa-cache'."
|
2018-06-07 17:59:23 +02:00
|
|
|
(cl-check-type name symbol)
|
|
|
|
(doom-initialize-packages)
|
2017-02-03 07:58:16 -05:00
|
|
|
(unless (package-installed-p name)
|
2017-04-18 05:45:24 -04:00
|
|
|
(user-error "%s isn't installed" name))
|
2017-06-10 23:32:59 +02:00
|
|
|
(let ((inhibit-message (not doom-debug-mode))
|
2018-06-23 16:48:58 +02:00
|
|
|
(spec (assq name quelpa-cache))
|
2017-06-10 23:32:59 +02:00
|
|
|
quelpa-p)
|
2018-06-23 16:48:58 +02:00
|
|
|
(when spec
|
|
|
|
(setq quelpa-cache (delq spec quelpa-cache))
|
2017-06-10 23:32:59 +02:00
|
|
|
(quelpa-save-cache)
|
|
|
|
(setq quelpa-p t))
|
|
|
|
(package-delete (cadr (assq name package-alist)) force-p)
|
2018-06-08 01:42:08 +02:00
|
|
|
(doom--delete-package-files name)
|
|
|
|
(not (package-installed-p name))))
|
2017-02-03 07:58:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2018-05-24 19:10:29 +02:00
|
|
|
;; Interactive commands
|
2017-02-02 19:15:58 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2018-05-24 19:10:29 +02:00
|
|
|
(defun doom/update-package (pkg)
|
|
|
|
"Prompts the user with a list of outdated packages and updates the selected
|
|
|
|
package. Use this interactively. Use `doom-update-package' for direct
|
|
|
|
calls."
|
|
|
|
(declare (interactive-only t))
|
|
|
|
(interactive
|
|
|
|
(let* ((packages (doom-get-outdated-packages))
|
|
|
|
(package (if packages
|
|
|
|
(completing-read "Update package: "
|
|
|
|
(mapcar #'car packages)
|
|
|
|
nil t)
|
|
|
|
(user-error "All packages are up to date"))))
|
|
|
|
(list (cdr (assq (car (assoc package package-alist)) packages)))))
|
|
|
|
(doom-initialize-packages)
|
|
|
|
(cl-destructuring-bind (package old-version new-version) pkg
|
|
|
|
(if-let* ((desc (doom-package-outdated-p package)))
|
|
|
|
(let ((old-v-str (package-version-join old-version))
|
|
|
|
(new-v-str (package-version-join new-version)))
|
|
|
|
(if (y-or-n-p (format "%s will be updated from %s to %s. Update?"
|
|
|
|
package old-v-str new-v-str))
|
|
|
|
(message "%s %s (%s => %s)"
|
|
|
|
(if (doom-update-package package t) "Updated" "Failed to update")
|
|
|
|
package old-v-str new-v-str)
|
|
|
|
(message "Aborted")))
|
|
|
|
(message "%s is up-to-date" package))))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Advice
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom*package-delete (desc &rest _)
|
|
|
|
"Update `quelpa-cache' upon a successful `package-delete'."
|
|
|
|
(doom-initialize-packages)
|
|
|
|
(let ((name (package-desc-name desc)))
|
2018-06-23 16:48:58 +02:00
|
|
|
(unless (package-installed-p name)
|
|
|
|
(when-let* ((spec (assq name quelpa-cache)))
|
|
|
|
(setq quelpa-cache (delq spec quelpa-cache))
|
|
|
|
(quelpa-save-cache)
|
|
|
|
(doom--delete-package-files name)))))
|
2018-05-24 19:10:29 +02:00
|
|
|
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
;;
|
|
|
|
;; Make package.el cooperate with Doom
|
|
|
|
|
|
|
|
;; Updates QUELPA after deleting a package
|
|
|
|
;;;###autoload
|
|
|
|
(advice-add #'package-delete :after #'doom*package-delete)
|
|
|
|
|
|
|
|
;; Replace with Doom variants
|
|
|
|
;;;###autoload
|
2018-06-17 21:35:58 +02:00
|
|
|
(advice-add #'package-autoremove :override (λ! (doom-packages-autoremove current-prefix-arg)))
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
;;;###autoload
|
2018-06-17 21:35:58 +02:00
|
|
|
(advice-add #'package-install-selected-packages :override (λ! (doom-packages-install current-prefix-arg)))
|
2018-06-11 23:18:15 +02:00
|
|
|
|