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.

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