setup-package.el 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ;;; Code:
  2. ;; Some functions adapted from https://github.com/patxoca/dot-emacs/ and prelude
  3. ;; When switching between Emacs 23 and 24, we always use the bundled package.el in Emacs 24
  4. (let ((package-el-site-lisp-dir
  5. (expand-file-name "site-elisp/package" user-emacs-directory)))
  6. (when (and (file-directory-p package-el-site-lisp-dir)
  7. (> emacs-major-version 23))
  8. (message "Removing local package.el from load-path to avoid shadowing bundled version")
  9. (setq load-path (remove package-el-site-lisp-dir load-path))))
  10. (require 'package)
  11. (require 'packages)
  12. (setq nsm-settings-file (expand-file-name ".cache/network-security.data" user-emacs-directory))
  13. (dolist (source '(("gnu" . "https://elpa.gnu.org/packages/")
  14. ("nongnu" . "https://elpa.nongnu.org/nongnu/")
  15. ("melpa" . "https://melpa.org/packages/")))
  16. (add-to-list 'package-archives source t))
  17. ;; Update
  18. (package-initialize)
  19. ;; Auto install
  20. (defun distopico-packages-installed-p ()
  21. (cl-loop for pkg in distopico-packages
  22. when (not (package-installed-p pkg)) do (cl-return nil)
  23. finally (cl-return t)))
  24. (defun distopico:available-package-p (pkg)
  25. "Return t if `PKG' is an available package."
  26. (unless package-archive-contents
  27. (package-refresh-contents))
  28. (not (null (assoc pkg package-archive-contents))))
  29. ;;;###autoload
  30. (defun distopico:ensure-required-packages ()
  31. "Check if dependencies packages are installed."
  32. (interactive)
  33. (unless (distopico-packages-installed-p)
  34. (message "%s" "Emacs is now refreshing its package database...")
  35. (package-refresh-contents)
  36. (message "%s" " done.")
  37. ;; install the missing packages
  38. (dolist (pkg distopico-packages)
  39. (when (and (distopico:available-package-p pkg)
  40. (not (package-installed-p pkg)))
  41. (package-install pkg)))))
  42. ;;;###autoload
  43. (defun distopico:check-required-packages ()
  44. "Check if `distopico-packages' is up to date."
  45. (interactive)
  46. (dolist (pkg package-alist)
  47. (unless (member (car pkg) required-packages)
  48. (message "Package missing: %s" (car pkg)))))
  49. ;;;###autoload
  50. (defun distopico:load-require-libs ()
  51. "Load all libs in `utils-dir'."
  52. (dolist (file (directory-files utils-dir t "\\w+"))
  53. (when (file-regular-p file)
  54. (load file))))
  55. ;;;###autoload
  56. (defun distopico:package-init-load-hook ()
  57. (if (getenv "EMACS_INSTALL")
  58. (distopico:startup-byte-recompile)))
  59. ;; Hooks
  60. (add-hook 'distopico:after-init-load-hook 'distopico:package-init-load-hook)
  61. ;; Run package
  62. (distopico:ensure-required-packages)
  63. (provide 'setup-package)