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.

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