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.

217 lines
7.1 KiB

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