aboutsummaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/init-package.el
blob: f7980e5ca96aa8c4766a5567e7c8fbe48b4575fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;;; init-package.el -*- lexical-binding: t -*-

(require 'package)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
                         ("mepla" . "https://melpa.org/packages/")
                         ("melpa-stable" . "https://stable.melpa.org/packages/")))
(setq package-user-dir
      (expand-file-name "elpa" user-emacs-directory))

(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)
            (gx/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)
(setq package-native-compile t)
(package-initialize)

(gx/maybe-require-package 'auto-package-update)
(autoload #'auto-package-update-now "auto-package-update" nil t)
(setq auto-package-update-delete-old-versions t
      auto-package-update-hide-results t)

(provide 'init-package)