init-emacs-lisp.el 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ;;; init-emacs-lisp.el --- Emacs Lisp Configuration File -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;; Based on prelude-emacs-lisp.el
  4. ;;; Code:
  5. (use-feature eldoc
  6. :diminish)
  7. (use-package elisp-slime-nav
  8. :diminish)
  9. (use-feature emacs
  10. :custom
  11. ;; These don't really belong here, but do affect ielm
  12. (comint-prompt-read-only t)
  13. (comint-buffer-maximum-size 2048)
  14. :config
  15. ;; Based on prelude-emacs-lisp.el
  16. (defun recompile-init-lisp ()
  17. "Recompile elisp files in `user-emacs-directory/lisp'."
  18. (interactive)
  19. (when (and
  20. (string-prefix-p (expand-file-name "lisp" user-emacs-directory) (file-truename buffer-file-name))
  21. (file-exists-p (byte-compile-dest-file buffer-file-name)))
  22. (emacs-lisp-byte-compile)))
  23. (defun recompile-init-lisp-on-save ()
  24. "Recompile your elc when saving an elisp file. (Adds buffer-local hook)."
  25. (add-hook 'after-save-hook 'recompile-init-lisp nil t))
  26. ;; From prelude-emacs-lisp.el
  27. (defun visit-ielm ()
  28. "Switch to default `ielm' buffer.
  29. Start `ielm' if it's not already running."
  30. (interactive)
  31. (crux-start-or-switch-to 'ielm "*ielm*"))
  32. ;; from https://www.n16f.net/blog/making-ielm-more-comfortable/
  33. (defun ielm-init-history ()
  34. (let ((path (expand-file-name "ielm/history" user-emacs-directory)))
  35. (make-directory (file-name-directory path) t)
  36. (setq-local comint-input-ring-file-name path))
  37. (setq-local comint-input-ring-size 10000)
  38. (setq-local comint-input-ignoredups t)
  39. (comint-read-input-ring))
  40. (defun ielm-write-history (&rest _args)
  41. (with-file-modes #o600
  42. (comint-write-input-ring)))
  43. :hook
  44. (ielm-mode . (lambda ()
  45. (eldoc-mode +1)
  46. (ielm-init-history)
  47. (advice-add 'ielm-send-input :after 'ielm-write-history)))
  48. (emacs-lisp-mode . (lambda ()
  49. (eldoc-mode +1)
  50. (setq mode-name "EL")
  51. (recompile-init-lisp-on-save)))
  52. :bind
  53. (:map emacs-lisp-mode-map
  54. (("C-c C-z" . visit-ielm)
  55. ("C-c C-c" . eval-defun)
  56. ("C-c C-k" . eval-buffer)
  57. ("C-c e f" . emacs-lisp-byte-compile-and-load)
  58. ("C-c e z" . byte-recompile-directory)
  59. ("C-c e c" . cancel-debug-on-entry)
  60. ("C-c e d" . debug-on-entry)
  61. ("C-c e e" . toggle-debug-on-error))))
  62. (use-package eros
  63. :config
  64. ;; https://xenodium.com/inline-previous-result-and-why-you-should-edebug/
  65. (defun adviced:edebug-previous-result (_ &rest r)
  66. "Adviced `edebug-previous-result'."
  67. (eros--make-result-overlay edebug-previous-result
  68. :where (point)
  69. :duration eros-eval-result-duration))
  70. (advice-add #'edebug-previous-result
  71. :around
  72. #'adviced:edebug-previous-result)
  73. :hook
  74. (emacs-lisp-mode . eros-mode))
  75. (use-package erefactor
  76. :hook (emacs-lisp-mode . (lambda () (define-key emacs-lisp-mode-map "\C-c\C-v" erefactor-map))))
  77. (use-package flycheck-package
  78. :hook
  79. (emacs-lisp-mode . flycheck-package-setup))
  80. (use-package elsa)
  81. (use-package flycheck-elsa
  82. :hook
  83. (emacs-lisp-mode . flycheck-elsa-setup))
  84. (provide 'init-emacs-lisp)
  85. ;;; init-emacs-lisp.el ends here