-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.el
380 lines (333 loc) · 13.3 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
(let ((debian-startup "/usr/share/emacs/site-lisp/debian-startup.el"))
(when (file-exists-p debian-startup)
(load-file debian-startup)))
(setq user-full-name "Dave Vandyke")
(setq user-mail-address "[email protected]")
(load "~/.emacs.d/my-helpers.el")
(load "~/.emacs.d/my-secrets.el")
(setq custom-file "~/.emacs.d/my-custom.el")
(load custom-file)
(require 'cl)
(require 'package)
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(defvar kzar/packages '(ace-window
cider
clojure-mode
dash
epl
font-utils
flycheck
gist
gnus-alias
ir-black-theme
js2-mode
list-utils
lsp-mode
magit
markdown-mode
notmuch
paredit
pcache
persistent-soft
php-mode
pkg-info
puppet-mode
typescript-mode
rust-mode
rvm
ucs-utils
unicode-fonts
web-mode
yaml-mode
yasnippet
org))
(defun abedra/packages-installed-p (packages)
(loop for pkg in packages
when (not (package-installed-p pkg)) do (return nil)
finally (return t)))
(unless (abedra/packages-installed-p kzar/packages)
(message "%s" "Refreshing package database...")
(package-refresh-contents)
(dolist (pkg kzar/packages)
(when (not (package-installed-p pkg))
(package-install pkg))))
(load "~/.emacs.d/lisp/org-notmuch.el")
(setq inhibit-splash-screen t
initial-scratch-message ";; Hello Dave\n"
initial-major-mode 'org-mode)
(prefer-coding-system 'utf-8)
; Make some special Unicode symbols more readable
(unicode-fonts-setup)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
; Enable column numbering
(setq column-number-mode t)
; Highlight matching parenthesis green
(show-paren-mode 1)
(setq show-paren-delay 0)
(set-face-background 'show-paren-match "#99FF00")
; Set default code indent to 2 spaces
(setq tab-width 2
indent-tabs-mode nil)
; Replace zap-to-char with custom zap-up-to-char function
(global-set-key "\M-z" 'zap-up-to-char)
; Magit mode
(global-set-key (kbd "C-c g") 'magit-status)
(global-set-key (kbd "C-x M-g") 'magit-dispatch-popup)
(setq magit-diff-refine-hunk t)
(add-hook 'git-commit-mode-hook (lambda () (flyspell-mode 1)))
(setq magit-last-seen-setup-instructions "2.1.0")
(setq magit-revert-buffers t)
(setq magit-push-always-verify nil)
; org-mode
(add-to-list `auto-mode-alist `("\\.org$" . org-mode))
(define-key global-map (kbd "C-c l") 'org-store-link)
(define-key global-map (kbd "C-c a") 'org-agenda)
(setq org-log-done t)
(setq org-agenda-files '("~/Davebox/todo-org/todo.org"))
(setq org-todo-keywords '((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
(sequence "WAITING(w@/!)" "CANCELLED(c@/!)"))
org-todo-keyword-faces '(("TODO" . (:foreground "black" :weight bold))
("NEXT" . (:foreground "red" :weight bold))
("WAITING" . (:foreground "orange" :weight bold))
("DONE" (:foreground "forest green" :weight bold))
("CANCELLED" (:foreground "forest green" :weight bold)))
org-log-reschedule t
org-todo-repeat-to-state t
calendar-week-start-day 1)
(setq org-log-state-notes-into-drawer t)
(add-hook 'org-mode-hook (lambda () (flyspell-mode 1)))
(setq org-archive-location "%s_archive::"
org-archive-subtree-save-file-p t)
(setq org-startup-indented t)
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(clojure . t)
(python . t)
(ruby . t)
(js . t)))
(setq org-src-fontify-natively t)
(add-to-list 'org-latex-packages-alist '("" "minted"))
(setq org-latex-listings 'minted)
(setq org-latex-pdf-process
'("xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
(eval-after-load "org"
(lambda ()
(require 'ox-md nil t)
(require 'ox-odt nil t)
(require 'ox-publish nil t)
(require 'org-notmuch)))
; IRC
(require 'tls)
(setq rcirc-default-nick "kzar")
(setq rcirc-default-full-name "Dave Vandyke")
(setq rcirc-authinfo
`(("libera" nickserv "kzar" ,(format "%s %s" "kzar" libera-password))
("oftc" nickserv "kzar" ,(format "%s %s" oftc-password "kzar"))))
(setq rcirc-server-alist
`(("irc.libera.chat" :port 6697 :encryption tls)
("irc.oftc.net" :port 6697 :encryption tls)))
(rcirc-track-minor-mode 1)
(add-hook 'rcirc-mode-hook
(lambda ()
(flyspell-mode 1)
(setq rcirc-ignore-buffer-activity-flag t)))
; Tramp
(setq tramp-default-method "ssh")
; Setup buffer switching
(ido-mode)
(setq ido-create-new-buffer 'always
ido-default-buffer-method 'selected-window
ido-default-file-method 'selected-window
ido-enable-flex-matching t)
(add-to-list `ido-ignore-files "~$")
(add-hook 'ido-setup-hook
(lambda ()
(define-key ido-completion-map (kbd "C-c g") 'ido-enter-magit-status)))
; Convenient window switching
(global-set-key (kbd "C-c w") 'ace-window)
; Add to the executable path for executable-find
(add-to-list `exec-path "/usr/local/bin")
(add-to-list `exec-path "/opt/local/bin")
; Highlight tabs and trailing whitespace (custom-set-faces defines colours)
(setq whitespace-style '(face trailing tabs space-mark))
(setq whitespace-global-modes '(not rcirc-mode magit-mode))
(global-whitespace-mode)
; Display zero-width unicode characters as standard spaces so we don't miss them
(setq whitespace-display-mappings '((space-mark ?\x200B [? ])
(space-mark ?\x200C [? ])
(space-mark ?\x200D [? ])
(space-mark ?\xFEFF [? ])))
; Add all unicode characters to tab regexp so we highlight them too
(setq whitespace-tab-regexp "\\([\t[:nonascii:]]\\)")
; Display a long-line indicator for code.
(setq display-fill-column-indicator-column t)
(setq-default fill-column 80)
(add-hook 'prog-mode-hook #'display-fill-column-indicator-mode)
; Flyspell
(setq ispell-program-name "hunspell"
flyspell-issue-welcome-flag nil
ispell-local-dictionary "en_GB"
ispell-local-dictionary-alist
'(("en_GB" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_GB") nil utf-8)))
;; Clojure
(require 'clojure-mode)
(setq nrepl-log-messages t)
(setq nrepl-hide-special-buffers t)
;; JavaScript
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.cjs$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.mjs$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.jsm$" . js2-mode))
(setq js2-highlight-level 3)
(setf js2-bounce-indent-p t)
(add-hook 'js2-mode-hook (lambda () (electric-indent-local-mode -1)))
(setq-default js2-basic-offset 2)
(setq js-indent-level 2)
(add-to-list 'js2-global-externs "globalThis")
;; Typescript
; We're using typescript-mode for syntax highlighting,
; lsp + typescript-language-server for IDE-like functionality and
; js2-mode's bounce-indent for indentation.
(add-to-list 'auto-mode-alist '("\\.ts$" . typescript-mode))
(eval-after-load "typescript-mode"
'(defun typescript-indent-line ()))
(add-hook 'typescript-mode-hook
'(lambda ()
(local-set-key (kbd "<tab>") 'js2-indent-bounce)
(lsp)))
; YAML
(require 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
;; Python
(setq python-indent 2
python-indent-offset 2)
(add-hook 'python-mode-hook
(function (lambda ()
(setq indent-tabs-mode nil
tab-width 2))))
; Ruby
(rvm-use-default)
(defun echo-false-comint ()
(setq comint-process-echoes t))
(add-hook 'comint-mode-hook 'echo-false-comint)
(setq ruby-insert-encoding-magic-comment nil)
(add-to-list 'auto-mode-alist '("Vagrantfile" . ruby-mode))
; Rust
(require 'rust-mode)
(add-to-list 'auto-mode-alist '("\\.rs$" . rust-mode))
(add-hook 'rust-mode 'lsp)
; Clojurescript
(setq auto-mode-alist (cons '("\\.cljs" . clojure-mode) auto-mode-alist))
(defun browser-repl (lisp-path)
(interactive "DCLJS project path: ")
(cd lisp-path)
(run-lisp "/usr/local/bin/lein trampoline cljsbuild repl-listen"))
; Markdown and reStructuredText
(add-to-list `auto-mode-alist `("\\.md$" . markdown-mode))
(add-hook 'markdown-mode-hook (lambda () (flyspell-mode 1)))
(add-hook 'rst-mode-hook (lambda () (flyspell-mode 1)))
; Puppet
(add-to-list `auto-mode-alist `("\\.pp$" . puppet-mode))
; Web-mode
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.pt\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.php$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tmpl?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.vue?\\'" . web-mode))
(setq web-mode-display-table nil)
(setq-default indent-tabs-mode nil)
(set-face-attribute 'web-mode-html-tag-face nil :foreground "blue")
(set-face-attribute 'web-mode-html-attr-name-face nil :foreground "brown")
(set-face-attribute 'web-mode-html-tag-bracket-face nil :foreground "black")
(set-face-attribute 'web-mode-html-attr-equal-face nil :foreground "black")
(set-face-attribute 'web-mode-doctype-face nil :foreground "purple")
(set-face-attribute 'web-mode-function-name-face nil :foreground "blue")
(set-face-attribute 'web-mode-function-call-face nil :foreground "black")
(add-hook 'web-mode-hook
(lambda ()
(local-set-key (kbd "RET") 'newline-and-indent)))
(setq web-mode-code-indent-offset 2)
(setq web-mode-markup-indent-offset 2)
; CSS Mode
(setq css-indent-offset 2)
; Manually indent a region of code, taking care of trailing whitespace
(defun indent-rectangle ()
(interactive)
(when (region-active-p)
(save-excursion
(let ((start (min (region-beginning) (region-end)))
(end (max (region-beginning) (region-end)))
(region-indent nil)
(first-line-start 0)
(last-line-start 0)
(last-line-end 0))
; Record the start / end positions
(goto-char end)
(setq last-line-end (line-end-position))
(goto-char start)
(setq first-line-start (line-beginning-position))
; Figure out the base indentation for the selected region
(while (< (point) last-line-end)
(unless (= (line-end-position) (line-beginning-position))
(setq region-indent (min (or region-indent (current-indentation))
(current-indentation)))
(setq last-line-start (line-beginning-position)))
(forward-line))
; Use rectangle mark mode to select the base indentation and
; prompt the user to alter that region
(push-mark first-line-start)
(goto-char (+ last-line-start region-indent))
(call-interactively 'string-rectangle)
; Clear any trailing whitespace
(delete-trailing-whitespace (region-beginning) (region-end)))
(pop-mark))))
(global-set-key (kbd "C-c SPC") 'indent-rectangle)
; C++
(setq lsp-completion-provider :none)
(require 'lsp)
;(add-hook 'c++-mode-hook 'lsp)
(lsp-register-client
(make-lsp-client :new-connection (lsp-tramp-connection "clangd")
:major-modes '(c++-mode)
:remote? t
:server-id 'clangd-remote))
(defun cpp-indent-setup ()
(c-set-offset 'arglist-intro '+)
(c-set-offset 'arglist-close '0)
(c-set-offset 'statement-cont '+))
(add-hook 'c++-mode-hook 'cpp-indent-setup)
; Enable spell-checking for code comments.
; Note: Can also perform a full check with
; M-x ispell-comments-and-strings
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
; Disable lock files, since they can confuse some tools which watch for file
; changes.
(setq create-lockfiles nil)
; Set DuckDuckGo-specific indentation etc rules.
(dir-locals-set-class-variables
'duckduckgo-directory
'((nil . ((js-indent-level . 4)
(js2-strict-missing-semi-warning . nil)))))
(dir-locals-set-directory-class "~/work/duckduckgo/" 'duckduckgo-directory)
(add-to-list 'auto-mode-alist '("/duckduckgo-privacy-extension/.*\\.js$" .
typescript-mode))
(add-to-list 'auto-mode-alist '("/duckduckgo-privacy-extension/build/.*" .
fundamental-mode))
; Load machine specific settings
; http://emacsblog.org/2007/10/07/declaring-emacs-bankruptcy/#comment-36295
(let ((local-conf-name (format "~/.emacs.d/%s.el" system-name)))
(cond ((file-exists-p local-conf-name)
(load-file local-conf-name))
((message "%s doesn't exist or I'd load it." local-conf-name))))