/
init-package.el
121 lines (101 loc) · 4.49 KB
/
init-package.el
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
;;; init-package.el --- Initialize package configurations. -*- lexical-binding: t -*-
;; Copyright (C) 2018 Vincent Zhang
;; Author: Vincent Zhang <seagle0128@gmail.com>
;; URL: https://github.com/seagle0128/.emacs.d
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;; Commentary:
;;
;; Emacs Package management configurations.
;;
;;; Code:
(eval-when-compile
(require 'init-custom))
;; HACK: DO NOT copy package-selected-packages to init/custom file forcibly.
;; https://github.com/jwiegley/use-package/issues/383#issuecomment-247801751
(defun my-save-selected-packages (&optional value)
"Set and (don't!) save `package-selected-packages' to VALUE."
(when value
(setq package-selected-packages value))
(unless after-init-time
(add-hook 'after-init-hook #'package--save-selected-packages)))
(advice-add 'package--save-selected-packages :override #'my-save-selected-packages)
;;
;; ELPA: refer to https://github.com/melpa/melpa and https://elpa.emacs-china.org/.
;;
(defun set-package-archives (archives)
"Set specific package ARCHIVES repository."
(interactive
(list
(intern (completing-read "Switch to archives: "
'(melpa melpa-mirror emacs-china netease tuna)))))
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(cond
((eq archives 'melpa)
(setq package-archives `(,(cons "gnu" (concat proto "://elpa.gnu.org/packages/"))
,(cons "melpa" (concat proto "://melpa.org/packages/")))))
((eq archives 'melpa-mirror)
(setq package-archives `(,(cons "gnu" (concat proto "://elpa.gnu.org/packages/"))
,(cons "melpa" (concat proto "://www.mirrorservice.org/sites/melpa.org/packages/")))))
((eq archives 'emacs-china)
(setq package-archives `(,(cons "gnu" (concat proto "://elpa.emacs-china.org/gnu/"))
,(cons "melpa" (concat proto "://elpa.emacs-china.org/melpa/")))))
((eq archives 'netease)
(setq package-archives `(,(cons "gnu" (concat proto "://mirrors.163.com/elpa/gnu/"))
,(cons "melpa" (concat proto "://mirrors.163.com/elpa/melpa/")))))
((eq archives 'tuna)
(setq package-archives `(,(cons "gnu" (concat proto "://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/"))
,(cons "melpa" (concat proto "://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))))
(t
(error "Unknown archives: '%s'" archives))))
(message "Set package archives to '%s'." archives))
(set-package-archives centaur-package-archives)
;; Initialize packages
(unless (bound-and-true-p package--initialized) ; To avoid warnings in 27
(setq package-enable-at-startup nil) ; To prevent initializing twice
(package-initialize))
;; Setup `use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
;; Should set before loading `use-package'
(setq use-package-always-ensure t)
(setq use-package-always-defer t)
(setq use-package-expand-minimally t)
(setq use-package-enable-imenu-support t)
(eval-when-compile
(require 'use-package))
;; Required by `use-package'
(use-package diminish)
(use-package bind-key)
;; Initialization benchmark
(when centaur-benchmark
(use-package benchmark-init
:commands (benchmark-init/activate)
:hook (after-init . benchmark-init/deactivate)
:init (benchmark-init/activate)))
;; Extensions
(use-package package-utils
:init
(defalias 'upgrade-packages 'package-utils-upgrade-all)
(defalias 'upgrade-packages-and-restart 'package-utils-upgrade-all-and-restart))
(provide 'init-package)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; init-package.el ends here