Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
7.1 KiB

12 years ago
9 years ago
9 years ago
10 years ago
11 years ago
  1. ;;; prelude-packages.el --- Emacs Prelude: default package selection.
  2. ;;
  3. ;; Copyright © 2011-2020 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar@batsov.com>
  6. ;; URL: https://github.com/bbatsov/prelude
  7. ;; This file is not part of GNU Emacs.
  8. ;;; Commentary:
  9. ;; Takes care of the automatic installation of all the packages required by
  10. ;; Emacs Prelude.
  11. ;;; License:
  12. ;; This program is free software; you can redistribute it and/or
  13. ;; modify it under the terms of the GNU General Public License
  14. ;; as published by the Free Software Foundation; either version 3
  15. ;; of the License, or (at your option) any later version.
  16. ;;
  17. ;; This program is distributed in the hope that it will be useful,
  18. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;; GNU General Public License for more details.
  21. ;;
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  24. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  25. ;; Boston, MA 02110-1301, USA.
  26. ;;; Code:
  27. (require 'cl-lib)
  28. (require 'package)
  29. ;; accessing a package repo over https on Windows is a no go, so we
  30. ;; fallback to http there
  31. (if (eq system-type 'windows-nt)
  32. (add-to-list 'package-archives
  33. '("melpa" . "http://melpa.org/packages/") t)
  34. (add-to-list 'package-archives
  35. '("melpa" . "https://melpa.org/packages/") t))
  36. ;; load the pinned packages
  37. (let ((prelude-pinned-packages-file (expand-file-name "prelude-pinned-packages.el" prelude-dir)))
  38. (if (file-exists-p prelude-pinned-packages-file)
  39. (load prelude-pinned-packages-file)))
  40. ;; set package-user-dir to be relative to Prelude install path
  41. (setq package-user-dir (expand-file-name "elpa" prelude-dir))
  42. (package-initialize)
  43. (defvar prelude-packages
  44. '(ace-window
  45. avy
  46. anzu
  47. beacon
  48. browse-kill-ring
  49. crux
  50. discover-my-major
  51. diff-hl
  52. diminish
  53. easy-kill
  54. editorconfig
  55. epl
  56. expand-region
  57. flycheck
  58. gist
  59. git-timemachine
  60. gitconfig-mode
  61. gitignore-mode
  62. guru-mode
  63. hl-todo
  64. imenu-anywhere
  65. projectile
  66. magit
  67. move-text
  68. operate-on-number
  69. smartparens
  70. smartrep
  71. super-save
  72. undo-tree
  73. volatile-highlights
  74. which-key
  75. zenburn-theme
  76. zop-to-char)
  77. "A list of packages to ensure are installed at launch.")
  78. (defun prelude-packages-installed-p ()
  79. "Check if all packages in `prelude-packages' are installed."
  80. (cl-every #'package-installed-p prelude-packages))
  81. (defun prelude-require-package (package)
  82. "Install PACKAGE unless already installed."
  83. (unless (memq package prelude-packages)
  84. (add-to-list 'prelude-packages package))
  85. (unless (package-installed-p package)
  86. (package-install package)))
  87. (defun prelude-require-packages (packages)
  88. "Ensure PACKAGES are installed.
  89. Missing packages are installed automatically."
  90. (mapc #'prelude-require-package packages))
  91. (define-obsolete-function-alias 'prelude-ensure-module-deps 'prelude-require-packages)
  92. (defun prelude-install-packages ()
  93. "Install all packages listed in `prelude-packages'."
  94. (unless (prelude-packages-installed-p)
  95. ;; check for new packages (package versions)
  96. (message "%s" "Emacs Prelude is now refreshing its package database...")
  97. (package-refresh-contents)
  98. (message "%s" " done.")
  99. ;; install the missing packages
  100. (prelude-require-packages prelude-packages)))
  101. ;; run package installation
  102. (prelude-install-packages)
  103. (defun prelude-list-foreign-packages ()
  104. "Browse third-party packages not bundled with Prelude.
  105. Behaves similarly to `package-list-packages', but shows only the packages that
  106. are installed and are not in `prelude-packages'. Useful for
  107. removing unwanted packages."
  108. (interactive)
  109. (package-show-package-list
  110. (cl-set-difference package-activated-list prelude-packages)))
  111. (defmacro prelude-auto-install (extension package mode)
  112. "When file with EXTENSION is opened triggers auto-install of PACKAGE.
  113. PACKAGE is installed only if not already present. The file is opened in MODE."
  114. `(add-to-list 'auto-mode-alist
  115. `(,extension . (lambda ()
  116. (unless (package-installed-p ',package)
  117. (package-install ',package))
  118. (,mode)))))
  119. (defvar prelude-auto-install-alist
  120. '(("\\.clj\\'" clojure-mode clojure-mode)
  121. ("\\.cmake\\'" cmake-mode cmake-mode)
  122. ("CMakeLists\\.txt\\'" cmake-mode cmake-mode)
  123. ("\\.coffee\\'" coffee-mode coffee-mode)
  124. ("\\.css\\'" css-mode css-mode)
  125. ("\\.csv\\'" csv-mode csv-mode)
  126. ("Cask" cask-mode cask-mode)
  127. ("\\.d\\'" d-mode d-mode)
  128. ("\\.dart\\'" dart-mode dart-mode)
  129. ("\\.elm\\'" elm-mode elm-mode)
  130. ("\\.ex\\'" elixir-mode elixir-mode)
  131. ("\\.exs\\'" elixir-mode elixir-mode)
  132. ("\\.elixir\\'" elixir-mode elixir-mode)
  133. ("\\.erl\\'" erlang erlang-mode)
  134. ("\\.feature\\'" feature-mode feature-mode)
  135. ("\\.go\\'" go-mode go-mode)
  136. ("\\.graphql\\'" graphql-mode graphql-mode)
  137. ("\\.groovy\\'" groovy-mode groovy-mode)
  138. ("\\.haml\\'" haml-mode haml-mode)
  139. ("\\.hs\\'" haskell-mode haskell-mode)
  140. ("\\.json\\'" json-mode json-mode)
  141. ("\\.kt\\'" kotlin-mode kotlin-mode)
  142. ("\\.kv\\'" kivy-mode kivy-mode)
  143. ("\\.latex\\'" auctex LaTeX-mode)
  144. ("\\.less\\'" less-css-mode less-css-mode)
  145. ("\\.lua\\'" lua-mode lua-mode)
  146. ("\\.markdown\\'" markdown-mode markdown-mode)
  147. ("\\.md\\'" markdown-mode markdown-mode)
  148. ("\\.ml\\'" tuareg tuareg-mode)
  149. ("\\.pp\\'" puppet-mode puppet-mode)
  150. ("\\.php\\'" php-mode php-mode)
  151. ("\\.proto\\'" protobuf-mode protobuf-mode)
  152. ("\\.pyd\\'" cython-mode cython-mode)
  153. ("\\.pyi\\'" cython-mode cython-mode)
  154. ("\\.pyx\\'" cython-mode cython-mode)
  155. ("PKGBUILD\\'" pkgbuild-mode pkgbuild-mode)
  156. ("\\.rs\\'" rust-mode rust-mode)
  157. ("\\.sass\\'" sass-mode sass-mode)
  158. ("\\.scala\\'" scala-mode scala-mode)
  159. ("\\.scss\\'" scss-mode scss-mode)
  160. ("\\.slim\\'" slim-mode slim-mode)
  161. ("\\.styl\\'" stylus-mode stylus-mode)
  162. ("\\.swift\\'" swift-mode swift-mode)
  163. ("\\.textile\\'" textile-mode textile-mode)
  164. ("\\.thrift\\'" thrift thrift-mode)
  165. ("\\.yml\\'" yaml-mode yaml-mode)
  166. ("\\.yaml\\'" yaml-mode yaml-mode)
  167. ("Dockerfile\\'" dockerfile-mode dockerfile-mode)))
  168. ;; markdown-mode doesn't have autoloads for the auto-mode-alist
  169. ;; so we add them manually if it's already installed
  170. (when (package-installed-p 'markdown-mode)
  171. (add-to-list 'auto-mode-alist '("\\.markdown\\'" . gfm-mode))
  172. (add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode)))
  173. (when (package-installed-p 'pkgbuild-mode)
  174. (add-to-list 'auto-mode-alist '("PKGBUILD\\'" . pkgbuild-mode)))
  175. ;; build auto-install mappings
  176. (mapc
  177. (lambda (entry)
  178. (let ((extension (car entry))
  179. (package (cadr entry))
  180. (mode (cadr (cdr entry))))
  181. (unless (package-installed-p package)
  182. (prelude-auto-install extension package mode))))
  183. prelude-auto-install-alist)
  184. (provide 'prelude-packages)
  185. ;; Local Variables:
  186. ;; byte-compile-warnings: (not cl-functions)
  187. ;; End:
  188. ;;; prelude-packages.el ends here