-
Notifications
You must be signed in to change notification settings - Fork 5
/
.emacs
484 lines (416 loc) · 16.5 KB
/
.emacs
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
;; Add a hook to display the startup time for profiling.
;;
;; Source: https://blog.d46.us/advanced-emacs-startup/
(add-hook 'emacs-startup-hook
(lambda ()
(message "Emacs ready in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract
after-init-time before-init-time)))
gcs-done)))
;; Make startup faster by reducing the frequency of garbage
;; collection. The default is 800 kilobytes. Measured in bytes.
(setq gc-cons-threshold (* 100 1024 1024))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(browse-url-netscape-program "opera")
'(browse-url-xterm-program "term.sh")
'(case-fold-search t)
'(column-number-mode t)
'(current-language-environment "UTF-8")
'(custom-safe-themes
(quote
("c74e83f8aa4c78a121b52146eadb792c9facc5b1f02c917e3dbb454fca931223" "3c83b3676d796422704082049fc38b6966bcad960f896669dfc21a7a37a748fa" "756597b162f1be60a12dbd52bab71d40d6a2845a3e3c2584c6573ee9c332a66e" "c5a044ba03d43a725bd79700087dea813abcb6beb6be08c7eb3303ed90782482" "6a37be365d1d95fad2f4d185e51928c789ef7a4ccf17e7ca13ad63a8bf5b922f" default)))
'(custom-theme-directory "~/.emacs.d/themes/")
'(default-input-method "rfc1345")
'(delete-old-versions t)
'(display-time-24hr-format t)
'(fill-column 80)
'(global-linum-mode t)
'(gud-gdb-command-name "gdb --annotate=1")
'(guess-style-guesser-alist (quote ((indent-tabs-mode . guess-style-guess-tabs-mode))))
'(indent-tabs-mode nil)
'(large-file-warning-threshold nil)
'(ledger-reports
(quote
(("Foo" "ledger ")
("bal" "%(binary) -f %(ledger-file) bal")
("reg" "%(binary) -f %(ledger-file) reg")
("payee" "%(binary) -f %(ledger-file) reg @%(payee)")
("account" "%(binary) -f %(ledger-file) reg %(account)"))))
'(line-number-mode t)
'(menu-bar-mode nil)
'(mouse-wheel-follow-mouse t)
'(mouse-wheel-mode t)
'(mouse-wheel-progressive-speed nil)
'(mouse-wheel-scroll-amount (quote (2)))
'(package-selected-packages
(quote
(ledger-mode yasnippet yaml-tomato yaml-mode use-package tabbar smooth-scrolling smart-mode-line-powerline-theme scad-mode rainbow-mode projectile nginx-mode matlab-mode markdown-mode magit goto-last-change gotham-theme go-mode git-gutter-fringe git-gutter-fringe+ flycheck-irony flx-ido f etags-table esup dockerfile-mode ctags-update company-irony color-theme-sanityinc-tomorrow color-theme-sanityinc-solarized benchmark-init ag ac-etags ac-c-headers)))
'(require-final-newline t)
'(show-paren-mode t nil (paren))
'(show-trailing-whitespace t)
'(sml/col-number-format "%02c]")
'(sml/line-number-format "[%3l")
'(sml/modified-char "×")
'(sml/numbers-separator ",")
'(sml/pos-id-separator ")")
'(sml/pos-minor-modes-separator "")
'(sml/position-percentage-format "%p")
'(sml/pre-id-separator " (")
'(sml/pre-minor-modes-separator "")
'(standard-indent 2)
'(swbuff-clear-delay 3)
'(swbuff-status-window-layout (quote adjust))
'(tab-width 2)
'(transient-mark-mode t)
'(uniquify-buffer-name-style nil nil (uniquify))
'(version-control t)
'(xterm-mouse-mode t))
(add-to-list 'load-path "~/.emacs.d/lisp/")
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
;; https://github.com/jwiegley/use-package
(eval-when-compile
(require 'use-package))
(setq use-package-always-ensure t)
;; Load custom theme.
(load-theme 'wombat-ms t)
;; Set up smart-mode-line.
(use-package smart-mode-line
:config
(sml/setup)
(sml/apply-theme 'respectful))
(use-package magit
:ensure t
:demand t
:bind (("C-x g" . magit-status)))
(setq git-commit-fill-column 72)
;; Set up projectile.
(use-package projectile
:defer 2
:config
(projectile-global-mode))
;; flx-ido for better matching with projectile and ido.
(use-package flx-ido
:defer 2)
;; ag for search.
(use-package ag
:defer 2)
;; Irony mode.
(defun my-irony-mode-hook ()
(define-key irony-mode-map [remap completion-at-point]
'irony-completion-at-point-async)
(define-key irony-mode-map [remap complete-symbol]
'irony-completion-at-point-async))
(use-package irony
:init
(add-hook 'irony-mode-hook 'my-irony-mode-hook)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
:hook ((c-mode
c++-mode
objc-mode-hook) . irony-mode))
(use-package company-irony)
(eval-after-load 'company
'(add-to-list 'company-backends 'company-irony))
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
(global-company-mode)
(require 'cc-mode)
(defun my-c-mode-common-hook ()
(setq c-basic-offset tab-width))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; https://github.com/ledger/ledger-mode
(use-package ledger-mode
:defer t)
;; Go mode.
(use-package go-mode
:defer t)
(use-package smooth-scrolling
:defer 2)
;; Dynamically calculate linum-format based on the number of lines in the file.
(defadvice linum-update-window (around linum-dynamic activate)
(let* ((w (length (number-to-string
(count-lines (point-min) (point-max)))))
(linum-format (concat "%" (number-to-string w) "d ")))
ad-do-it))
;; Tab bar.
(use-package tabbar)
(tabbar-mode)
;; Move between tabs within a group with M-p and M-n.
(global-set-key (kbd "M-p") 'tabbar-backward-tab)
(global-set-key (kbd "M-n") 'tabbar-forward-tab)
;; Move between tab groups with C-M-p and C-M-n.
(global-set-key (kbd "C-M-p") 'tabbar-backward-group)
(global-set-key (kbd "C-M-n") 'tabbar-forward-group)
;; From "Xah Lee".
(defun tabbar-buffer-groups ()
"Return the list of group names the current buffer belongs to.
This function is a custom function for tabbar-mode's
tabbar-buffer-groups. This function group all buffers into 3
groups: Those Dired, those user buffer, and those emacs buffer.
Emacs buffer are those starting with '*'."
(list
(cond
((or (string-equal "*" (substring (buffer-name) 0 1))
(string-equal "TAGS" (buffer-name)))
"Emacs Buffer")
((eq major-mode 'dired-mode)
"Dired")
(t "User Buffer"))))
(setq tabbar-buffer-groups-function 'tabbar-buffer-groups)
;; Add a buffer modification state indicator in the tab label,
;; and place a space around the label to make it look less crowded.
(defadvice tabbar-buffer-tab-label (after fixup activate)
(setq ad-return-value
(if (and (buffer-modified-p (tabbar-tab-value tab))
(buffer-file-name (tabbar-tab-value tab)))
(concat " " (concat ad-return-value "[+] "))
(concat " " (concat ad-return-value " ")))))
;; called each time the modification state of the buffer changed
(defun ztl-modification-state-change ()
(tabbar-set-template tabbar-current-tabset nil)
(tabbar-display-update))
;; first-change-hook is called BEFORE the change is made
(defun ztl-on-buffer-modification ()
(set-buffer-modified-p t)
(ztl-modification-state-change))
(add-hook 'after-save-hook 'ztl-modification-state-change)
;; this doesn't work for revert
;;(add-hook 'after-revert-hook 'ztl-modification-state-change)
(add-hook 'first-change-hook 'ztl-on-buffer-modification)
(setq tabbar-home-button (quote (("[Home]") "[x]")))
(setq tabbar-separator (quote (" ")))
(global-set-key (kbd "C-c C-c C-c") 'compile)
;; Only prompt for a compile command if a prefix argument is given.
(setq compilation-read-command nil)
;; Ido mode for magic autocompleting.
(ido-mode)
;; Ido mode in M-x.
(global-set-key
"\M-x"
(lambda ()
(interactive)
(call-interactively
(intern
(ido-completing-read
"M-x "
(all-completions "" obarray 'commandp))))))
;; Coding style preferences.
(require 'custom-google-coding-style)
;; set indent style to 'k&r' style for everything but java
;; http://en.wikipedia.org/wiki/Indent_style
(setq c-default-style
'((java-mode . "java") (other . "k&r")))
;; Enable backup files.
(setq make-backup-files t)
;; Save all backup file in this directory.
(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))
;; Put autosave files (i.e., #foo#) in ~/.emacs_autosaves.
(defvar autosave-dir (concat "~/.emacs_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) "#")))))
;; Fill mode for text mode by default
;;(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Fill mode by default for most major modes.
(setq-default auto-fill-function 'do-auto-fill)
(add-hook 'sh-mode-hook (lambda () (auto-fill-mode nil)))
(add-hook 'go-mode-hook (lambda () (auto-fill-mode nil)))
;; Make Text mode the default mode for new buffers
(setq default-major-mode 'text-mode)
;; Periodically reload buffers from disk.
(global-auto-revert-mode)
;; Enable time-stamp updating on save.
(setq
time-stamp-active t ; do enable time-stamps
time-stamp-line-limit 10 ; check first 10 buffer lines for Time-stamp:
time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S") ; date format
(add-hook 'write-file-hooks 'time-stamp) ; update when saving
;; Disable splash screen.
(setq inhibit-splash-screen t)
;; And startup message.
(eval-after-load "startup" '(fset
'display-startup-echo-area-message (lambda ())))
;; Make bells less visible. The visible bell (terminal flash) is annoying.
(setq ring-bell-function (lambda () (message "*beep*")))
(defun font-lock-set-up-width-warning (width)
"In the current buffer, make text beyond column `width' appear in
`font-lock-warning-face'."
(require 'font-lock)
(font-lock-mode 1)
(make-local-variable 'font-lock-keywords)
(font-lock-add-keywords
nil
`((,(format "^.\\{%d\\}\\(.+\\)" width) 1 font-lock-warning-face t))))
;; cperl-mode is preferred to perl-mode.
(defalias 'perl-mode 'cperl-mode)
;; Matlab major mode.
(use-package matlab
:ensure matlab-mode
:defer t
:init
(setq matlab-indent-function t)
(setq matlab-shell-command "matlab"))
(add-hook 'c-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'c++-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'css-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'java-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'js2-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'cperl-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'python-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'rst-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'emacs-lisp-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'text-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'matlab-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
;; Look for spelling mistakes in code comments and strings.
(add-hook 'c-mode-hook
'(lambda () (flyspell-prog-mode)))
(add-hook 'c++-mode-hook
'(lambda () (flyspell-prog-mode)))
(add-hook 'css-mode-hook
'(lambda () (flyspell-prog-mode)))
(add-hook 'java-mode-hook
'(lambda () (flyspell-prog-mode)))
(add-hook 'js2-mode-hook
'(lambda () (flyspell-prog-mode)))
(add-hook 'cperl-mode-hook
'(lambda () (flyspell-prog-mode)))
(add-hook 'python-mode-hook
'(lambda () (flyspell-prog-mode)))
(add-hook 'emacs-mode-hook
'(lambda () (flyspell-prog-mode)))
(add-hook 'matlab-mode-hook
'(lambda () (flyspell-prog-mode)))
;; Look for spelling mistakes in all text.
(add-hook 'text-mode-hook
'(lambda () (flyspell-mode)))
(add-hook 'rst-mode-hook
'(lambda () (flyspell-mode)))
;; Use 72-column fills in mail mode.
(add-hook 'mail-mode-hook
(lambda () (set-fill-column 72)))
(add-hook 'mail-mode-hook
'(lambda () (font-lock-set-up-width-warning 72)))
;; Dart looks a little like C++.
(add-to-list 'auto-mode-alist '("\\.dart$" . c++-mode))
;; Markdown major mode.
(use-package markdown-mode
:config
;; M-n and M-p are used for switching between buffers, so unbind them from
;; markdown-mode.
(unbind-key "M-n" markdown-mode-map)
(unbind-key "M-p" markdown-mode-map)
:defer t)
(add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown$" . markdown-mode))
;; reStructuredText major mode.
(add-to-list 'auto-mode-alist '("\\.rst$" . rst-mode))
;; Arduino code is C++.
(add-to-list 'auto-mode-alist '("\\.pde$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.ino$" . c++-mode))
;; Protocol buffer definitions are best edited as C.
(add-to-list 'auto-mode-alist '("\\.proto$" . c-mode))
;; BUILD files in python-mode.
(add-to-list 'auto-mode-alist '("\/BUILD$" . python-mode))
;; TypeScript files in javascript-mode.
(add-to-list 'auto-mode-alist '("\\.ts$" . javascript-mode))
;; SCons files in python-mode.
(add-to-list 'auto-mode-alist '("SConstruct$" . python-mode))
(add-to-list 'auto-mode-alist '("SConscript$" . python-mode))
;; Diff mode settings.
(setq diff-default-read-only t) ;; open diffs in RO mode
;; Goto-last-change. Bound to 'C-x \'.
(use-package goto-last-change
:defer 1
:config
(global-set-key (kbd "C-x \\") 'goto-last-change))
;; For finding and updating TAGS files.
(use-package etags-table
:defer 2
:config
(setq etags-table-search-up-depth 10))
(use-package ctags-update
:defer 2
:config
(add-hook 'c-mode-common-hook 'turn-on-ctags-auto-update-mode))
;; Use guess-style.el to automatically figure out the indentation settings of
;; the file we're editing. The customized guess-style-guesser-alist setting
;; above determines what settings to discover.
(require 'guess-style)
(autoload 'guess-style-set-variable "guess-style" nil t)
(autoload 'guess-style-guess-variable "guess-style")
(autoload 'guess-style-guess-all "guess-style" nil t)
(add-hook 'c-mode-hook 'guess-style-guess-all)
(add-hook 'c++-mode-hook 'guess-style-guess-all)
(add-hook 'java-mode-hook 'guess-style-guess-all)
(add-hook 'cperl-mode-hook 'guess-style-guess-all)
(add-hook 'python-mode-hook 'guess-style-guess-all)
(add-hook 'emacs-lisp-mode-hook 'guess-style-guess-all)
(add-hook 'text-mode-hook 'guess-style-guess-all)
(add-hook 'matlab-mode-hook 'guess-style-guess-all)
(global-guess-style-info-mode 1)
;; Language-cpecific indentation tweaks.
;; https://dougie.io/emacs/indentation/
(setq-default css-indent-offset tab-width) ;; CSS
(setq-default python-indent-offset tab-width) ;; Python
(setq-default js-indent-level tab-width) ;; Javascript
(setq-default lisp-indent-offset 2)
(setq lisp-indent-function 'common-lisp-indent-function)
;; Default window fame size.
(add-to-list 'default-frame-alist '(height . 45))
(add-to-list 'default-frame-alist '(width . 85)) ;; 80+5 for gutter
;; Prefer a dark background.
(setq frame-background-mode 'dark)
;; Define a new face for hard tabs.
(defface hard-tabs-face
'((t (:foreground "gray30" :underline t))) "Used for hard tabs.")
;; Draw hard tabs with the custom face.
(add-hook 'font-lock-mode-hook
(lambda ()
(font-lock-add-keywords
nil
'(("\t" 0 'hard-tabs-face prepend)))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "#202020" :foreground "#cccccc" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 120 :width normal :foundry "nil" :family "Monaco"))))
'(font-lock-warning-face ((t (:background "purple"))))
'(linum ((t (:inherit (shadow default) :background "black" :foreground "#989973"))))
'(sml/col-number ((t (:foreground "#9A75A6"))))
'(sml/git ((t (:foreground "#CC6666"))))
'(sml/line-number ((t (:foreground "#9A75A6" :weight bold))))
'(sml/minor-modes ((t (:foreground "#81A2BE"))))
'(sml/modes ((t (:foreground "#5F819D" :weight normal))))
'(sml/numbers-separator ((t (:foreground "#aaa"))))
'(sml/position-percentage ((t (:foreground "#B294BB" :weight normal))))
'(tabbar-button ((t (:background "#202020" :foreground "#202020"))))
'(tabbar-default ((t (:background "#202020" :foreground "white"))))
'(tabbar-selected ((t (:background "#222222" :foreground "Pink"))))
'(trailing-whitespace ((t (:background "#aaaaaa")))))
;; Make gc pauses faster by decreasing the threshold.
(setq gc-cons-threshold (* 2 1024 1024))