54 lines
1.9 KiB
EmacsLisp
54 lines
1.9 KiB
EmacsLisp
;;; Find and load the correct package.el
|
|
;; When switching between Emacs 23 and 24, we always use the bundled package.el in Emacs 24
|
|
(let ((package-el-site-lisp-dir
|
|
(expand-file-name "site-lisp/package" user-emacs-directory)))
|
|
(when (and (file-directory-p package-el-site-lisp-dir)
|
|
(> emacs-major-version 23))
|
|
(message "Removing local package.el from load-path to avoid shadowing bundled version")
|
|
(setq load-path (remove package-el-site-lisp-dir load-path))))
|
|
|
|
(require 'package)
|
|
|
|
;; Repositories
|
|
;; ================
|
|
(setq package-archives
|
|
'(("melpa" . "https://melpa.org/packages/")
|
|
;;("melpa-stable" . "https://stable.melpa.org/packages/")
|
|
("gnu" . "https://elpa.gnu.org/packages/")
|
|
("org" . "https://orgmode.org/elpa/")))
|
|
|
|
(setq package-archive-priorities
|
|
'(("melpa" . 4)
|
|
("melpa-stable" . 0)
|
|
("gnu" . 1)
|
|
("org" . 3)))
|
|
;; =================
|
|
|
|
;; Refresh packages in Emacs
|
|
;; ==========================
|
|
(when (not package-archive-contents)
|
|
(package-refresh-contents))
|
|
|
|
;;; Find packages if not installed
|
|
;; ================================
|
|
;;; On-demand installation of packages
|
|
(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)))))
|
|
;; ================================
|
|
|
|
(package-initialize)
|
|
|
|
(provide 'init-elpa)
|