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.

214 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. nlinum
  69. operate-on-number
  70. smartparens
  71. smartrep
  72. super-save
  73. undo-tree
  74. volatile-highlights
  75. which-key
  76. zenburn-theme
  77. zop-to-char)
  78. "A list of packages to ensure are installed at launch.")
  79. (defun prelude-packages-installed-p ()
  80. "Check if all packages in `prelude-packages' are installed."
  81. (cl-every #'package-installed-p prelude-packages))
  82. (defun prelude-require-package (package)
  83. "Install PACKAGE unless already installed."
  84. (unless (memq package prelude-packages)
  85. (add-to-list 'prelude-packages package))
  86. (unless (package-installed-p package)
  87. (package-install package)))
  88. (defun prelude-require-packages (packages)
  89. "Ensure PACKAGES are installed.
  90. Missing packages are installed automatically."
  91. (mapc #'prelude-require-package packages))
  92. (define-obsolete-function-alias 'prelude-ensure-module-deps 'prelude-require-packages)
  93. (defun prelude-install-packages ()
  94. "Install all packages listed in `prelude-packages'."
  95. (unless (prelude-packages-installed-p)
  96. ;; check for new packages (package versions)
  97. (message "%s" "Emacs Prelude is now refreshing its package database...")
  98. (package-refresh-contents)
  99. (message "%s" " done.")
  100. ;; install the missing packages
  101. (prelude-require-packages prelude-packages)))
  102. ;; run package installation
  103. (prelude-install-packages)
  104. (defun prelude-list-foreign-packages ()
  105. "Browse third-party packages not bundled with Prelude.
  106. Behaves similarly to `package-list-packages', but shows only the packages that
  107. are installed and are not in `prelude-packages'. Useful for
  108. removing unwanted packages."
  109. (interactive)
  110. (package-show-package-list
  111. (cl-set-difference package-activated-list prelude-packages)))
  112. (defmacro prelude-auto-install (extension package mode)
  113. "When file with EXTENSION is opened triggers auto-install of PACKAGE.
  114. PACKAGE is installed only if not already present. The file is opened in MODE."
  115. `(add-to-list 'auto-mode-alist
  116. `(,extension . (lambda ()
  117. (unless (package-installed-p ',package)
  118. (package-install ',package))
  119. (,mode)))))
  120. (defvar prelude-auto-install-alist
  121. '(("\\.clj\\'" clojure-mode clojure-mode)
  122. ("\\.cmake\\'" cmake-mode cmake-mode)
  123. ("CMakeLists\\.txt\\'" cmake-mode cmake-mode)
  124. ("\\.coffee\\'" coffee-mode coffee-mode)
  125. ("\\.css\\'" css-mode css-mode)
  126. ("\\.csv\\'" csv-mode csv-mode)
  127. ("Cask" cask-mode cask-mode)
  128. ("\\.d\\'" d-mode d-mode)
  129. ("\\.dart\\'" dart-mode dart-mode)
  130. ("\\.elm\\'" elm-mode elm-mode)
  131. ("\\.ex\\'" elixir-mode elixir-mode)
  132. ("\\.exs\\'" elixir-mode elixir-mode)
  133. ("\\.elixir\\'" elixir-mode elixir-mode)
  134. ("\\.erl\\'" erlang erlang-mode)
  135. ("\\.feature\\'" feature-mode feature-mode)
  136. ("\\.go\\'" go-mode go-mode)
  137. ("\\.graphql\\'" graphql-mode graphql-mode)
  138. ("\\.groovy\\'" groovy-mode groovy-mode)
  139. ("\\.haml\\'" haml-mode haml-mode)
  140. ("\\.hs\\'" haskell-mode haskell-mode)
  141. ("\\.json\\'" json-mode json-mode)
  142. ("\\.kt\\'" kotlin-mode kotlin-mode)
  143. ("\\.kv\\'" kivy-mode kivy-mode)
  144. ("\\.latex\\'" auctex LaTeX-mode)
  145. ("\\.less\\'" less-css-mode less-css-mode)
  146. ("\\.lua\\'" lua-mode lua-mode)
  147. ("\\.markdown\\'" markdown-mode markdown-mode)
  148. ("\\.md\\'" markdown-mode markdown-mode)
  149. ("\\.ml\\'" tuareg tuareg-mode)
  150. ("\\.pp\\'" puppet-mode puppet-mode)
  151. ("\\.php\\'" php-mode php-mode)
  152. ("\\.proto\\'" protobuf-mode protobuf-mode)
  153. ("\\.pyd\\'" cython-mode cython-mode)
  154. ("\\.pyi\\'" cython-mode cython-mode)
  155. ("\\.pyx\\'" cython-mode cython-mode)
  156. ("PKGBUILD\\'" pkgbuild-mode pkgbuild-mode)
  157. ("\\.rs\\'" rust-mode rust-mode)
  158. ("\\.sass\\'" sass-mode sass-mode)
  159. ("\\.scala\\'" scala-mode scala-mode)
  160. ("\\.scss\\'" scss-mode scss-mode)
  161. ("\\.slim\\'" slim-mode slim-mode)
  162. ("\\.styl\\'" stylus-mode stylus-mode)
  163. ("\\.swift\\'" swift-mode swift-mode)
  164. ("\\.textile\\'" textile-mode textile-mode)
  165. ("\\.thrift\\'" thrift thrift-mode)
  166. ("\\.yml\\'" yaml-mode yaml-mode)
  167. ("\\.yaml\\'" yaml-mode yaml-mode)
  168. ("Dockerfile\\'" dockerfile-mode dockerfile-mode)))
  169. ;; markdown-mode doesn't have autoloads for the auto-mode-alist
  170. ;; so we add them manually if it's already installed
  171. (when (package-installed-p 'markdown-mode)
  172. (add-to-list 'auto-mode-alist '("\\.markdown\\'" . gfm-mode))
  173. (add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode)))
  174. (when (package-installed-p 'pkgbuild-mode)
  175. (add-to-list 'auto-mode-alist '("PKGBUILD\\'" . pkgbuild-mode)))
  176. ;; build auto-install mappings
  177. (mapc
  178. (lambda (entry)
  179. (let ((extension (car entry))
  180. (package (cadr entry))
  181. (mode (cadr (cdr entry))))
  182. (unless (package-installed-p package)
  183. (prelude-auto-install extension package mode))))
  184. prelude-auto-install-alist)
  185. (provide 'prelude-packages)
  186. ;; Local Variables:
  187. ;; byte-compile-warnings: (not cl-functions)
  188. ;; End:
  189. ;;; prelude-packages.el ends here