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.

120 lines
3.9 KiB

13 years ago
  1. ;;; prelude-emacs-lisp.el --- Emacs Prelude: Nice config for Elisp programming.
  2. ;;
  3. ;; Copyright © 2011-2017 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. ;; Package-Requires: ((prelude-lisp "1.0.0"))
  10. ;; This file is not part of GNU Emacs.
  11. ;;; Commentary:
  12. ;; Nice config for Elisp Programming.
  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 'prelude-lisp)
  30. (require 'crux)
  31. (prelude-require-packages '(elisp-slime-nav rainbow-mode))
  32. (defun prelude-recompile-elc-on-save ()
  33. "Recompile your elc when saving an elisp file."
  34. (add-hook 'after-save-hook
  35. (lambda ()
  36. (when (and
  37. (string-prefix-p prelude-dir (file-truename buffer-file-name))
  38. (file-exists-p (byte-compile-dest-file buffer-file-name)))
  39. (emacs-lisp-byte-compile)))
  40. nil
  41. t))
  42. (defun prelude-visit-ielm ()
  43. "Switch to default `ielm' buffer.
  44. Start `ielm' if it's not already running."
  45. (interactive)
  46. (crux-start-or-switch-to 'ielm "*ielm*"))
  47. (define-key emacs-lisp-mode-map (kbd "C-c C-z") 'prelude-visit-ielm)
  48. (define-key emacs-lisp-mode-map (kbd "C-c C-c") 'eval-defun)
  49. (define-key emacs-lisp-mode-map (kbd "C-c C-b") 'eval-buffer)
  50. (defun prelude-conditional-emacs-lisp-checker ()
  51. "Don't check doc style in Emacs Lisp test files."
  52. (let ((file-name (buffer-file-name)))
  53. (when (and file-name (string-match-p ".*-tests?\\.el\\'" file-name))
  54. (setq-local flycheck-checkers '(emacs-lisp)))))
  55. (defun prelude-emacs-lisp-mode-defaults ()
  56. "Sensible defaults for `emacs-lisp-mode'."
  57. (run-hooks 'prelude-lisp-coding-hook)
  58. (eldoc-mode +1)
  59. (prelude-recompile-elc-on-save)
  60. (rainbow-mode +1)
  61. (setq mode-name "EL")
  62. (prelude-conditional-emacs-lisp-checker))
  63. (setq prelude-emacs-lisp-mode-hook 'prelude-emacs-lisp-mode-defaults)
  64. (add-hook 'emacs-lisp-mode-hook (lambda ()
  65. (run-hooks 'prelude-emacs-lisp-mode-hook)))
  66. (add-to-list 'auto-mode-alist '("Cask\\'" . emacs-lisp-mode))
  67. ;; ielm is an interactive Emacs Lisp shell
  68. (defun prelude-ielm-mode-defaults ()
  69. "Sensible defaults for `ielm'."
  70. (run-hooks 'prelude-interactive-lisp-coding-hook)
  71. (eldoc-mode +1))
  72. (setq prelude-ielm-mode-hook 'prelude-ielm-mode-defaults)
  73. (add-hook 'ielm-mode-hook (lambda ()
  74. (run-hooks 'prelude-ielm-mode-hook)))
  75. (eval-after-load "elisp-slime-nav"
  76. '(diminish 'elisp-slime-nav-mode))
  77. (eval-after-load "rainbow-mode"
  78. '(diminish 'rainbow-mode))
  79. (eval-after-load "eldoc"
  80. '(diminish 'eldoc-mode))
  81. (eval-after-load "ielm"
  82. '(progn
  83. (define-key ielm-map (kbd "M-(") (prelude-wrap-with "("))
  84. (define-key ielm-map (kbd "M-\"") (prelude-wrap-with "\""))))
  85. ;; enable elisp-slime-nav-mode
  86. (dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))
  87. (add-hook hook 'elisp-slime-nav-mode))
  88. (defun conditionally-enable-smartparens-mode ()
  89. "Enable `smartparens-mode' in the minibuffer, during `eval-expression'."
  90. (if (eq this-command 'eval-expression)
  91. (smartparens-mode 1)))
  92. (add-hook 'minibuffer-setup-hook 'conditionally-enable-smartparens-mode)
  93. (provide 'prelude-emacs-lisp)
  94. ;;; prelude-emacs-lisp.el ends here