-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-lisp.el
161 lines (119 loc) · 6 KB
/
init-lisp.el
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
(autoload 'turn-on-pretty-mode "pretty-mode")
;; ----------------------------------------------------------------------------
;; Paredit
;; ----------------------------------------------------------------------------
(autoload 'enable-paredit-mode "paredit")
;; {{
(setq scheme-program-name "guile")
(require 'quack)
;; }}
(defun maybe-map-paredit-newline ()
(unless (or (eq major-mode 'inferior-emacs-lisp-mode) (minibufferp))
(local-set-key (kbd "RET") 'paredit-newline)))
(add-hook 'paredit-mode-hook 'maybe-map-paredit-newline)
(eval-after-load 'paredit
'(progn
(diminish 'paredit-mode " Par")
;; These are handy everywhere, not just in lisp modes
(global-set-key (kbd "M-(") 'paredit-wrap-round)
(global-set-key (kbd "M-[") 'paredit-wrap-square)
(global-set-key (kbd "M-{") 'paredit-wrap-curly)
(global-set-key (kbd "M-)") 'paredit-close-round-and-newline)
(global-set-key (kbd "M-]") 'paredit-close-square-and-newline)
(global-set-key (kbd "M-}") 'paredit-close-curly-and-newline)
(dolist (binding (list (kbd "C-<left>") (kbd "C-<right>")
(kbd "C-M-<left>") (kbd "C-M-<right>")))
(define-key paredit-mode-map binding nil))
;; Disable kill-sentence, which is easily confused with the kill-sexp
;; binding, but doesn't preserve sexp structure
(define-key paredit-mode-map [remap kill-sentence] nil)
(define-key paredit-mode-map [remap backward-kill-sentence] nil)))
;; Use paredit in the minibuffer
(add-hook 'minibuffer-setup-hook 'conditionally-enable-paredit-mode)
(defvar paredit-minibuffer-commands '(eval-expression
pp-eval-expression
eval-expression-with-eldoc
ibuffer-do-eval
ibuffer-do-view-and-eval)
"Interactive commands for which paredit should be enabled in the minibuffer.")
(defun conditionally-enable-paredit-mode ()
"Enable paredit during lisp-related minibuffer commands."
(if (memq this-command paredit-minibuffer-commands)
(enable-paredit-mode)))
;; ----------------------------------------------------------------------------
;; Hippie-expand
;; ----------------------------------------------------------------------------
(defun set-up-hippie-expand-for-elisp ()
"Locally set `hippie-expand' completion functions for use with Emacs Lisp."
(make-local-variable 'hippie-expand-try-functions-list)
(add-to-list 'hippie-expand-try-functions-list 'try-complete-lisp-symbol t)
(add-to-list 'hippie-expand-try-functions-list 'try-complete-lisp-symbol-partially t))
;; ----------------------------------------------------------------------------
;; Automatic byte compilation
;; ----------------------------------------------------------------------------
;(auto-compile-on-save-mode 1)
;; TODO: also use auto-compile-on-load-mode
;; TODO: exclude .dir-locals.el
;; ----------------------------------------------------------------------------
;; Highlight current sexp
;; ----------------------------------------------------------------------------
;; Prevent flickery behaviour due to hl-sexp-mode unhighlighting before each command
(eval-after-load 'hl-sexp
'(defadvice hl-sexp-mode (after unflicker (turn-on) activate)
(when turn-on
(remove-hook 'pre-command-hook #'hl-sexp-unhighlight))))
;; ----------------------------------------------------------------------------
;; Enable desired features for all lisp modes
;; ----------------------------------------------------------------------------
(defun sanityinc/lisp-setup ()
"Enable features useful in any Lisp mode."
(enable-paredit-mode)
(turn-on-eldoc-mode))
(defun sanityinc/emacs-lisp-setup ()
"Enable features useful when working with elisp."
(rainbow-delimiters-mode t)
(set-up-hippie-expand-for-elisp)
;; (ac-emacs-lisp-mode-setup)
(checkdoc-minor-mode))
(let* ((elispy-hooks '(emacs-lisp-mode-hook
ielm-mode-hook))
(lispy-hooks (append elispy-hooks '(lisp-mode-hook
inferior-lisp-mode-hook
lisp-interaction-mode-hook))))
(dolist (hook lispy-hooks)
(add-hook hook 'sanityinc/lisp-setup))
(dolist (hook elispy-hooks)
(add-hook hook 'sanityinc/emacs-lisp-setup)))
(require 'eldoc-eval)
(add-to-list 'auto-mode-alist '("\\.emacs-project\\'" . emacs-lisp-mode))
(add-to-list 'auto-mode-alist '("archive-contents\\'" . emacs-lisp-mode))
(define-key emacs-lisp-mode-map (kbd "C-x C-a") 'pp-macroexpand-last-sexp)
;; ----------------------------------------------------------------------------
;; Delete .elc files when reverting the .el from VC or magit
;; ----------------------------------------------------------------------------
;; When .el files are open, we can intercept when they are modified
;; by VC or magit in order to remove .elc files that are likely to
;; be out of sync.
;; This is handy while actively working on elisp files, though
;; obviously it doesn't ensure that unopened files will also have
;; their .elc counterparts removed - VC hooks would be necessary for
;; that.
(defvar sanityinc/vc-reverting nil
"Whether or not VC or Magit is currently reverting buffers.")
(defadvice revert-buffer (after sanityinc/maybe-remove-elc activate)
"If reverting from VC, delete any .elc file that will now be out of sync."
(when sanityinc/vc-reverting
(when (and (eq 'emacs-lisp-mode major-mode)
buffer-file-name
(string= "el" (file-name-extension buffer-file-name)))
(let ((elc (concat buffer-file-name "c")))
(when (file-exists-p elc)
(message "Removing out-of-sync elc file %s" (file-name-nondirectory elc))
(delete-file elc))))))
(defadvice magit-revert-buffers (around sanityinc/reverting activate)
(let ((sanityinc/vc-reverting t))
ad-do-it))
(defadvice vc-revert-buffer-internal (around sanityinc/reverting activate)
(let ((sanityinc/vc-reverting t))
ad-do-it))
(provide 'init-lisp)