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.

210 lines
6.8 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. (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. )
  37. ;; set package-user-dir to be relative to Prelude install path
  38. (setq package-user-dir (expand-file-name "elpa" prelude-dir))
  39. (package-initialize)
  40. (defvar prelude-packages
  41. '(ace-window
  42. avy
  43. anzu
  44. beacon
  45. browse-kill-ring
  46. crux
  47. dash
  48. discover-my-major
  49. diff-hl
  50. diminish
  51. easy-kill
  52. editorconfig
  53. epl
  54. expand-region
  55. flycheck
  56. gist
  57. git-timemachine
  58. gitconfig-mode
  59. gitignore-mode
  60. god-mode
  61. grizzl
  62. guru-mode
  63. imenu-anywhere
  64. ov
  65. projectile
  66. magit
  67. move-text
  68. operate-on-number
  69. smart-mode-line
  70. smartparens
  71. smartrep
  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. (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. (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. ("\\.groovy\\'" groovy-mode groovy-mode)
  137. ("\\.haml\\'" haml-mode haml-mode)
  138. ("\\.hs\\'" haskell-mode haskell-mode)
  139. ("\\.json\\'" json-mode json-mode)
  140. ("\\.kt\\'" kotlin-mode kotlin-mode)
  141. ("\\.kv\\'" kivy-mode kivy-mode)
  142. ("\\.latex\\'" auctex LaTeX-mode)
  143. ("\\.less\\'" less-css-mode less-css-mode)
  144. ("\\.lua\\'" lua-mode lua-mode)
  145. ("\\.markdown\\'" markdown-mode markdown-mode)
  146. ("\\.md\\'" markdown-mode markdown-mode)
  147. ("\\.ml\\'" tuareg tuareg-mode)
  148. ("\\.pp\\'" puppet-mode puppet-mode)
  149. ("\\.php\\'" php-mode php-mode)
  150. ("\\.proto\\'" protobuf-mode protobuf-mode)
  151. ("\\.pyd\\'" cython-mode cython-mode)
  152. ("\\.pyi\\'" cython-mode cython-mode)
  153. ("\\.pyx\\'" cython-mode cython-mode)
  154. ("PKGBUILD\\'" pkgbuild-mode pkgbuild-mode)
  155. ("\\.rs\\'" rust-mode rust-mode)
  156. ("\\.sass\\'" sass-mode sass-mode)
  157. ("\\.scala\\'" scala-mode scala-mode)
  158. ("\\.scss\\'" scss-mode scss-mode)
  159. ("\\.slim\\'" slim-mode slim-mode)
  160. ("\\.styl\\'" stylus-mode stylus-mode)
  161. ("\\.swift\\'" swift-mode swift-mode)
  162. ("\\.textile\\'" textile-mode textile-mode)
  163. ("\\.thrift\\'" thrift thrift-mode)
  164. ("\\.yml\\'" yaml-mode yaml-mode)
  165. ("\\.yaml\\'" yaml-mode yaml-mode)
  166. ("Dockerfile\\'" dockerfile-mode dockerfile-mode)))
  167. ;; markdown-mode doesn't have autoloads for the auto-mode-alist
  168. ;; so we add them manually if it's already installed
  169. (when (package-installed-p 'markdown-mode)
  170. (add-to-list 'auto-mode-alist '("\\.markdown\\'" . gfm-mode))
  171. (add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode)))
  172. (when (package-installed-p 'pkgbuild-mode)
  173. (add-to-list 'auto-mode-alist '("PKGBUILD\\'" . pkgbuild-mode)))
  174. ;; build auto-install mappings
  175. (mapc
  176. (lambda (entry)
  177. (let ((extension (car entry))
  178. (package (cadr entry))
  179. (mode (cadr (cdr entry))))
  180. (unless (package-installed-p package)
  181. (prelude-auto-install extension package mode))))
  182. prelude-auto-install-alist)
  183. (provide 'prelude-packages)
  184. ;; Local Variables:
  185. ;; byte-compile-warnings: (not cl-functions)
  186. ;; End:
  187. ;;; prelude-packages.el ends here