-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.el
More file actions
545 lines (430 loc) · 18.6 KB
/
init.el
File metadata and controls
545 lines (430 loc) · 18.6 KB
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
;;; init.el --- emacs.d initialization code.
;;; Commentary:
;;; Requires:
(eval-when-compile (require 'cl-lib))
;;; Code:
;; increase the gc threshold
(setq gc-cons-threshold 100000000)
;; increase the amount of data which emacs reads from processes
(setq read-process-output-max (* 1024 1024)) ;; 1mb
;; (add-to-list 'exec-path "/usr/local/bin")
;; these are shoved at the top to speed boot.
(setq inhibit-splash-screen t)
(setq-default indent-tabs-mode nil)
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;; (if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(when (string-equal window-system "x")
(add-to-list 'default-frame-alist '(font . "BitstreamVeraSansMono Nerd Font-9"))
(set-frame-parameter nil 'alpha-background 95)
(add-to-list 'default-frame-alist '(alpha-background . 95))
;; set chrome as the default browser
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "google-chrome"))
(blink-cursor-mode t)
(column-number-mode t)
(electric-pair-mode t)
(global-auto-revert-mode)
(global-hl-line-mode t)
(line-number-mode t)
(show-paren-mode t)
(fset 'yes-or-no-p 'y-or-n-p)
;; use the echo area for tooltips
(tooltip-mode -1)
;; (setq tooltip-use-echo-area t)
;; disable the "... of ..." to save space on the mode line
(size-indication-mode -1)
;; highlight region and comment
(global-set-key (kbd "\C-c\C-c") 'comment-or-uncomment-region)
;; Unbind Pesky Sleep Button
(global-unset-key [(control z)])
(global-unset-key [(control x)(control z)])
(setq exec-path (append '("/home/tellett/bin") exec-path))
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; --------------------------------------------------------------------------
;; autosaves
;; Auto-save more often
(setq auto-save-interval 150)
(setq auto-save-timeout 20)
;; Put autosave files (ie #foo#) in one place, *not* scattered all over the
;; file system! (The make-autosave-file-name function is invoked to determine
;; the filename of an autosave file.)
(defvar autosave-dir (concat user-emacs-directory
(convert-standard-filename "autosaves/")))
(make-directory autosave-dir t)
(defun auto-save-file-name-p (filename)
(string-match "^#.*#$" (file-name-nondirectory filename)))
(defun make-auto-save-file-name ()
(concat autosave-dir
(if buffer-file-name
(concat "#" (file-name-nondirectory buffer-file-name) "#")
(expand-file-name
(concat "#%" (buffer-name) "#")))))
;; Numbered backups
(setq version-control t
kept-old-versions 3
kept-new-versions 10
trim-versions-without-asking t
delete-old-versions t)
;; Put backup files (ie foo~) in one place too. (The backup-directory-alist
;; list contains regexp=>directory mappings; filenames matching a regexp are
;; backed up in the corresponding directory. Emacs will mkdir it if necessary.)
(defvar backup-dir (concat user-emacs-directory
(convert-standard-filename "backups/")))
(setq backup-directory-alist (list (cons "." backup-dir)))
;; --------------------------------------------------------------------------
;; auto-fill-mode
(setq-default fill-column 78)
;; Auto-fill-mode the the automatic wrapping of lines and insertion of
;; newlines when the cursor goes over the column limit.
(dolist (hook '(prog-mode-hook text-mode-hook))
(add-hook hook (lambda ()
(setq-local comment-auto-fill-only-comments t)
(auto-fill-mode 1))))
;; --------------------------------------------------------------------------
;; compilation-mode
(setq-default compilation-scroll-output 'first-error)
(when (require 'ansi-color nil t)
(defun my-colorize-compilation-buffer ()
(when (eq major-mode 'compilation-mode)
(defvar compilation-filter-start)
(ansi-color-apply-on-region compilation-filter-start (point-max))))
(add-hook 'compilation-filter-hook 'my-colorize-compilation-buffer))
;; --------------------------------------------------------------------------
;; clean the mode line
(defvar mode-line-cleaner-alist
`((abbrev-mode . "")
(auto-complete-mode . " α")
(auto-fill-function . " F")
(eldoc-mode . "")
(yas-minor-mode . " υ")
(yas-global-mode . " υ")
(paredit-mode . " π")
;; Major modes
(compilation-mode . "Comp")
(emacs-lisp-mode . "EL")
(hi-lock-mode . "")
(lisp-interaction-mode . "λ")
(nxhtml-mode . "nx")
(python-mode . "Py")
)
"Alist for `clean-mode-line'.
When you add a new element to the alist, keep in mind that you
must pass the correct minor/major mode symbol and a string you
want to use in the modeline *in lieu of* the original.")
(defun clean-mode-line ()
(interactive)
(cl-loop for cleaner in mode-line-cleaner-alist
do (let* ((mode (car cleaner))
(mode-str (cdr cleaner))
(old-mode-str (cdr (assq mode minor-mode-alist))))
(when old-mode-str
(setcar old-mode-str mode-str))
;; major mode
(when (eq mode major-mode)
(setq mode-name mode-str)))))
(add-hook 'after-change-major-mode-hook 'clean-mode-line)
;;; alias the new `flymake-report-status-slim' to
;;; `flymake-report-status'
(defalias 'flymake-report-status 'flymake-report-status-slim)
(defun flymake-report-status-slim (e-w &optional status)
"Show \"slim\" flymake status in mode line."
(defvar flymake-mode-line-e-w)
(defvar flymake-mode-line-status)
(defvar flymake-mode-line)
(when e-w
(setq flymake-mode-line-e-w e-w))
(when status
(setq flymake-mode-line-status status))
(let* ((mode-line " Φ"))
(when (> (length flymake-mode-line-e-w) 0)
(setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
(setq mode-line (concat mode-line flymake-mode-line-status))
(setq flymake-mode-line mode-line)
(force-mode-line-update)))
;; --------------------------------------------------------------------------
;; desktop-save-mode
;;;; Very important code to save desktop state between Emacs sessions.
(require 'desktop)
(savehist-mode 1)
(defun save-emacs-state ()
"Save the desktop as of right now, so if it dies it'll come back in the right place."
(interactive)
(desktop-save desktop-dirname)
(message "Saved desktop %s" desktop-dirname))
;; Save the desktop state after a bunch of idle time
(defvar save-emacs-timer
(run-with-idle-timer 300 t #'save-emacs-state)
"Timer that saves my desktop state every 5 minutes.")
;; ;; Augment shell-mode to save state (history and current directory) on desktop
;; ;; save
;; (defun my-shell-save-desktop-data (desktop-dirname)
;; "Extra info for shell-mode buffers to be saved in the desktop file."
;; (list default-directory comint-input-ring))
;; (defun my-shell-restore-desktop-buffer
;; (desktop-buffer-file-name desktop-buffer-name desktop-buffer-misc)
;; "Restore a shell buffer's state from the desktop file."
;; (let ((dir (nth 0 desktop-buffer-misc))
;; (ring (nth 1 desktop-buffer-misc)))
;; (when desktop-buffer-name
;; (set-buffer (get-buffer-create desktop-buffer-name))
;; (when dir
;; (setq default-directory dir))
;; (shell desktop-buffer-name)
;; (when ring
;; (setq comint-input-ring ring))
;; (current-buffer))))
;; (defun my-shell-setup-desktop ()
;; "Sets up a shell buffer to have its state saved in the desktop file."
;; (set (make-local-variable 'desktop-save-buffer) #'my-shell-save-desktop-data))
;; (add-to-list 'desktop-buffer-mode-handlers
;; '(shell-mode . my-shell-restore-desktop-buffer))
;; (add-hook 'shell-mode-hook #'my-shell-setup-desktop)
(setq desktop-dirname (expand-file-name "~/"))
(setq desktop-path (list desktop-dirname))
(when (desktop-owner)
(let* ((attrs (process-attributes (desktop-owner)))
(usercons (and attrs (assq 'user attrs)))
(user (and usercons (cdr usercons))))
(if (equal user (user-login-name))
;; Best guess is that the old emacs is still there
(setq desktop-load-locked-desktop (if (daemonp) nil 'ask))
;; It's dead, Jim.
(delete-file (desktop-full-lock-name)))))
;; ;; bugfix in desktop.el
;; (defadvice desktop-create-buffer (around dont-bury-dead-buffers act)
;; (cl-flet ((real-bury-buffer () nil))
;; (fset 'real-bury-buffer (symbol-function #'bury-buffer))
;; (cl-flet ((bury-buffer (buf) (when (buffer-live-p buf)
;; (real-bury-buffer buf))))
;; ad-do-it)))
;; ;; don't ever prompt while restoring desktop
;; (defadvice desktop-read (around no-prompting act)
;; (cl-flet ((y-or-n-p (prompt) nil)
;; (read-char-choice
;; (prompt chars suppress-quit)
;; (if (memq ?n chars)
;; ?n
;; (error "Don't know how to fake read-char-choice"))))
;; ad-do-it))
(desktop-save-mode 1)
;; --------------------------------------------------------------------------
;; sticky windows
(define-minor-mode sticky-mode
"Make the current window always display this buffer."
nil " st" nil
(set-window-dedicated-p (selected-window) sticky-mode))
(global-set-key [f11] 'sticky-mode)
;; --------------------------------------------------------------------------
;; electric pairs
;; TODO: change this to walk over a closing brace...
(defun electric-pair ()
"Insert character pair without surrounding spaces."
(interactive)
(let (parens-require-spaces)
(insert-pair)))
(dolist (hook '(prog-mode-hook text-mode-hook))
(add-hook hook (lambda ()
(electric-pair-mode t)
(define-key prog-mode-map "\"" 'electric-pair)
(define-key prog-mode-map "\'" 'electric-pair)
(define-key prog-mode-map "(" 'electric-pair)
(define-key prog-mode-map "[" 'electric-pair)
(define-key prog-mode-map "{" 'electric-pair))))
;; --------------------------------------------------------------------------
;; flyspell-mode
(setq ispell-personal-dictionary "~/.ispell-personal-dict")
;; Use aspell if installed
(when (executable-find "aspell")
(defvar ispell-program-name)
(setq ispell-program-name "aspell")
(defvar ispell-list-command)
(setq ispell-list-command "--list")
(defvar ispell-extra-args)
(setq ispell-extra-args '("--sug-mode=ultra" "--lang=en_US")))
;; enable for the following modes
(dolist (hook '(text-mode-hook))
(add-hook hook (lambda () (flyspell-mode 1))))
(dolist (hook '(prog-mode-hook))
(add-hook hook (lambda () (flyspell-prog-mode))))
;; disable for the following modes
(dolist (hook '(change-log-mode-hook log-edit-mode-hook))
(add-hook hook (lambda () (flyspell-mode -1))))
;; --------------------------------------------------------------------------
; html-mode
(add-hook 'html-mode-hook (lambda () (auto-fill-mode -1) (zencoding-mode 1)))
;; --------------------------------------------------------------------------
; ido-mode
(ido-mode t)
(ido-everywhere t)
(setq ido-case-fold t ; be case-insensitive
ido-confirm-unique-completion t ; wait for RET, period.
ido-save-directory-list-file "~/.emacs.d/cache/ido.last"
ido-enable-flex-matching t ; be smart
ido-enable-last-directory-history t ; remember last used dirs
ido-ignore-buffers '("\\` " "^\*Mess" "^\*Back" ".*Completion" "^\*Ido"
"^\*trace" "^\*compilation" "^\*GTAGS" "^session\.*"
"^\*")
ido-ignore-extensions t ; ignore stuff like .o files, etc
ido-max-work-directory-list 30 ; should be enough
ido-max-work-file-list 50 ; remember many
ido-use-filename-at-point nil ; don't use filename at point (annoying)
ido-use-url-at-point nil ; don't use url at point (annoying)
ido-max-prospects 8 ; don't spam my minibuffer
;; ido-work-directory-list '("~/" "~/Desktop" "~/Documents" "~src"))
)
;; when using ido, the confirmation is rather annoying...
(setq confirm-nonexistent-file-or-buffer nil)
;; --------------------------------------------------------------------------
;; Line numbering
(when (version<= emacs-version "26.0.50")
(add-hook 'linum-before-numbering-hook
(lambda ()
(let ((w (length (number-to-string
(count-lines (point-min) (point-max))))))
(defvar linum-format)
(setq linum-format
`(lambda (line)
(propertize (concat
(truncate-string-to-width
"" (- ,w (length (number-to-string line)))
nil ?\x2007)
(number-to-string line)
"\x2007")
'face 'linum)))))))
(if (version<= "26.0.50" emacs-version)
(dolist (hook '(prog-mode-hook text-mode-hook conf-mode-hook))
(add-hook hook (lambda ()
(display-line-numbers-mode 1))))
(dolist (hook '(prog-mode-hook text-mode-hook conf-mode-hook))
(add-hook hook (lambda ()
(linum-mode 1)))))
;; --------------------------------------------------------------------------
;; text-mode
(add-hook 'text-mode-hook 'turn-on-visual-line-mode)
;; --------------------------------------------------------------------------
;; sh-mode
(add-hook 'sh-mode-hook (lambda ()
(setq sh-basic-offset 2)
(setq sh-indentation 2)
(setq indent-tabs-mode nil)))
;; --------------------------------------------------------------------------
;; uniquify
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward)
;; --------------------------------------------------------------------------
;; whitespace-mode
(setq
;; make whitespace-mode use “¶” for newline and “▷” for tab.
;; together with the rest of its defaults
;; source: http://xahlee.org/emacs/whitespace-mode.html
whitespace-display-mappings '((space-mark 32 [183] [46]) ; normal space, ·
(space-mark 160 [164] [95])
(space-mark 2208 [2212] [95])
(space-mark 2336 [2340] [95])
(space-mark 3616 [3620] [95])
(space-mark 3872 [3876] [95])
(newline-mark 10 [182 10]) ; newlne, ¶
(tab-mark 9 [9655 9] [92 9])) ; tab, ▷
;; make whitespace-mode use just basic coloring
whitespace-style '(lines
lines-tail
newline
newline-mark
spaces
space-mark
tabs
tab-mark
trailing))
;; --------------------------------------------------------------------------
;; winner-mode
(require 'winner)
(winner-mode 1)
;; --------------------------------------------------------------------------
;; el-get
(add-to-list 'load-path (concat user-emacs-directory "el-get/el-get"))
(setq el-get-git-install-url "https://github.com/tellett/el-get.git"
el-get-user-directory (concat user-emacs-directory "el-get-user")
el-get-user-package-directory (concat (file-name-as-directory
el-get-user-directory) "init")
the-el-get-packages '(all-the-icons
auto-highlight-symbol
company-lsp
company-mode
company-quickhelp
company-web
deft
docker-compose-mode
dockerfile-mode
emacs-pet
emacs-bazel-mode
envrc
flycheck
git-gutter-fringe
go-company
go-mode
gradle-mode
ido-completing-read-plus
json-mode
json-reformat
lsp-mode
lsp-treemacs
lsp-ui
magit
markdown-mode
org-mode
pip-requirements
popup
pos-tip
projectile
protobuf-mode
puppet-mode
python-mode
;; python-black
;; python-isort
rainbow-delimiters
rainbow-mode
scala-mode
smex
spaceline
sr-speedbar
terraform-mode
tomorrow-theme
treemacs
treemacs-magit
treemacs-projectile
color-theme-sanityinc-tomorrow
toml-mode
web-completion-data
web-mode
yaml-mode
yasnippet
yasnippet-snippets
zencoding-mode))
(eval-after-load "el-get/el-get.el"
(lambda()
'((add-to-list 'el-get-recipe-path
(concat el-get-user-directory "recipes")))))
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.github.com/tellett/el-get/master/el-get-install.el")
(let (el-get-master-branch)
(goto-char (point-max))
(eval-print-last-sexp))))
(mapc (lambda(x) (add-to-list 'package-archives x))
'(
("marmalade" . "https://marmalade-repo.org/packages/")
("melpa" . "https://melpa.org/packages/")
("tromey" . "http://tromey.com/elpa/")))
(add-to-list 'el-get-recipe-path (concat el-get-user-directory "/recipes"))
(el-get 'sync '(el-get))
(el-get 'sync the-el-get-packages)
;; (envrc-global-mode)
;; --------------------------------------------------------------------------
;; compile and load up the local stuff
(setq custom-file (concat user-emacs-directory "init-local.el"))
(if (and (file-exists-p custom-file) (file-readable-p custom-file))
(byte-compile-file custom-file t))
(put 'upcase-region 'disabled nil)
;;; init.el ends here