-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
292 lines (255 loc) · 9.8 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
;;; package -- init.el
;;; Commentary:
;;; This is my Emacs config.
;;; Code:
;; hooks
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
(progn
(global-set-key (kbd "M-x") 'helm-M-x)
;; konsole keybinds act weird so comments out if needed.
;; (global-set-key (kbd "C-c C-m") 'helm-mini)
;; (global-set-key (kbd "C-c C-b") 'helm-buffers-list)
;; (global-set-key (kbd "C-c C-a") 'helm-apropos)
;; (global-set-key (kbd "C-c C-g") 'helm-grep-do-git-grep)
;; (global-set-key (kbd "C-c q") 'replace-regexp)
(global-set-key (kbd "C-h C-m") 'helm-mini)
(global-set-key (kbd "C-h C-b") 'helm-buffers-list)
(global-set-key (kbd "C-h C-a") 'helm-apropos)
(global-set-key (kbd "C-c t") 'beginning-of-buffer)
(global-set-key (kbd "C-c r") 'end-of-buffer)
(global-set-key (kbd "C-c u") 'ispell-region)
(global-set-key (kbd "C-c ]") 'windmove-right)
(global-set-key (kbd "C-c [") 'windmove-left)
(global-set-key (kbd "C-c <up>") 'windmove-up)
(global-set-key (kbd "C-c <down>") 'windmove-down)
(global-set-key (kbd "C-c <right>") 'windmove-right)
(global-set-key (kbd "C-c <left>") 'windmove-left))
;; konsole keybinds act weird so comments out if needed.
;; (normal-erase-is-backspace-mode 0)
;; (setq help-char nil)
;; (keyboard-translate ?\C-h ?\C-?)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(add-hook 'before-save-hook 'whitespace-cleanup)
(add-hook 'after-init-hook #'global-flycheck-mode)
(add-hook 'flycheck-mode-hook
#'load-eslint-from-node_modules)
(add-hook 'ruby-mode-hook #'rubocop-mode)
(add-hook 'ruby-mode-hook #'ruby-electric-mode)
;; prevent from adding a utf-8 comment
(setq ruby-insert-encoding-magic-comment nil)
(defun search (item)
"Quick search :ITEM."
(interactive "sitem: ")
(shell-command(shell-command-to-string
(concat "chromium https://duckduckgo.com/\?q=" "'"item"'" ))))
(defun json-format ()
"The go-format for json."
(interactive)
(shell-command-on-region (point-min) (point-max)
"python -mjson.tool"
(current-buffer) t))
(define-key global-map (kbd "C-c q") 'replace-regexp)
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
;; control auto-save-list
(setq delete-old-versions -1)
(setq version-control t)
(setq vc-make-backup-files t)
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
(setq backup-directory-alist'(("."."~/.backups")))
(savehist-mode 1)
(setq history-length t)
(setq history-delete-duplicates t)
;; load-path
(defun load-directory (dir)
(let ((loading (lambda (f)
(load-file (concat (file-name-as-directory dir) f)))))
(mapc loading (directory-files dir nil "\\.el$"))))
(load-directory "~/.emacs.d/vendor/")
(load-directory "/usr/share/emacs/site-lisp/")
(load-directory "~/.emacs.d/elpa/")
;; theme
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(load-theme 'jqg t)
(global-hl-line-mode 1)
(set-face-background 'hl-line "green")
(set-face-foreground 'highlight nil)
;; line number
(defvar linum-format
(setq linum-format "%3d \u2502"))
(line-number-mode)
(global-linum-mode 1)
(setq column-number-mode t)
(defun open-nice()
"A macro lets you open windows nice"
(interactive)
(let* ((parent (if (buffer-file-name)
(file-name-directory (buffer-file-name))
default-directory))
(height (/ (window-total-height) 3))
(name (car (last (split-string parent "/" t)))))
(split-window-vertically (- height))
(other-window 1)))
(global-set-key (kbd "C-c o") 'open-nice)
(defun eshell-here()
"Opens up a new shell in the directory associated with the
current buffer's file. The eshell is renamed to match that directory
to make multiple eshell windows easier."
(interactive)
(let* ((parent (if (buffer-file-name)
(file-name-directory (buffer-file-name))
default-directory))
(height (/ (window-total-height) 3))
(name (car (last (split-string parent "/" t)))))
(split-window-vertically (- height))
(other-window 1)
(eshell "new")
(rename-buffer (concat "*eshell: " name "*"))
(insert (concat "ls"))
(eshell-send-input)))
(global-set-key (kbd "C-c e") 'eshell-here)
(global-set-key (kbd "C-x g") 'goto-line)
(global-set-key (kbd "C-c s") 'shell-script-mode)
(global-set-key (kbd "C-c m") 'set-mark-command)
(global-set-key (kbd "C-h C-g") 'helm-grep-do-git-grep)
(add-to-list 'default-frame-alist '(font "Monospace-8"))
(defun eshell/x ()
"Exit eshell."
(insert "exit")
(eshell-send-input)
(delete-window)
)
(defun c-lineup-arglist-tabs-only (ignored)
"Line up argument lists by tabs, not spaces :IGNORED."
(let* ((anchor (c-langelem-pos c-syntactic-element))
(column (c-langelem-2nd-pos c-syntactic-element))
(offset (- (1+ column) anchor))
(steps (floor offset c-basic-offset)))
(* (max steps 1)
c-basic-offset)))
(add-hook 'c-mode-common-hook
(lambda ()
;; Add kernel style
(c-add-style
"linux-tabs-only"
'("linux" (c-offsets-alist
(arglist-cont-nonempty
c-lineup-gcc-asm-reg
c-lineup-arglist-tabs-only))))))
(add-hook 'c-mode-hook
(lambda ()
(let ((filename (buffer-file-name)))
;; Enable kernel mode for the appropriate files
(when (and filename
(string-match (expand-file-name "~/src/linux-trees")
filename))
(setq indent-tabs-mode t)
(setq show-trailing-whitespace t)
(c-set-style "linux-tabs-only")))))
;; cc-mode indent
(setq-default c-basic-offset 4)
;; javascript FUCKS
(defun load-eslint-from-node_modules ()
"Eslint loading from node_modules/eslint/bin/eslint."
(interactive)
(let* ((root (locate-dominating-file
(or (buffer-file-name) default-directory)
"node-module"))
(eslint (and root
(expand-file-name "node_modules/eslint/bin/eslint.js" root))))
(when (and eslint (file-executeable-p eslint))
(setq-local flycheck-javascript-eslint-executeable eslint))))
(defun setup-tide-mode ()
(interactive)
(tide-setup)
(flycheck-add-next-checker 'typescript-tide '(t . typescript-tslint) 'append)
(eldoc-mode +1)
(company-mode +1)
(tide-hl-identifier-mode +1))
;; aligns annotation to the right hand side
(setq company-tooltip-align-annotations t)
;; formats the buffer before saving
;; (add-hook 'before-save-hook 'tide-format-before-save)
(add-hook 'typescript-mode-hook #'setup-tide-mode)
(add-hook 'typescript-mode-hook (setq indent-tabs-mode nil))
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
(add-hook 'typescript-mode-hook
(lambda ()
(when (string-equal "tsx" (file-name-extension buffer-file-name))
(setup-tide-mode))))
;; funky typescript linting in web-mode
(flycheck-add-mode 'typescript-tslint 'web-mode)
(with-eval-after-load 'tide
(flycheck-add-mode 'typescript-tslint 'react-ts-mode)
(flycheck-add-mode 'typescript-tide 'react-ts-mode)
)
(setq web-mode-content-types-alist '(("jsx" . "\\.js[x]?\\'")))
(add-hook 'json-mode-hook (lambda () (setq js-indent-level 2)))
(add-to-list 'auto-mode-alist '("\\.\\(json\\)" . json-mode))
(add-to-list 'flycheck-disabled-checkers 'javascript)
(add-hook 'js-jsx-mode (lambda ()
(setq js-indent-level 4)
(setq indent-tabs-mode nil)))
(setq web-mode-code-indent-offset 2)
(add-to-list 'auto-mode-alist '("\\.\\(html\\|scss\\|css\\|jsx\\|js\\)" . web-mode))
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.\\(zsh\\|sh\\|bash\\|ch\\)" . shell-script-mode))
(add-to-list 'auto-mode-alist '("\\.\\(?:cap\\|gemspec\\|irbrc\\|gemrc\\|rake\\|rb\\|ru\\|thor\\)\\'" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\(?:Brewfile\\|Capfile\\|Gemfile\\(?:\\.[a-zA-Z0-9._-]+\\)?\\|[rR]akefile\\)\\'" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.go'" . go-mode))
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
(add-to-list 'auto-mode-alist '("\\.conf\\'" . conf-mode))
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
(add-to-list 'auto-mode-alist '("\\.slim" . slim-mode))
;; spell check
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
;;; init.el ends here
(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.
'(package-selected-packages
'(scala-mode org-static-blog web-mode tide ruby-electric rubocop magit helm go-mode exec-path-from-shell elpy editorconfig auto-complete)))
(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.
)
;; org-mode export body
;; ref: https://orgmode.org/worg/org-tutorials/org-jekyll.html
(setq org-publish-project-alist
'(
("org-weblog"
;; Path to your org files.
:base-directory "~/.w/blog/_org/"
:base-extension "org"
;; Path to your Jekyll project.
;; :publishing-directory "~/.w/blog/jekyll/"
:publishing-directory "~/.w/blog/_posts/"
:recursive t
:publishing-function org-html-publish-to-html
:headline-levels 4
:html-extension "html"
:body-only t ;; Only export section between <body> </body>
)
("org-static-weblog"
:base-directory "~/.w/blog/_org/"
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|php"
:publishing-directory "~/w/blog"
:recursive t
:publishing-function org-publish-attachment)
("weblog" :components ("org-weblog" "org-static-weblog"))
)
)
;; org-mode shortcuts
(require 'org-tempo)