aboutsummaryrefslogtreecommitdiffstats
path: root/oni-elisp.el
blob: 152061d4f4c71ac95932ed984cc3508a758fb5d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
;;; oni-elisp.el --- Emacs Lisp configuration        -*- lexical-binding: t; -*-

;; Copyright (C) 2019  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
;; Version: 2026.0527.003032
;; Package-Requires: (oni-company oni-flycheck oni-paredit oni-hydra rainbow-delimiters nameless erefactor flycheck-relint elisp-format)

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; My configuration for working in Emacs Lisp.

;;; Code:

(require 'checkdoc)
(require 'flycheck-relint)
(require 'hydra)

(let ((byte-compile-not-obsolete-funcs '(preceding-sexp)))
  (require 'erefactor))

(require 'ielm)

(defconst oni-elisp-root
  (file-name-directory
   (or load-file-name
       (buffer-file-name)))
  "The directory where ‘oni-elisp’ was loaded from.")

(font-lock-add-keywords
 'emacs-lisp-mode
 `((,(rx symbol-start
         (group (or "t"
                    "nil"
                    (and (optional "-")
                         digit
                         (minimal-match (zero-or-more (any digit ?.))))))
         symbol-end)
    1 font-lock-constant-face)))

(defun oni-elisp-auto-fill-mode ()
  "Enable ‘auto-fill-mode’ only for comments and inhibit for Package-Requires."
  (setq-local comment-auto-fill-only-comments t)
  (setq-local auto-fill-inhibit-regexp (rx line-start ";; Package-Requires: "))
  (auto-fill-mode))

(defun oni-elisp-setup-ielm-mode-line ()
  "Clean up the mode-line for ielm buffers."
  (setq mode-line-buffer-identification
        (list (propertize "Interactive Emacs Lisp Mode" 'face 'mode-line-buffer-id))
        mode-line-format
        '("%e"
          mode-line-front-space
          mode-line-remote
          mode-line-frame-identification
          mode-line-buffer-identification
          " on "
          (:eval (buffer-name ielm-working-buffer))
          mode-line-end-spaces)))

(defun oni-elisp-ielm-remove-paredit-newline-keys ()
  "Disable ‘C-j’ and ‘RET’ keybindings from ‘paredit-mode’."
  (let ((oldmap (map-elt minor-mode-map-alist 'paredit-mode))
        (newmap (make-sparse-keymap)))
    (set-keymap-parent newmap oldmap)
    (define-key newmap (kbd "RET") nil)
    (define-key newmap (kbd "C-j") nil)
    (make-local-variable 'minor-mode-overriding-map-alist)
    (push `(paredit-mode . ,newmap) minor-mode-overriding-map-alist)))

(defhydra oni-elisp-hydra (:color teal :hint nil)
  "
^Eval^
^^----------
_eb_: Buffer
"
  ("eb" eval-buffer))

(add-hook 'emacs-lisp-mode-hook #'oni-elisp-auto-fill-mode)
(add-hook 'emacs-lisp-mode-hook 'company-mode)
(add-hook 'emacs-lisp-mode-hook 'display-fill-column-indicator-mode)
(add-hook 'emacs-lisp-mode-hook 'electric-quote-local-mode)
(add-hook 'emacs-lisp-mode-hook 'erefactor-lazy-highlight-turn-on)
(add-hook 'emacs-lisp-mode-hook 'flycheck-mode)
(add-hook 'emacs-lisp-mode-hook 'nameless-mode)
(add-hook 'emacs-lisp-mode-hook 'paredit-mode)
(add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode)

(add-hook 'ielm-mode-hook #'oni-elisp-ielm-remove-paredit-newline-keys)
(add-hook 'ielm-mode-hook #'oni-elisp-setup-ielm-mode-line)
(add-hook 'ielm-mode-hook 'company-mode)
(add-hook 'ielm-mode-hook 'paredit-mode)

(setq ielm-prompt "λ> ")

(define-key emacs-lisp-mode-map (kbd "C-c r") erefactor-map)
(define-key emacs-lisp-mode-map (kbd "C-c SPC") 'oni-elisp-hydra/body)

;;;###autoload
(add-to-list 'auto-mode-alist '("/Cask\\'" . emacs-lisp-mode))

(add-to-list 'display-buffer-alist
             '("\\`\\*ielm\\*\\'" display-buffer-in-side-window
               (side . bottom)
               (slot . 0)
               (window-height . 0.33)))

(flycheck-relint-setup)

(add-hook 'emacs-lisp-mode-hook 'checkdoc-minor-mode)

(setq checkdoc-spellcheck-documentation-flag t)

(provide 'oni-elisp)
;;; oni-elisp.el ends here