forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-lisp.el
155 lines (114 loc) · 5.18 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
(require-package 'elisp-slime-nav)
(require-package 'lively)
(require-package 'pretty-mode)
(autoload 'turn-on-pretty-mode "pretty-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
;; ----------------------------------------------------------------------------
(require-package 'auto-compile)
(auto-compile-on-save-mode 1)
(auto-compile-on-load-mode 1)
;; ----------------------------------------------------------------------------
;; Highlight current sexp
;; ----------------------------------------------------------------------------
(require-package 'hl-sexp)
;; Prevent flickery behaviour due to hl-sexp-mode unhighlighting before each command
(eval-after-load 'hl-sexp
'(defadvice hl-sexp-mode (after unflicker (&optional turn-on) activate)
(when turn-on
(remove-hook 'pre-command-hook #'hl-sexp-unhighlight))))
;;; Support byte-compilation in a sub-process, as
;;; required by highlight-cl
(defun sanityinc/byte-compile-file-batch (filename)
"Byte-compile FILENAME in batch mode, ie. a clean sub-process."
(interactive "fFile to byte-compile in batch mode: ")
(let ((emacs (car command-line-args)))
(compile
(concat
emacs " "
(mapconcat
'shell-quote-argument
(list "-Q" "-batch" "-f" "batch-byte-compile" filename)
" ")))))
;; ----------------------------------------------------------------------------
;; Enable desired features for all lisp modes
;; ----------------------------------------------------------------------------
(require-package 'rainbow-delimiters)
(require-package 'redshank)
(eval-after-load 'redshank
'(diminish 'redshank-mode))
(defun sanityinc/lisp-setup ()
"Enable features useful in any Lisp mode."
(rainbow-delimiters-mode t)
(enable-paredit-mode)
(turn-on-eldoc-mode)
(redshank-mode))
(defun sanityinc/emacs-lisp-setup ()
"Enable features useful when working with elisp."
(elisp-slime-nav-mode t)
(set-up-hippie-expand-for-elisp)
(ac-emacs-lisp-mode-setup)
(checkdoc-minor-mode))
(defconst sanityinc/elispy-modes
'(emacs-lisp-mode ielm-mode)
"Major modes relating to elisp.")
(defconst sanityinc/lispy-modes
(append sanityinc/elispy-modes
'(lisp-mode inferior-lisp-mode lisp-interaction-mode))
"All lispy major modes.")
(require 'derived)
(dolist (hook (mapcar #'derived-mode-hook-name sanityinc/lispy-modes))
(add-hook hook 'sanityinc/lisp-setup))
(dolist (hook (mapcar #'derived-mode-hook-name sanityinc/elispy-modes))
(add-hook hook 'sanityinc/emacs-lisp-setup))
(defun sanityinc/maybe-check-parens ()
"Run `check-parens' if this is a lispy mode."
(when (memq major-mode sanityinc/lispy-modes)
(check-parens)))
(add-hook 'after-save-hook #'sanityinc/maybe-check-parens)
(require-package 'eldoc-eval)
(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)
(define-key emacs-lisp-mode-map (kbd "C-x C-e") 'pp-eval-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))
(require-package 'macrostep)
(eval-after-load 'lisp-mode
'(define-key emacs-lisp-mode-map (kbd "C-c e") 'macrostep-expand))
(provide 'init-lisp)