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.

202 lines
6.5 KiB

12 years ago
10 years ago
12 years ago
11 years ago
  1. ;;; prelude-packages.el --- Emacs Prelude: default package selection.
  2. ;;
  3. ;; Copyright © 2011-2016 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. (add-to-list 'package-archives
  32. '("melpa" . "https://melpa.org/packages/") t)
  33. ;; set package-user-dir to be relative to Prelude install path
  34. (setq package-user-dir (expand-file-name "elpa" prelude-dir))
  35. (package-initialize)
  36. (defvar prelude-packages
  37. '(ace-window
  38. avy
  39. anzu
  40. beacon
  41. browse-kill-ring
  42. dash
  43. discover-my-major
  44. diff-hl
  45. diminish
  46. easy-kill
  47. epl
  48. expand-region
  49. flycheck
  50. gist
  51. git-timemachine
  52. gitconfig-mode
  53. gitignore-mode
  54. god-mode
  55. grizzl
  56. guru-mode
  57. imenu-anywhere
  58. ov
  59. projectile
  60. magit
  61. move-text
  62. operate-on-number
  63. smart-mode-line
  64. smartparens
  65. smartrep
  66. undo-tree
  67. volatile-highlights
  68. which-key
  69. zenburn-theme
  70. zop-to-char)
  71. "A list of packages to ensure are installed at launch.")
  72. (defun prelude-packages-installed-p ()
  73. "Check if all packages in `prelude-packages' are installed."
  74. (every #'package-installed-p prelude-packages))
  75. (defun prelude-require-package (package)
  76. "Install PACKAGE unless already installed."
  77. (unless (memq package prelude-packages)
  78. (add-to-list 'prelude-packages package))
  79. (unless (package-installed-p package)
  80. (package-install package)))
  81. (defun prelude-require-packages (packages)
  82. "Ensure PACKAGES are installed.
  83. Missing packages are installed automatically."
  84. (mapc #'prelude-require-package packages))
  85. (define-obsolete-function-alias 'prelude-ensure-module-deps 'prelude-require-packages)
  86. (defun prelude-install-packages ()
  87. "Install all packages listed in `prelude-packages'."
  88. (unless (prelude-packages-installed-p)
  89. ;; check for new packages (package versions)
  90. (message "%s" "Emacs Prelude is now refreshing its package database...")
  91. (package-refresh-contents)
  92. (message "%s" " done.")
  93. ;; install the missing packages
  94. (prelude-require-packages prelude-packages)))
  95. ;; run package installation
  96. (prelude-install-packages)
  97. (defun prelude-list-foreign-packages ()
  98. "Browse third-party packages not bundled with Prelude.
  99. Behaves similarly to `package-list-packages', but shows only the packages that
  100. are installed and are not in `prelude-packages'. Useful for
  101. removing unwanted packages."
  102. (interactive)
  103. (package-show-package-list
  104. (set-difference package-activated-list prelude-packages)))
  105. (defmacro prelude-auto-install (extension package mode)
  106. "When file with EXTENSION is opened triggers auto-install of PACKAGE.
  107. PACKAGE is installed only if not already present. The file is opened in MODE."
  108. `(add-to-list 'auto-mode-alist
  109. `(,extension . (lambda ()
  110. (unless (package-installed-p ',package)
  111. (package-install ',package))
  112. (,mode)))))
  113. (defvar prelude-auto-install-alist
  114. '(("\\.clj\\'" clojure-mode clojure-mode)
  115. ("\\.cmake\\'" cmake-mode cmake-mode)
  116. ("CMakeLists\\.txt\\'" cmake-mode cmake-mode)
  117. ("\\.coffee\\'" coffee-mode coffee-mode)
  118. ("\\.css\\'" css-mode css-mode)
  119. ("\\.csv\\'" csv-mode csv-mode)
  120. ("\\.d\\'" d-mode d-mode)
  121. ("\\.dart\\'" dart-mode dart-mode)
  122. ("\\.elm\\'" elm-mode elm-mode)
  123. ("\\.ex\\'" elixir-mode elixir-mode)
  124. ("\\.exs\\'" elixir-mode elixir-mode)
  125. ("\\.elixir\\'" elixir-mode elixir-mode)
  126. ("\\.erl\\'" erlang erlang-mode)
  127. ("\\.feature\\'" feature-mode feature-mode)
  128. ("\\.go\\'" go-mode go-mode)
  129. ("\\.groovy\\'" groovy-mode groovy-mode)
  130. ("\\.haml\\'" haml-mode haml-mode)
  131. ("\\.hs\\'" haskell-mode haskell-mode)
  132. ("\\.json\\'" json-mode json-mode)
  133. ("\\.kv\\'" kivy-mode kivy-mode)
  134. ("\\.latex\\'" auctex LaTeX-mode)
  135. ("\\.less\\'" less-css-mode less-css-mode)
  136. ("\\.lua\\'" lua-mode lua-mode)
  137. ("\\.markdown\\'" markdown-mode markdown-mode)
  138. ("\\.md\\'" markdown-mode markdown-mode)
  139. ("\\.ml\\'" tuareg tuareg-mode)
  140. ("\\.pp\\'" puppet-mode puppet-mode)
  141. ("\\.php\\'" php-mode php-mode)
  142. ("\\.proto\\'" protobuf-mode protobuf-mode)
  143. ("\\.pyd\\'" cython-mode cython-mode)
  144. ("\\.pyi\\'" cython-mode cython-mode)
  145. ("\\.pyx\\'" cython-mode cython-mode)
  146. ("PKGBUILD\\'" pkgbuild-mode pkgbuild-mode)
  147. ("\\.rs\\'" rust-mode rust-mode)
  148. ("\\.sass\\'" sass-mode sass-mode)
  149. ("\\.scala\\'" scala-mode2 scala-mode)
  150. ("\\.scss\\'" scss-mode scss-mode)
  151. ("\\.slim\\'" slim-mode slim-mode)
  152. ("\\.styl\\'" stylus-mode stylus-mode)
  153. ("\\.swift\\'" swift-mode swift-mode)
  154. ("\\.textile\\'" textile-mode textile-mode)
  155. ("\\.thrift\\'" thrift thrift-mode)
  156. ("\\.yml\\'" yaml-mode yaml-mode)
  157. ("\\.yaml\\'" yaml-mode yaml-mode)
  158. ("Dockerfile\\'" dockerfile-mode dockerfile-mode)))
  159. ;; markdown-mode doesn't have autoloads for the auto-mode-alist
  160. ;; so we add them manually if it's already installed
  161. (when (package-installed-p 'markdown-mode)
  162. (add-to-list 'auto-mode-alist '("\\.markdown\\'" . gfm-mode))
  163. (add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode)))
  164. (when (package-installed-p 'pkgbuild-mode)
  165. (add-to-list 'auto-mode-alist '("PKGBUILD\\'" . pkgbuild-mode)))
  166. ;; build auto-install mappings
  167. (mapc
  168. (lambda (entry)
  169. (let ((extension (car entry))
  170. (package (cadr entry))
  171. (mode (cadr (cdr entry))))
  172. (unless (package-installed-p package)
  173. (prelude-auto-install extension package mode))))
  174. prelude-auto-install-alist)
  175. (provide 'prelude-packages)
  176. ;; Local Variables:
  177. ;; byte-compile-warnings: (not cl-functions)
  178. ;; End:
  179. ;;; prelude-packages.el ends here