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.

142 lines
5.1 KiB

13 years ago
14 years ago
  1. ;;; prelude-packages.el --- Emacs Prelude: default package selection.
  2. ;;
  3. ;; Copyright © 2011-2013 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" . "http://melpa.milkbox.net/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-jump-mode ack-and-a-half dash diminish elisp-slime-nav
  38. expand-region flx-ido flycheck gist
  39. git-commit-mode gitconfig-mode gitignore-mode grizzl
  40. guru-mode helm helm-projectile ido-ubiquitous
  41. key-chord magit rainbow-mode
  42. smartparens smex solarized-theme undo-tree
  43. volatile-highlights zenburn-theme)
  44. "A list of packages to ensure are installed at launch.")
  45. (defun prelude-packages-installed-p ()
  46. "Check if all packages in `prelude-packages' are installed."
  47. (every #'package-installed-p prelude-packages))
  48. (defun prelude-require-package (package)
  49. "Install PACKAGE unless already installed."
  50. (unless (package-installed-p package)
  51. (package-install package)))
  52. (defun prelude-require-packages (packages)
  53. "Ensure PACKAGES are installed.
  54. Missing packages are installed automatically."
  55. (mapc #'prelude-require-package packages))
  56. (defalias 'prelude-ensure-module-deps 'prelude-require-packages)
  57. (defun prelude-install-packages ()
  58. "Install all packages listed in `prelude-packages'."
  59. (unless (prelude-packages-installed-p)
  60. ;; check for new packages (package versions)
  61. (message "%s" "Emacs Prelude is now refreshing its package database...")
  62. (package-refresh-contents)
  63. (message "%s" " done.")
  64. ;; install the missing packages
  65. (prelude-require-packages prelude-packages)))
  66. (prelude-install-packages)
  67. (defmacro prelude-auto-install (extension package mode)
  68. "When file with EXTENSION is opened triggers auto-install of PACKAGE.
  69. PACKAGE is installed only if not already present. The file is opened in MODE."
  70. `(add-to-list 'auto-mode-alist
  71. `(,extension . (lambda ()
  72. (unless (package-installed-p ',package)
  73. (package-install ',package))
  74. (,mode)))))
  75. (defvar prelude-auto-install-alist
  76. '(("\\.clj\\'" clojure-mode clojure-mode)
  77. ("\\.coffee\\'" coffee-mode coffee-mode)
  78. ("\\.css\\'" css-mode css-mode)
  79. ("\\.csv\\'" csv-mode csv-mode)
  80. ("\\.d\\'" d-mode d-mode)
  81. ("\\.dart\\'" dart-mode dart-mode)
  82. ("\\.erl\\'" erlang erlang-mode)
  83. ("\\.feature\\'" feature-mode feature-mode)
  84. ("\\.go\\'" go-mode go-mode)
  85. ("\\.groovy\\'" groovy-mode groovy-mode)
  86. ("\\.haml\\'" haml-mode haml-mode)
  87. ("\\.hs\\'" haskell-mode haskell-mode)
  88. ("\\.latex\\'" auctex LaTeX-mode)
  89. ("\\.less\\'" less-css-mode less-css-mode)
  90. ("\\.lua\\'" lua-mode lua-mode)
  91. ("\\.markdown\\'" markdown-mode markdown-mode)
  92. ("\\.md\\'" markdown-mode markdown-mode)
  93. ("\\.ml\\'" tuareg tuareg-mode)
  94. ("\\.php\\'" php-mode php-mode)
  95. ("PKGBUILD\\'" pkgbuild-mode pkgbuild-mode)
  96. ("\\.sass\\'" sass-mode sass-mode)
  97. ("\\.scala\\'" scala-mode2 scala-mode)
  98. ("\\.scss\\'" scss-mode scss-mode)
  99. ("\\.slim\\'" slim-mode slim-mode)
  100. ("\\.textile\\'" textile-mode textile-mode)
  101. ("\\.yml\\'" yaml-mode yaml-mode)))
  102. ;; markdown-mode doesn't have autoloads for the auto-mode-alist
  103. ;; so we add them manually if it's already installed
  104. (when (package-installed-p 'markdown-mode)
  105. (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
  106. (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)))
  107. (when (package-installed-p 'pkgbuild-mode)
  108. (add-to-list 'auto-mode-alist '("PKGBUILD\\'" . pkgbuild-mode)))
  109. ;; build auto-install mappings
  110. (mapc
  111. (lambda (entry)
  112. (let ((extension (car entry))
  113. (package (cadr entry))
  114. (mode (cadr (cdr entry))))
  115. (unless (package-installed-p package)
  116. (prelude-auto-install extension package mode))))
  117. prelude-auto-install-alist)
  118. (provide 'prelude-packages)
  119. ;; Local Variables:
  120. ;; byte-compile-warnings: (not cl-functions)
  121. ;; End:
  122. ;;; prelude-packages.el ends here