|
1 | 1 | (require 'package)
|
2 | 2 |
|
3 |
| -(setq package-archives '(("qinghua" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/"))) |
4 |
| - ;; ("gnu" . "http://elpa.emacs-china.org/gnu/") |
5 |
| - ;; ("melpa" . "http://elpa.emacs-china.org/melpa/") |
6 |
| - |
| 3 | +(setq package-archives '(("gnu" . "http://elpa.emacs-china.org/gnu/") |
| 4 | + ("melpa" . "http://elpa.emacs-china.org/melpa/") |
| 5 | + ("qinghua" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/"))) |
7 | 6 |
|
8 | 7 | ;;; Install into separate package dirs for each Emacs version, to prevent bytecode incompatibility
|
9 | 8 | (let ((versioned-package-dir
|
|
14 | 13 |
|
15 | 14 | ;;; Standard package repositories
|
16 | 15 |
|
17 |
| -;;(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos)) |
18 |
| -;; (not (gnutls-available-p)))) |
19 |
| -;; (proto (if no-ssl "http" "https"))) |
| 16 | +(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos)) |
| 17 | + (not (gnutls-available-p)))) |
| 18 | + (proto (if no-ssl "http" "https"))) |
20 | 19 | ;;(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
|
21 | 20 | ;; Official MELPA Mirror, in case necessary.
|
22 |
| -;; (add-to-list 'package-archives (cons "melpa-mirror" (concat proto "://elpa.emacs-china.org/melpa/")) t) |
23 |
| -;; (if (< emacs-major-version 24) |
| 21 | + (add-to-list 'package-archives (cons "melpa-mirror" (concat proto "://elpa.emacs-china.org/melpa/")) t) |
| 22 | + (if (< emacs-major-version 24) |
24 | 23 | ;; For important compatibility libraries like cl-lib
|
25 |
| -;; (add-to-list 'package-archives '("gnu" . (concat proto "://elpa.emacs-china.org/gnu/"))) |
26 |
| -;; (unless no-ssl |
| 24 | + (add-to-list 'package-archives '("gnu" . (concat proto "://elpa.emacs-china.org/gnu/"))) |
| 25 | + (unless no-ssl |
27 | 26 | ;; Force SSL for GNU ELPA
|
28 |
| -;; (setcdr (assoc "gnu" package-archives) "http://elpa.emacs-china.org/gnu/")))) |
| 27 | + (setcdr (assoc "gnu" package-archives) "http://elpa.emacs-china.org/gnu/")))) |
29 | 28 |
|
30 | 29 | ;; We include the org repository for completeness, but don't normally
|
31 | 30 | ;; use it.
|
32 | 31 | (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
|
33 | 32 |
|
| 33 | + |
| 34 | +;;; On-demand installation of packages |
| 35 | + |
| 36 | +(defun require-package (package &optional min-version no-refresh) |
| 37 | + "Install given PACKAGE, optionally requiring MIN-VERSION. |
| 38 | +If NO-REFRESH is non-nil, the available package lists will not be |
| 39 | +re-downloaded in order to locate PACKAGE." |
| 40 | + (if (package-installed-p package min-version) |
| 41 | + t |
| 42 | + (if (or (assoc package package-archive-contents) no-refresh) |
| 43 | + (if (boundp 'package-selected-packages) |
| 44 | + ;; Record this as a package the user installed explicitly |
| 45 | + (package-install package nil) |
| 46 | + (package-install package)) |
| 47 | + (progn |
| 48 | + (package-refresh-contents) |
| 49 | + (require-package package min-version t))))) |
| 50 | + |
| 51 | + |
| 52 | +(defun maybe-require-package (package &optional min-version no-refresh) |
| 53 | + "Try to install PACKAGE, and return non-nil if successful. |
| 54 | +In the event of failure, return nil and print a warning message. |
| 55 | +Optionally require MIN-VERSION. If NO-REFRESH is non-nil, the |
| 56 | +available package lists will not be re-downloaded in order to |
| 57 | +locate PACKAGE." |
| 58 | + (condition-case err |
| 59 | + (require-package package min-version no-refresh) |
| 60 | + (error |
| 61 | + (message "Couldn't install optional package `%s': %S" package err) |
| 62 | + nil))) |
| 63 | + |
34 | 64 | ;;; Fire up package.el
|
35 | 65 |
|
36 | 66 | (setq package-enable-at-startup nil)
|
37 | 67 | (package-initialize)
|
38 | 68 |
|
| 69 | +(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") |
| 70 | + |
39 | 71 |
|
40 | 72 | (provide 'init-elpa)
|
0 commit comments