aboutsummaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/init-package.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/init-package.el')
-rw-r--r--.emacs.d/lisp/init-package.el47
1 files changed, 38 insertions, 9 deletions
diff --git a/.emacs.d/lisp/init-package.el b/.emacs.d/lisp/init-package.el
index 1501de4..dbd520e 100644
--- a/.emacs.d/lisp/init-package.el
+++ b/.emacs.d/lisp/init-package.el
@@ -2,17 +2,46 @@
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("mepla" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")))
-(package-initialize)
-(dolist (package '(use-package))
- (unless (package-installed-p package)
- (package-refresh-contents)
- (package-install package)))
-(require 'use-package)
-(setq use-package-always-ensure t
- use-package-always-defer t)
+(defun gx/require-package (package &optional min-version no-refresh)
+ "Install given PACKAGE, optionally requiring MIN-VERSION. If
+NO-REFRESH is non-nil, the available package lists will not be
+re-downloaded in order to locate PACKAGE.
+
+This function is copied from
+https://github.com/purcell/emacs.d/blob/master/lisp/init-elpa.el"
+ (or (package-installed-p package min-version)
+ (let* ((known (cdr (assoc package package-archive-contents)))
+ (best (car (sort known (lambda (a b)
+ (version-list-<= (package-desc-version b)
+ (package-desc-version a)))))))
+ (if (and best (version-list-<= min-version (package-desc-version best)))
+ (package-install best)
+ (if no-refresh
+ (error "No version of %s >= %S is available" package min-version)
+ (package-refresh-contents)
+ (require-package package min-version t)))
+ (package-installed-p package min-version))))
+
+(defun gx/maybe-require-package (package &optional min-version no-refresh)
+ "Try to install PACKAGE, and return non-nil if successful.
+In the event of failure, return nil and print a warning message.
+Optionally require MIN-VERSION. If NO-REFRESH is non-nil, the
+available package lists will not be re-downloaded in order to
+locate PACKAGE.
+
+This function is copied from
+https://github.com/purcell/emacs.d/blob/master/lisp/init-elpa.el"
+ (condition-case err
+ (gx/require-package package min-version no-refresh)
+ (error
+ (message "Couldn't install optional package `%s': %S" package err)
+ nil)))
+
+(setq package-enable-at-startup nil)
+(package-initialize)
-(use-package auto-package-update)
+(gx/maybe-require-package 'auto-package-update)
(setq auto-package-update-delete-old-versions t
auto-package-update-hide-results t)