-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.el
357 lines (299 loc) · 13 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
;;; package -- Summary
;;; Commentary:
;;; Code:
(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 (>= emacs-major-version 24)
(require 'package)
(add-to-list
'package-archives
'("melpa" . "http://melpa.org/packages/")
t)
(package-initialize))
(setq
backup-by-copying t
backup-directory-alist
'(("." . "~/.emacs.d/auto-save-list"))
delete-old-versions t
kept-new-versions 2000
kept-old-versions 0
version-control t)
(require 'backup-each-save)
(add-hook 'after-save-hook 'backup-each-save)
;; https://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00211.html
;; Enriched Text mode has its support for decoding 'x-display' disabled.
;; This feature allows saving 'display' properties as part of text.
;; Emacs 'display' properties support evaluation of arbitrary Lisp forms
;; as part of instantiating the property, so decoding 'x-display' is
;; vulnerable to executing arbitrary malicious Lisp code included in the
;; text (e.g., sent as part of an email message).
(eval-after-load "enriched"
'(defun enriched-decode-display-prop (start end &optional param)
(list start end)))
(load-theme 'base16-atelier-forest t)
(add-hook 'after-init-hook 'global-company-mode)
(require 'company-terraform)
(company-terraform-init)
(defun my/python-mode-hook ()
(add-to-list 'company-backends 'company-jedi))
(add-hook 'python-mode-hook 'my/python-mode-hook)
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(add-hook 'coffee-mode-hook (lambda () (interactive) (setq tab-width 2)))
(add-hook 'go-mode-hook (lambda () (interactive) (setq tab-width 4)))
(add-hook 'python-mode-hook 'jedi:setup)
(column-number-mode t)
(require 'flycheck)
(electric-indent-mode 0)
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(global-git-gutter-mode t)
(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.
'(flycheck-pycheckers-checkers (quote (pylint mypy3 pyflakes bandit)))
'(flycheck-pycheckers-venv-root "~/.pyenv/versions/")
'(git-gutter:ask-p nil)
'(git-gutter:handled-backends (quote (git)))
'(git-gutter:update-interval 2)
'(git-gutter:visual-line t)
'(helm-ff-newfile-prompt-p t)
'(magit-log-arguments (quote ("--graph" "--color" "--decorate" "-n256")))
'(package-selected-packages
(quote
(jedi lua-mode nginx-mode kubernetes plantuml-mode flycheck-golangci-lint flycheck-gometalinter flymake-go flycheck-pycheckers pyvenv backup-each-save exec-path-from-shell company-jedi use-package helm-projectile pipenv projectile pyenv-mode tide rainbow-mode nvm multiple-cursors markdown-mode less-css-mode helm-ag go-mode git-gutter-fringe dockerfile-mode docker-compose-mode company-terraform base16-theme adaptive-wrap)))
'(plantuml-jar-path "~/.emacs.d/elpa/plantuml-mode-20190510.657/plantuml.jar")
'(savehist-mode t))
(require 'git-gutter-fringe)
(set-face-foreground 'git-gutter:modified "#CEB300")
(set-face-background 'git-gutter:modified "#CEB300")
(set-face-foreground 'git-gutter:added "#0E3389")
(set-face-background 'git-gutter:added "#0E3389")
(set-face-foreground 'git-gutter:deleted "#803C3C")
(set-face-background 'git-gutter:deleted "#803C3C")
(add-hook 'json-mode-hook (lambda () (interactive) (setq tab-width 2)))
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'load-path ".")
(require 'tty-format)
;; M-x display-ansi-colors to explicitly decode ANSI color escape sequences
(defun display-ansi-colors ()
(interactive)
(format-decode-buffer 'ansi-colors))
(add-to-list 'auto-mode-alist '("\\.color\\'" . display-ansi-colors))
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-hook 'markdown-mode-hook
(lambda ()
(local-unset-key (kbd "M-<up>"))
(local-unset-key (kbd "M-<down>"))
(local-unset-key (kbd "M-<left>"))
(local-unset-key (kbd "M-<right>"))
(toggle-truncate-lines)
(adaptive-wrap-prefix-mode)))
(setq-default truncate-lines 1)
(require 'multiple-cursors)
(defun pyenv-activate-current-project ()
"Automatically activates pyenv version if .python-version file exists."
(interactive)
(let ((python-version-directory (locate-dominating-file (buffer-file-name) ".python-version")))
(if python-version-directory
(let* ((pyenv-version-path (f-expand ".python-version" python-version-directory))
(pyenv-current-version (s-trim (f-read-text pyenv-version-path 'utf-8))))
(pyenv-mode-set pyenv-current-version)
(message (concat "Setting virtualenv to " pyenv-current-version))))))
(add-to-list 'auto-mode-alist '("\\.plantuml\\'" . plantuml-mode))
(add-to-list 'auto-mode-alist '("\\.puml\\'" . plantuml-mode))
(use-package pyenv-mode
:hook (python-mode . pyenv-activate-current-project)
:init
(add-to-list 'exec-path "~/.pyenv/shims")
(setenv "WORKON_HOME" "~/.pyenv/versions/")
:config
(pyenv-mode))
(defvar pyenv-current-version nil nil)
(defun pyenv-init()
"Initialize pyenv's current version to the global one."
(let ((global-pyenv (replace-regexp-in-string "\n" "" (shell-command-to-string "pyenv global"))))
(message (concat "Setting pyenv version to " global-pyenv))
(pyenv-mode-set global-pyenv)
(setq pyenv-current-version global-pyenv)))
(add-hook 'after-init-hook 'pyenv-init)
(global-flycheck-mode 1)
(with-eval-after-load 'flycheck
(add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup))
(defvar flycheck-check-syntax-automatically)
(setq flycheck-check-syntax-automatically '(save))
(let ((govet (flycheck-checker-get 'go-vet 'command)))
(when (equal (cadr govet) "tool")
(setf (cdr govet) (cddr govet))))
(add-hook 'css-mode-hook 'rainbow-mode)
(recentf-mode 1)
(set-default 'tramp-default-proxies-alist (quote ((".*" "\\`root\\'" "/ssh:%h:"))))
(setq tramp-default-method "ssh")
(helm-mode 1)
(helm-autoresize-mode 1)
(define-key global-map [remap list-buffers] 'helm-buffers-list)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "C-x C-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "M-D") 'helm-buffer-run-kill-buffers)
(defun setup-tide-mode ()
(interactive)
(tide-setup)
(flycheck-mode +1)
(setq flycheck-check-syntax-automatically '(save mode-enabled))
(eldoc-mode +1)
(company-mode +1))
(setq company-tooltip-align-annotations t)
(add-hook 'typescript-mode-hook 'setup-tide-mode)
(setq tide-tsserver-process-environment '("TSS_LOG=-level verbose -file /tmp/tss.log"))
(winner-mode 1)
;Custom functions
(defun reload-init ()
"Reload init.el without restarting."
(interactive)
(load-file "~/.emacs.d/init.el"))
(defun show-file-name ()
"Show the full path file name in the minibuffer."
(interactive)
(message (buffer-file-name)))
(defun flush-blank-lines ()
"Remove any blank lines from the entire buffer."
(interactive)
(flush-lines "^$"))
(defun halve-other-window-height ()
"Expand current window to use half of the other window's lines."
(interactive)
(enlarge-window (/ (window-height (next-window)) 2)))
(defun halve-this-window-height ()
"Shrink current window to use half of the other window's lines."
(interactive)
(shrink-window (/ (window-height (next-window)) 2)))
(defun unix-newline ()
"Convert all Windows newlines to Unix styles line endings."
(set-buffer-file-coding-system 'utf-8))
(add-hook 'before-save-hook 'unix-newline)
(add-hook 'before-save-hook (lambda ()
(whitespace-cleanup)))
(defun restart-shell ()
"Restart (or start a new) shell in current buffer."
(interactive)
(shell (current-buffer)))
(defun new-browser-tab ()
"Open a new browser tab in the default browser."
(interactive)
(shell-command "open http://google.com"))
(defun retabify-buffer ()
"Apply a reindent operation on the entire buffer."
(interactive)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))
(defun retabify-buffer-to (tab-size)
"Apply a reindent operation on the entire buffer with new TAB-SIZE."
(interactive "nNew buffer tab size: ")
(setq tab-width tab-size)
(setq js-indent-level tab-size)
(retabify-buffer))
(defun duplicate-line-or-region (&optional n)
"Duplicate current line, or region if active.
With argument N, make N copies.
With negative N, comment out original line and use the absolute value.
Taken from https://stackoverflow.com/a/4717026/881224"
(interactive "*p")
(let ((use-region (use-region-p)))
(save-excursion
(let ((text (if use-region ;Get region if active, otherwise line
(buffer-substring (region-beginning) (region-end))
(prog1 (thing-at-point 'line)
(end-of-line)
(if (< 0 (forward-line 1)) ;Go to beginning of next line, or make a new one
(newline))))))
(dotimes (i (abs (or n 1))) ;Insert N times, or once if not specified
(insert text))))
(if use-region nil ;Only if we're working with a line (not a region)
(let ((pos (- (point) (line-beginning-position)))) ;Save column
(if (> 0 n) ;Comment out original with negative arg
(comment-region (line-beginning-position) (line-end-position)))
(forward-line 1)
(forward-char pos)))))
;custom keys
;;;;;;;;;;;;
(global-unset-key (kbd "C-x l")) ;; count-lines-page
;global
(global-set-key [(control f5)] 'restart-shell)
(global-set-key [(control f9)] 'reload-init)
(global-set-key [(control f11)] 'show-file-name)
(global-set-key [(control f12)] 'describe-key)
(global-set-key [(control tab)] 'company-complete)
(global-set-key (kbd "<s-return>") 'newline-and-indent)
(global-set-key (kbd "C-S-z") (lambda () (interactive) (forward-whitespace -1)))
(global-set-key (kbd "C-S-t") 'recentf-open-most-recent-file)
(global-set-key (kbd "C-c /") 'comment-region)
(global-set-key (kbd "C-c <backtab>") 'retabify-buffer-to)
(global-set-key (kbd "C-c <tab>") 'retabify-buffer)
(global-set-key (kbd "C-c ?") 'uncomment-region)
(global-set-key (kbd "C-c R") 'reverse-region)
(global-set-key (kbd "C-c S") 'sort-lines)
(global-set-key (kbd "C-c W") 'flush-blank-lines)
(global-set-key (kbd "C-c a g") 'helm-do-ag-project-root)
(global-set-key (kbd "C-c d") 'duplicate-line-or-region)
(global-set-key (kbd "C-c n") 'flycheck-next-error)
(global-set-key (kbd "C-c p") 'flycheck-previous-error)
(global-set-key (kbd "C-c w") 'whitespace-cleanup)
(global-set-key (kbd "C-c ~") 'flycheck-buffer)
(global-set-key (kbd "C-x !") 'winner-undo)
(global-set-key (kbd "C-x @") 'winner-redo)
(global-set-key (kbd "C-x <down>") 'git-gutter:next-hunk)
(global-set-key (kbd "C-x <up>") 'git-gutter:previous-hunk)
(global-set-key (kbd "C-x C-z") nil) ;; stop annoying suspend frame behavior
(global-set-key (kbd "C-x M-s-<down>") 'halve-this-window-height)
(global-set-key (kbd "C-x M-s-<up>") 'halve-other-window-height)
(global-set-key (kbd "C-x a") 'git-gutter:stage-hunk)
(global-set-key (kbd "C-x c o") 'git-gutter:revert-hunk)
(global-set-key (kbd "C-x n") 'rename-buffer)
(global-set-key (kbd "C-z") 'forward-whitespace)
(global-set-key (kbd "M-<down>") 'forward-paragraph)
(global-set-key (kbd "M-<up>") 'backward-paragraph)
(global-set-key (kbd "M-s-<down>") 'windmove-down)
(global-set-key (kbd "M-s-<left>") 'windmove-left)
(global-set-key (kbd "M-s-<right>") 'windmove-right)
(global-set-key (kbd "M-s-<up>") 'windmove-up)
(global-set-key (kbd "s-t") 'new-browser-tab)
(global-set-key (kbd "s-{") 'previous-buffer)
(global-set-key (kbd "s-}") 'next-buffer)
;multiple-cursors
(global-set-key (kbd "C-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-auto-revert-mode t)
(global-linum-mode t)
(setq default-directory "~")
(setq inhibit-startup-message t)
(setq ring-bell-function 'ignore)
(setq ispell-program-name "/usr/local/bin/ispell")
(show-paren-mode 1)
;extra mode configs
(setq-default indent-tabs-mode nil)
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'erase-buffer 'disabled nil)
;; this gets ag working
(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
(setq exec-path (append exec-path '("/usr/local/bin")))
(exec-path-from-shell-initialize)
(server-start)
(setq confirm-kill-emacs 'y-or-n-p)
(provide 'init)
;;; init.el ends here
(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.
)