;;; 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 '(("GNU ELPA" . "https://elpa.gnu.org/packages/") ("MELPA Stable" . "https://stable.melpa.org/packages/") ("ORG" . "https://orgmode.org/elpa/") ("MELPA" . "https://melpa.org/packages/")) package-archive-priorities '(("MELPA Stable" . 10) ("GNU ELPA" . 5) ("ORG" . 3) ("MELPA" . 0))) ;; ================= ;;; 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)