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.2 KiB

12 years ago
9 years ago
9 years ago
11 years ago
  1. ;;; prelude-packages.el --- Emacs Prelude: default package selection.
  2. ;;
  3. ;; Copyright © 2011-2020 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar@batsov.com>
  6. ;; URL: https://github.com/bbatsov/prelude
  7. ;; This file is not part of GNU Emacs.
  8. ;;; Commentary:
  9. ;; Takes care of the automatic installation of all the packages required by
  10. ;; Emacs Prelude. This module also adds a couple of package.el extensions
  11. ;; and provides functionality for auto-installing major modes on demand.
  12. ;;; License:
  13. ;; This program is free software; you can redistribute it and/or
  14. ;; modify it under the terms of the GNU General Public License
  15. ;; as published by the Free Software Foundation; either version 3
  16. ;; of the License, or (at your option) any later version.
  17. ;;
  18. ;; This program is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;;
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  25. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  26. ;; Boston, MA 02110-1301, USA.
  27. ;;; Code:
  28. (require 'cl-lib)
  29. (require 'package)
  30. ;;;; Package setup and additional utility functions
  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. ag
  48. avy
  49. anzu
  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. guru-mode
  65. hl-todo
  66. imenu-anywhere
  67. projectile
  68. magit
  69. move-text
  70. nlinum
  71. operate-on-number
  72. smartparens
  73. smartrep
  74. super-save
  75. undo-tree
  76. volatile-highlights
  77. which-key
  78. zenburn-theme
  79. zop-to-char)
  80. "A list of packages to ensure are installed at launch.")
  81. (defun prelude-packages-installed-p ()
  82. "Check if all packages in `prelude-packages' are installed."
  83. (cl-every #'package-installed-p prelude-packages))
  84. (defun prelude-require-package (package)
  85. "Install PACKAGE unless already installed."
  86. (unless (memq package prelude-packages)
  87. (add-to-list 'prelude-packages package))
  88. (unless (package-installed-p package)
  89. (package-install package)))
  90. (defun prelude-require-packages (packages)
  91. "Ensure PACKAGES are installed.
  92. Missing packages are installed automatically."
  93. (mapc #'prelude-require-package packages))
  94. (defun prelude-install-packages ()
  95. "Install all packages listed in `prelude-packages'."
  96. (unless (prelude-packages-installed-p)
  97. ;; check for new packages (package versions)
  98. (message "%s" "Emacs Prelude is now refreshing its package database...")
  99. (package-refresh-contents)
  100. (message "%s" " done.")
  101. ;; install the missing packages
  102. (prelude-require-packages prelude-packages)))
  103. ;; run package installation
  104. (prelude-install-packages)
  105. (defun prelude-list-foreign-packages ()
  106. "Browse third-party packages not bundled with Prelude.
  107. Behaves similarly to `package-list-packages', but shows only the packages that
  108. are installed and are not in `prelude-packages'. Useful for
  109. removing unwanted packages."
  110. (interactive)
  111. (package-show-package-list
  112. (cl-set-difference package-activated-list prelude-packages)))
  113. ;;;; Auto-installation of major modes on demand
  114. (defmacro prelude-auto-install (extension package mode)
  115. "When file with EXTENSION is opened triggers auto-install of PACKAGE.
  116. PACKAGE is installed only if not already present. The file is opened in MODE."
  117. `(add-to-list 'auto-mode-alist
  118. `(,extension . (lambda ()
  119. (unless (package-installed-p ',package)
  120. (package-install ',package))
  121. (,mode)))))
  122. (defvar prelude-auto-install-alist
  123. '(("\\.clj\\'" clojure-mode clojure-mode)
  124. ("\\.cmake\\'" cmake-mode cmake-mode)
  125. ("CMakeLists\\.txt\\'" cmake-mode cmake-mode)
  126. ("\\.coffee\\'" coffee-mode coffee-mode)
  127. ("\\.css\\'" css-mode css-mode)
  128. ("\\.csv\\'" csv-mode csv-mode)
  129. ("Cask" cask-mode cask-mode)
  130. ("\\.d\\'" d-mode d-mode)
  131. ("\\.dart\\'" dart-mode dart-mode)
  132. ("\\.elm\\'" elm-mode elm-mode)
  133. ("\\.ex\\'" elixir-mode elixir-mode)
  134. ("\\.exs\\'" elixir-mode elixir-mode)
  135. ("\\.elixir\\'" elixir-mode elixir-mode)
  136. ("\\.erl\\'" erlang erlang-mode)
  137. ("\\.feature\\'" feature-mode feature-mode)
  138. ("\\.go\\'" go-mode go-mode)
  139. ("\\.graphql\\'" graphql-mode graphql-mode)
  140. ("\\.groovy\\'" groovy-mode groovy-mode)
  141. ("\\.haml\\'" haml-mode haml-mode)
  142. ("\\.hs\\'" haskell-mode haskell-mode)
  143. ("\\.json\\'" json-mode json-mode)
  144. ("\\.kt\\'" kotlin-mode kotlin-mode)
  145. ("\\.kv\\'" kivy-mode kivy-mode)
  146. ("\\.latex\\'" auctex LaTeX-mode)
  147. ("\\.less\\'" less-css-mode less-css-mode)
  148. ("\\.lua\\'" lua-mode lua-mode)
  149. ("\\.markdown\\'" markdown-mode markdown-mode)
  150. ("\\.md\\'" markdown-mode markdown-mode)
  151. ("\\.ml\\'" tuareg tuareg-mode)
  152. ("\\.pp\\'" puppet-mode puppet-mode)
  153. ("\\.php\\'" php-mode php-mode)
  154. ("\\.proto\\'" protobuf-mode protobuf-mode)
  155. ("\\.pyd\\'" cython-mode cython-mode)
  156. ("\\.pyi\\'" cython-mode cython-mode)
  157. ("\\.pyx\\'" cython-mode cython-mode)
  158. ("PKGBUILD\\'" pkgbuild-mode pkgbuild-mode)
  159. ("\\.rs\\'" rust-mode rust-mode)
  160. ("\\.sass\\'" sass-mode sass-mode)
  161. ("\\.scala\\'" scala-mode scala-mode)
  162. ("\\.scss\\'" scss-mode scss-mode)
  163. ("\\.slim\\'" slim-mode slim-mode)
  164. ("\\.styl\\'" stylus-mode stylus-mode)
  165. ("\\.swift\\'" swift-mode swift-mode)
  166. ("\\.textile\\'" textile-mode textile-mode)
  167. ("\\.thrift\\'" thrift thrift-mode)
  168. ("\\.yml\\'" yaml-mode yaml-mode)
  169. ("\\.yaml\\'" yaml-mode yaml-mode)
  170. ("Dockerfile\\'" dockerfile-mode dockerfile-mode)))
  171. ;; markdown-mode doesn't have autoloads for the auto-mode-alist
  172. ;; so we add them manually if it's already installed
  173. (when (package-installed-p 'markdown-mode)
  174. (add-to-list 'auto-mode-alist '("\\.markdown\\'" . gfm-mode))
  175. (add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode)))
  176. (when (package-installed-p 'pkgbuild-mode)
  177. (add-to-list 'auto-mode-alist '("PKGBUILD\\'" . pkgbuild-mode)))
  178. ;; build auto-install mappings
  179. (mapc
  180. (lambda (entry)
  181. (let ((extension (car entry))
  182. (package (cadr entry))
  183. (mode (cadr (cdr entry))))
  184. (unless (package-installed-p package)
  185. (prelude-auto-install extension package mode))))
  186. prelude-auto-install-alist)
  187. (provide 'prelude-packages)
  188. ;; Local Variables:
  189. ;; byte-compile-warnings: (not cl-functions)
  190. ;; End:
  191. ;;; prelude-packages.el ends here