-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
307 lines (232 loc) · 8.15 KB
/
init.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
;; A minimial setup for Clojurians
(require 'package)
;; Define package repositories
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
;; Load and activate emacs packages. Do this first so that the
;; packages are loaded before you start trying to modify them.
;; This also sets the load path.
(package-initialize)
;; Automatically reload files when they change on disk
(global-auto-revert-mode 1)
(setq auto-revert-verbose nil)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)
(column-number-mode 1)
;; Install use-package
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
(setq use-package-verbose t)
(setq-default use-package-always-ensure t)
;; Show full file path in the title bar
(setq
frame-title-format
'((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))))
;; Use y/n instead of full yes/no for confirmation messages
(fset 'yes-or-no-p 'y-or-n-p)
;; Line numbers
(global-linum-mode t)
;; Remove trailing whitespace before saving
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; M-x with recently/frequently used commands
(use-package smex)
(global-set-key (kbd "M-x") 'smex)
;; On OS X, an Emacs instance started from the graphical user
;; interface will have a different environment than a shell in a
;; terminal window, because OS X does not run a shell during the
;; login. Obviously this will lead to unexpected results when
;; calling external utilities like make from Emacs.
;; This library works around this problem by copying important
;; environment variables from the user's shell.
;; https://github.com/purcell/exec-path-from-shell
(use-package exec-path-from-shell
:ensure t
:config
(exec-path-from-shell-initialize))
;; Move custom configuration variables set by Emacs, to a seperate file
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)
;; Install and setup company-mode for autocompletion
(use-package company
:ensure t
:init
(add-hook 'prog-mode-hook 'company-mode)
:config
(global-company-mode)
(setq company-tooltip-limit 10)
(setq company-idle-delay 0.2)
(setq company-echo-delay 0)
(setq company-minimum-prefix-length 3)
(setq company-require-match nil)
(setq company-selection-wrap-around t)
(setq company-tooltip-align-annotations t)
(setq company-tooltip-flip-when-above t)
;; weight by frequency
(setq company-transformers '(company-sort-by-occurrence)))
;; Better syntax highlighting
(use-package clojure-mode-extra-font-locking
:ensure t)
;; Highlight matching parentheses
(require 'paren)
(show-paren-mode 1)
(setq show-paren-delay 1)
(set-face-background 'show-paren-match (face-background 'default))
(if (eq (frame-parameter nil 'background-mode) 'dark)
(set-face-foreground 'show-paren-match "red")
(set-face-foreground 'show-paren-match "black"))
(set-face-attribute 'show-paren-match nil :weight 'extra-bold)
;; Add ability to shift between buffers using shift+arrow keys.
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings))
;; Paredit makes it easier to navigate/edit s-expressions as blocks.
(use-package paredit
:ensure t
:init
(add-hook 'clojure-mode-hook 'enable-paredit-mode)
(add-hook 'cider-repl-mode-hook 'enable-paredit-mode))
;; To add some colors to those boring parens
(use-package rainbow-delimiters
:ensure t
:init (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
;; Cider integrates a Clojure buffer with a REPL
(use-package cider
:ensure t
:pin melpa-stable
:init
(setq cider-repl-pop-to-buffer-on-connect t
cider-show-error-buffer t
cider-auto-select-error-buffer t
cider-repl-history-file "~/.emacs.d/cider-history"
cider-repl-wrap-history t
cider-repl-history-size 100
cider-repl-use-clojure-font-lock t
cider-docview-fill-column 70
cider-stacktrace-fill-column 76
;; Stop error buffer from popping up while working in buffers other than REPL:
nrepl-popup-stacktraces nil
nrepl-log-messages t
nrepl-hide-special-buffers nil
cider-repl-use-pretty-printing t
cider-repl-result-prefix ";; => ")
:config
(global-set-key (kbd "C-c k") 'cider-repl-clear-buffer)
(add-hook 'cider-mode-hook #'eldoc-mode)
(add-hook 'cider-repl-mode-hook #'paredit-mode)
(add-hook 'cider-repl-mode-hook #'company-mode)
(add-hook 'cider-mode-hook #'company-mode)
(add-hook 'cider-mode-hook
(local-set-key (kbd "<C-return>") 'cider-eval-defun-at-point)))
;; Adds some niceties/refactoring support
(use-package clj-refactor
:ensure t
:config
(add-hook 'clojure-mode-hook
(lambda ()
(clj-refactor-mode 1))))
;; Aggressively indents your clojure code
(use-package aggressive-indent
:ensure t
:commands (aggressive-indent-mode)
:config
(add-hook 'clojure-mode-hook 'aggressive-indent-mode))
;; Operate (list, search, replace....) on files at a project level.
(use-package projectile
:ensure t
:init
(setq-default projectile-cache-file
(expand-file-name ".projectile-cache" user-emacs-directory))
(add-hook 'prog-mode-hook #'projectile-mode)
:config
(projectile-mode)
(setq-default projectile-enable-caching t
;; Show project (if any) name in modeline
projectile-mode-line '(:eval (projectile-project-name)))
(projectile-global-mode t))
;; Magit: The only git interface you'll ever need
(use-package magit :ensure t)
;; User customizations
(when (file-exists-p "~/.emacs.d/init-user.el")
(setq user-custom-file "~/.emacs.d/init-user.el")
(load user-custom-file))
(tool-bar-mode -1)
(toggle-scroll-bar -1)
(defun back-to-indentation-or-beginning () (interactive)
(if (= (point) (progn (back-to-indentation) (point)))
(beginning-of-line)))
(defun indent-buffer ()
"Indent the currently visited buffer."
(interactive)
(indent-region (point-min) (point-max)))
(defun indent-region-or-buffer ()
"Indent a region if selected, otherwise the whole buffer."
(interactive)
(save-excursion
(if (region-active-p)
(progn (indent-region (region-beginning) (region-end)))
(progn (indent-buffer)))))
(global-set-key (kbd "C-c n") 'indent-region-or-buffer)
(defun move-line-up ()
(interactive)
(transpose-lines 1)
(forward-line -2))
(defun move-line-down ()
(interactive)
(forward-line 1)
(transpose-lines 1)
(forward-line -1))
(global-set-key (kbd "M-S-<up>") 'move-line-up)
(global-set-key (kbd "M-S-<down>") 'move-line-down)
(defun kill-other-buffers ()
"Kill all other buffers."
(interactive)
(mapc 'kill-buffer
(delq (current-buffer)
(remove-if-not 'buffer-file-name (buffer-list)))))
(global-set-key (kbd "C-a") 'back-to-indentation-or-beginning)
(global-set-key (kbd "RET") 'newline-and-indent)
(use-package expand-region
:ensure t
:config
(global-set-key (kbd "C-=") 'er/expand-region))
(use-package undo-tree
:ensure t
:config
(global-undo-tree-mode t))
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(global-hl-line-mode)
;; Disables audio bell
(setq ring-bell-function
(lambda () (message "*beep*")))
;; Set default font
(set-default-font "Inconsolata 16")
(use-package helm-projectile
:ensure t
:config
(global-set-key (kbd "s-t") 'helm-projectile))
(use-package align-cljlet
:ensure t)
(defun unfill-paragraph (&optional region)
"Takes a multi-line paragraph and makes it into a single line of text."
(interactive (progn (barf-if-buffer-read-only) '(t)))
(let ((fill-column (point-max))
;; This would override `fill-column' if it's an integer.
(emacs-lisp-docstring-fill-column t))
(fill-paragraph nil region)))
(define-key global-map "\M-Q" 'unfill-paragraph)
(use-package golden-ratio
:init
(golden-ratio-mode 1))
;; disable backup files
(setq make-backup-files nil)
;; ido-vertical mode
(use-package ido-vertical-mode
:init
(ido-vertical-mode 1)
(setq ido-vertical-define-keys 'C-n-C-p-up-and-down))