Add Emacs elpa configuration

ELPA mirror

Emacs China镜像

ELPA镜像地址
GNU ELPAhttp://elpa.emacs-china.org/gnu/
MELPAhttp://elpa.emacs-china.org/melpa/
MELPA Stablehttp://elpa.emacs-china.org/melpa-stable/
Marmaladehttp://elpa.emacs-china.org/marmalade/
Orghttp://elpa.emacs-china.org/org/
Sunrise Commander ELPAhttp://elpa.emacs-china.org/sunrise-commander/
user42 ELPAhttp://elpa.emacs-china.org/user42/

如果需要 HTTPS,请将镜像地址中的 http 改成 https

清华镜像

ELPA镜像地址
GNU ELPAhttp://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/
MELPAhttp://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/
MELPA Stablehttp://mirrors.tuna.tsinghua.edu.cn/elpa/melpa-stable/
Marmaladehttp://mirrors.tuna.tsinghua.edu.cn/elpa/marmalade/
Orghttp://mirrors.tuna.tsinghua.edu.cn/elpa/org/

可以从 d12frosted/elpa-mirror 下载包镜像到本地使用。

包管理

定义如下代码,即可使用 use-packagerequire-package 来安装和管理包:

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
(defun 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."
(if (package-installed-p package min-version)
t
(if (or (assoc package package-archive-contents) no-refresh)
(if (boundp 'package-selected-packages)
;; Record this as a package the user installed explicitly
(package-install package nil)
(package-install package))
(progn
(package-refresh-contents)
(require-package package min-version t)))))


(defun 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."
(condition-case err
(require-package package min-version no-refresh)
(error
(message "Couldn't install optional package `%s': %S" package err)
nil)))

(setq package-archives
'(("melpa" . "E:/GitHub/elpa-mirror/melpa")
("org" . "E:/GitHub/elpa-mirror/org")
("gnu" . "E:/GitHub/elpa-mirror/gnu")
)
)

;; update the package metadata is the local cache is missing
(unless package-archive-contents
(package-refresh-contents))

(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))

(eval-when-compile
(require 'use-package))

请注意修改 package-archives 中的 ELPA 源。

使用示例

use-package

1
2
3
(use-package helm
:ensure t
)

require-package

1
(require-package 'helm)
0%