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.

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