-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
442 lines (375 loc) · 12.7 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
;;; init.el --- an Emacs configuration for JavaScript programming
;; Copyright (C) 2016 Zak B. Elep, <[email protected]>
;;; Commentary:
;; This is a minimal(? Really now...) Emacs configuration for my talk
;; on Emacs + JavaScript :) Adapted from my own personal `init.el'.
;; Usage
;; Put this file inside your `user-emacs-directory' (typically
;; `~/.emacs.d').
;; TODO (Left for the reader ;)
;; - Switch from ido to Ivy or Helm for more consistent completion
;; - Add a few more conveniences (multiple-cursors, hungry-delete)
;;; Code:
;;; General setup
;; High GC threshold for Emacs
(setq gc-cons-threshold 20000000)
;; Enable mouse wheel support
(if (fboundp 'mwheel-install) (mwheel-install))
;; Disable menu, tool, and scroll bars
(mapc (lambda (mode)
(when (fboundp mode) (funcall mode -1)))
'(menu-bar-mode tool-bar-mode scroll-bar-mode))
(blink-cursor-mode -1) ; Stop blinking the cursor/point
(setq load-prefer-newer t) ; Always load newer elisp
(setq enable-local-eval t) ; Tell Emacs to obey variables
; set by the files it reads
(setq visible-bell t) ; Blink the screen instead of
; beeping
(set-language-environment "UTF-8") ; Set my default language
; environment
(windmove-default-keybindings) ; Enable windmove
(winner-mode 1) ; Enable winner-mode
(auto-image-file-mode 1) ; Show images as images, not as
; semi-random bits
(setq inhibit-startup-message t) ; No splash screen (well...)
(if (fboundp 'fringe-mode) (fringe-mode 0)) ; no fringes too, please!
;; package.el
(require 'package)
(nconc package-archives
'(("melpa" . "https://melpa.org/packages/")))
(setq package-enable-at-startup nil)
(package-initialize)
;; use-package
(unless (package-installed-p 'use-package)
(progn
(package-refresh-contents)
(package-install 'use-package)))
(eval-when-compile
(eval-after-load 'advice
`(setq ad-redefinition-action 'accept))
(setq use-package-enable-imenu-support t)
(require 'use-package))
(require 'diminish)
(require 'bind-key)
(bind-key "C-x c @" 'list-packages)
;; quelpa helper for use-package
(use-package quelpa-use-package
:ensure t
:config
(setq quelpa-checkout-melpa-p nil))
;;; Editing/Programming
;; I want backups in their own directory, and even backup while in VC
(setq backup-directory-alist
`(("." . ,(expand-file-name "backups" user-emacs-directory)))
vc-make-backup-files t)
;; Disable backups for TRAMP files, though
(add-to-list 'backup-directory-alist
(cons tramp-file-name-regexp nil))
(global-font-lock-mode 1)
(setq font-lock-support-mode 'jit-lock-mode) ; Just In Time font-locking
(setq font-lock-maximum-decoration t)
(line-number-mode 1) ; Show line number ...
(column-number-mode 1) ; ... and column number on
; modeline
(show-paren-mode 1) ; Automatically makes the
; matching parenthesis stand out
; in color
(setq show-paren-style 'expression) ; Make the entire matched expression
; stand out
(mouse-avoidance-mode 'cat-and-mouse) ; Move the mouse pointer out
; of my way when I type
(temp-buffer-resize-mode 1) ; Temporary windows should not
; get into our way
(auto-compression-mode 1) ; Load Auto-(De)Compression Mode
(setq search-whitespace-regexp ".*?") ; match anything (non-greedy)
(setq auto-save-timeout 15 ; Auto-save after 15 sec of
; idleness
require-final-newline t ; Always add a newline to file's end
search-highlight t ; Highlight search strings
compilation-window-height 10 ; Set a small window for
; compiles
compilation-scroll-output
'first-error ; Follow compilation scrolling
; until the first error
compilation-ask-about-save nil)
;; Use imenu to browse use-package blocks
;; (defun zakame/imenu-use-package ()
;; "Extract use-package lines to be used as anchors in imenu."
;; (add-to-list 'imenu-generic-expression
;; '(nil
;; "\\(^\\s-*(use-package +\\)\\(\\_<.+\\_>\\)" 2)))
;; (add-hook 'emacs-lisp-mode-hook #'zakame/imenu-use-package)
;; ido-mode
(use-package ido
:config
(ido-mode 1)
(ido-everywhere 1)
(setq ido-use-virtual-buffers t
ido-use-filename-at-point 'guess
ido-create-new-buffer 'always
ido-ignore-extensions t))
;; ido-ubiquitous
(use-package ido-ubiquitous
:ensure t
:config
(ido-ubiquitous-mode 1))
;; flx-ido
(use-package flx-ido
:ensure t
:config
(flx-ido-mode 1)
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil))
;; ido-vertical-mode
(use-package ido-vertical-mode
:ensure t
:config
(ido-vertical-mode 1)
(setq ido-vertical-define-keys 'C-n-C-p-up-down-left-right
ido-vertical-show-count t))
;; idomenu
(use-package idomenu
:ensure t
:bind (("C-x c i" . idomenu)))
;; ido-other-window
(use-package ido-other-window
:quelpa (ido-other-window :fetcher github :repo "zakame/ido-other-window"))
;; smex
(use-package smex
:ensure t
:bind (("M-x" . smex)
("M-X" . smex-major-mode-commands))
:config
(smex-initialize))
;; Save point position between editing sessions
(use-package saveplace
:config
(unless (version< emacs-version "25")
(save-place-mode 1))
(setq-default save-place t
save-place-file (expand-file-name ".places"
user-emacs-directory)))
;; Enable tail mode for logs
(use-package autorevert
:diminish auto-revert-mode
:mode (("\\.log\\'" . auto-revert-tail-mode)))
;; Ace Jump mode
(use-package ace-jump-mode
:ensure t
:bind (("C-c SPC" . ace-jump-mode)
("C-c C-0" . ace-jump-mode)))
;; expand-region
(use-package expand-region
:ensure t
:bind (("C-=" . er/expand-region)))
;; Auto refresh buffers and dired, and be quiet about it
(global-auto-revert-mode 1)
(setq global-auto-revert-non-file-buffers t
auto-revert-verbose nil)
;; dired-x
(add-hook 'dired-load-hook
'(lambda ()
(load "dired-x")))
;; set human-readable sizes in dired
(setq dired-listing-switches "-alh")
;; recentf tweaks
(use-package recentf
:bind (("C-c f" . zakame/ido-recentf-open))
:config
(defun zakame/ido-recentf-open ()
"Use `ido-completing-read' to find a recent file."
(interactive)
(find-file (ido-completing-read "Find recent file: " recentf-list nil t)))
(recentf-mode)
(setq recentf-exclude '("TAGS" ".*-autoloads\\.el\\'")))
;; Ansi-Term tweaks
(use-package term
:bind (("C-c t" . ansi-term))
:config
(defadvice term-sentinel (around ansi-term-kill-buffer (proc msg))
(if (memq (process-status proc) '(signal exit))
(let ((buffer (process-buffer proc)))
ad-do-it
(kill-buffer buffer))
ad-do-it))
(ad-activate 'term-sentinel)
(defadvice ansi-term (before ansi-term-force-shell)
(interactive (list (getenv "SHELL"))))
(ad-activate 'ansi-term)
(add-hook 'term-mode-hook 'goto-address-mode)
(add-hook 'term-exec-hook
'(lambda ()
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))))
;; Eshell tweaks
(use-package eshell
:bind (("C-c e" . eshell))
:config
(defun zakame/eshell-rename-buffer-before-command ()
(let* ((last-input
(buffer-substring eshell-last-input-start eshell-last-input-end)))
(rename-buffer
(format "*eshell[%s]$ %s...*" default-directory last-input) t)))
(defun zakame/eshell-rename-buffer-after-command ()
(rename-buffer
(format "*eshell[%s]$ %s*" default-directory
(eshell-previous-input-string 0)) t))
(add-hook 'eshell-pre-command-hook
'zakame/eshell-rename-buffer-before-command)
(add-hook 'eshell-post-command-hook
'zakame/eshell-rename-buffer-after-command)
(use-package em-smart)
(setq eshell-where-to-jump 'begin
eshell-review-quick-commands nil
eshell-smart-space-goes-to-end t)
(add-hook 'eshell-mode-hook
'(lambda ()
(eshell-smart-initialize))))
;; make window splits much smarter especially when on widescreen
(defun zakame/split-window-prefer-side-by-side (window)
"Split WINDOW, preferably side by side."
(let ((split-height-threshold (and (< (window-width window)
split-width-threshold)
split-height-threshold)))
(split-window-sensibly window)))
(setq split-window-preferred-function
#'zakame/split-window-prefer-side-by-side)
;; undo-tree
(use-package undo-tree
:diminish undo-tree-mode
:ensure t
:config
(global-undo-tree-mode 1))
;; hippie-exp
(use-package hippie-exp
:config
(global-set-key (kbd "M-/") 'hippie-expand)
(setq hippie-expand-try-functions-list
'(
try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
try-expand-list
try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol)))
;; diff-hl
(use-package diff-hl
:ensure t
:config
(global-diff-hl-mode)
(setq diff-hl-side 'left)
(diff-hl-margin-mode)
(unless (version<= emacs-version "24.4")
(diff-hl-flydiff-mode))
(eval-after-load "magit"
'(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)))
;; aggressive indent
(use-package aggressive-indent
:diminish aggressive-indent-mode
:ensure t
:config
(mapc
(lambda (mode)
(add-to-list 'aggressive-indent-excluded-modes mode))
'(jade-mode web-mode html-mode))
(global-aggressive-indent-mode 1))
;; which-key-mode
(use-package which-key
:ensure t
:diminish which-key-mode
:config
(which-key-mode))
;; adaptive wrap for long lines
(use-package adaptive-wrap
:diminish visual-line-mode
:ensure t
:config
(add-hook 'text-mode-hook #'visual-line-mode)
(add-hook 'text-mode-hook #'adaptive-wrap-prefix-mode))
;; pos-tip
(use-package pos-tip
:ensure t)
;; use the_silver_searcher when available
(use-package ag
:ensure t
:if (executable-find "ag"))
;; Enable ElDoc for automatic documentation of elisp functions
(dolist (hook
'(emacs-lisp-mode-hook lisp-interaction-mode-hook ielm-mode-hook))
(add-hook hook #'eldoc-mode))
;; Don't mention ElDoc mode in modeline
(eval-after-load "eldoc"
'(diminish 'eldoc-mode))
;; Always indent using spaces, no tabs
(setq-default indent-tabs-mode nil)
;; htmlize
(use-package htmlize
:defer t
:ensure t)
;; swiper
(use-package swiper
:ensure t
:bind ("C-s" . swiper))
;;; JavaScript and other modes for this talk is all in the slides!
(with-temp-buffer
(insert-file-contents "~/README.org")
(goto-char (point-min))
(while (not (eobp))
(forward-line 1)
(cond
;; Report headers
((looking-at
(format "\\*\\{2,%s\\} +.*$" 2))
(message "%s" (match-string 0)))
;; Evaluate elisp configuration src blocks
((looking-at "^#\\+BEGIN_SRC +emacs-lisp *$")
(let ((l (match-end 0)))
(search-forward "\n#+END_SRC")
(eval-region l (match-beginning 0)))))))
;;; Misc
;; Zenburn theme (for cool coding for the eyes)
(use-package zenburn-theme
:ensure t
:config
(add-hook 'after-make-frame-functions
'(lambda (frame)
(with-selected-frame frame
(load-theme 'zenburn t)))))
;; Emojis! :+1:
(use-package emojify
:ensure t
:config
(unless (file-exists-p (emojify-image-dir))
(emojify-download-emoji emojify-emoji-set))
(add-hook 'after-init-hook #'global-emojify-mode))
;; Nyan-mode :3
(use-package nyan-mode
:ensure t
:config
(setq nyan-bar-length 16)
(nyan-mode 1))
;; zone out with Nyan cat when idle after 2 minutes :3
(use-package zone-nyan
:ensure t
:preface
(use-package zone)
:config
(setq zone-programs [zone-nyan])
(zone-when-idle 120))
;; Set up a cozy fireplace
(use-package fireplace
:ensure t
:config
(add-hook 'after-init-hook
'(lambda ()
(unless (daemonp)
(delete-other-windows)
(fireplace t)))))
;;; Local customizations
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
(load custom-file))
(provide 'init)
;;; init.el ends here