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.

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