                          (package--find-non-dependencies)))))
 
 (defun doom/packages-clean ()
-  "Delete unused packages."
+  "Delete packages that are no longer used or referred to."
   (interactive)
   (doom-package-init t)
   (let* ((package-selected-packages (-intersection (package--find-non-dependencies) doom-packages))

      (not (version-list-<= newest-version installed-version)))))

(defun doom/packages-reload ()
  "Reload DOOM Emacs. This includes the `load-path'"
  (interactive)
  (setq load-path doom--load-path)
  (doom-package-init t)
  (when (called-interactively-p 'interactive)
    (message "Reloaded %s packages" (length package-alist))))

(defun doom/packages-install ()
  "Activate `doom-packages-auto-p' and evaluation your emacs configuration
again, in order to auto-install all packages that are missing."
  (interactive)
  (setq doom-packages-auto-p t)
  (doom-package-init t)
  (load (expand-file-name "init.el" doom-emacs-dir) nil nil t))

(defun doom/packages-update ()
  "Update all installed packages. This includes quelpa itself, quelpa-installed
packages, and ELPA packages."
  (interactive)
  (doom-package-init t)
  (quelpa-upgrade) ; upgrade quelpa + quelpa-installed packages
  (package-refresh-contents) ; ...then packages.el
  (mapc (lambda (package)
          (condition-case ex
              (let ((desc (cadr (assq package package-alist))))

        ("melpa" . "http://melpa.org/packages/")
        ("org"   . "http://orgmode.org/elpa/"))

      use-package-always-defer t
      use-package-always-ensure nil
      use-package-debug doom-debug-mode
      quelpa-checkout-melpa-p nil
      quelpa-update-melpa-p nil
      quelpa-use-package-inhibit-loading-quelpa t
      quelpa-dir (expand-file-name "quelpa" doom-packages-dir))


;;
;; Library
;;

(defun doom-package-init (&optional force-p)
  "Initialize DOOM, its essential packages and package.el. This must be used on
first run. If you byte compile core/core.el, this file is avoided to speed up
startup. Returns `load-path'."
  (when (or (not doom-init) force-p)
    (package-initialize)
    (when (or (not (file-exists-p package-user-dir)) force-p)
      (package-refresh-contents))
    (unless (package-installed-p 'quelpa-use-package)
      (package-install 'quelpa-use-package t))

    (require 'quelpa-use-package)
    (setq use-package-always-ensure t)
    (quelpa-use-package-activate-advice)

    (add-to-list 'load-path doom-local-dir)
    (add-to-list 'load-path doom-modules-dir)
    (add-to-list 'load-path doom-core-dir)

    (setq doom-init t)))

(defmacro package! (name &rest rest)
  "Declare a package. Wraps around `use-package', and takes the same arguments
that it does. NOTE: Packages are deferred by default."
  (declare (indent defun))
  (add-to-list 'doom-packages name)
  ;; If `use-package-always-ensure' is nil, then remove any possibility of an
  ;; installation by package.el or quelpa.
  (unless use-package-always-ensure
    (when (and (plist-member rest :ensure)
               (plist-get rest :ensure))
      (setq rest (plist-put rest :ensure nil)))
