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.

116 lines
3.8 KiB

13 years ago
  1. ;;; prelude-emacs-lisp.el --- Emacs Prelude: Nice config for Elisp programming.
  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. ;; Nice config for Elisp Programming.
  10. ;;; License:
  11. ;; This program is free software; you can redistribute it and/or
  12. ;; modify it under the terms of the GNU General Public License
  13. ;; as published by the Free Software Foundation; either version 3
  14. ;; of the License, or (at your option) any later version.
  15. ;;
  16. ;; This program is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; GNU General Public License for more details.
  20. ;;
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  23. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  24. ;; Boston, MA 02110-1301, USA.
  25. ;;; Code:
  26. (require 'prelude-lisp)
  27. (require 'crux)
  28. (prelude-require-packages '(elisp-slime-nav rainbow-mode))
  29. (defun prelude-recompile-elc-on-save ()
  30. "Recompile your elc when saving an elisp file."
  31. (add-hook 'after-save-hook
  32. (lambda ()
  33. (when (and
  34. (string-prefix-p prelude-dir (file-truename buffer-file-name))
  35. (file-exists-p (byte-compile-dest-file buffer-file-name)))
  36. (emacs-lisp-byte-compile)))
  37. nil
  38. t))
  39. (defun prelude-visit-ielm ()
  40. "Switch to default `ielm' buffer.
  41. Start `ielm' if it's not already running."
  42. (interactive)
  43. (crux-start-or-switch-to 'ielm "*ielm*"))
  44. (define-key emacs-lisp-mode-map (kbd "C-c C-z") 'prelude-visit-ielm)
  45. (define-key emacs-lisp-mode-map (kbd "C-c C-c") 'eval-defun)
  46. (define-key emacs-lisp-mode-map (kbd "C-c C-b") 'eval-buffer)
  47. (defun prelude-conditional-emacs-lisp-checker ()
  48. "Don't check doc style in Emacs Lisp test files."
  49. (let ((file-name (buffer-file-name)))
  50. (when (and file-name (string-match-p ".*-tests?\\.el\\'" file-name))
  51. (setq-local flycheck-checkers '(emacs-lisp)))))
  52. (defun prelude-emacs-lisp-mode-defaults ()
  53. "Sensible defaults for `emacs-lisp-mode'."
  54. (run-hooks 'prelude-lisp-coding-hook)
  55. (eldoc-mode +1)
  56. (prelude-recompile-elc-on-save)
  57. (rainbow-mode +1)
  58. (setq mode-name "EL")
  59. (prelude-conditional-emacs-lisp-checker))
  60. (setq prelude-emacs-lisp-mode-hook 'prelude-emacs-lisp-mode-defaults)
  61. (add-hook 'emacs-lisp-mode-hook (lambda ()
  62. (run-hooks 'prelude-emacs-lisp-mode-hook)))
  63. (add-to-list 'auto-mode-alist '("Cask\\'" . emacs-lisp-mode))
  64. ;; ielm is an interactive Emacs Lisp shell
  65. (defun prelude-ielm-mode-defaults ()
  66. "Sensible defaults for `ielm'."
  67. (run-hooks 'prelude-interactive-lisp-coding-hook)
  68. (eldoc-mode +1))
  69. (setq prelude-ielm-mode-hook 'prelude-ielm-mode-defaults)
  70. (add-hook 'ielm-mode-hook (lambda ()
  71. (run-hooks 'prelude-ielm-mode-hook)))
  72. (with-eval-after-load "elisp-slime-nav"
  73. (diminish 'elisp-slime-nav-mode))
  74. (with-eval-after-load "rainbow-mode"
  75. (diminish 'rainbow-mode))
  76. (with-eval-after-load "eldoc"
  77. (diminish 'eldoc-mode))
  78. (with-eval-after-load "ielm"
  79. (define-key ielm-map (kbd "M-(") (prelude-wrap-with "("))
  80. (define-key ielm-map (kbd "M-\"") (prelude-wrap-with "\"")))
  81. ;; enable elisp-slime-nav-mode
  82. (dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))
  83. (add-hook hook 'elisp-slime-nav-mode))
  84. (defun conditionally-enable-smartparens-mode ()
  85. "Enable `smartparens-mode' in the minibuffer, during `eval-expression'."
  86. (if (eq this-command 'eval-expression)
  87. (smartparens-mode 1)))
  88. (add-hook 'minibuffer-setup-hook 'conditionally-enable-smartparens-mode)
  89. (provide 'prelude-emacs-lisp)
  90. ;;; prelude-emacs-lisp.el ends here