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
|
;; Hey, Emacs: -*- Indent-tabs-mode: nil -*-
;; This config requires Emacs 27.
;; With some differences in package.el initialization it should work with Emacs 24.4(+?).
;; Without (advice-add) it should work in older versions of Emacs 24.
;;;; Use XDG-ish locations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(let ((xdg-cache-home (file-name-as-directory (or (getenv "XDG_CACHE_HOME") "~/.cache")))
(xdg-data-home (file-name-as-directory (or (getenv "XDG_DATA_HOME") "~/.local/share"))))
(setq
wl-init-file (concat user-emacs-directory "wl.el")
eshell-directory-name (concat xdg-data-home "emacs/eshell/") ;; actually should be split between config and data
ido-save-directory-list-file (concat xdg-data-home "emacs/ido.last.el")
package-user-dir (concat xdg-cache-home "emacs/elpa")
el-get-dir (concat xdg-cache-home "emacs/el-get/")
wl-score-files-directory (concat xdg-cache-home "emacs/wl-score-files/")
elmo-msgdb-directory (concat xdg-cache-home "emacs/elmo-msgdb/")
elmo-cache-directory (concat xdg-cache-home "emacs/elmo-cache/")
auto-save-list-file-prefix (concat xdg-cache-home "emacs/auto-save-list/saves-")
tramp-persistency-file-name (concat xdg-cache-home "emacs/tramp-cache.el")
))
(setq custom-file (concat user-emacs-directory "custom.el"))
(load custom-file 'noerror)
;;;; The basics that I can't use Emacs without ;;;;;;;;;;;;;;;;;;;;;;;
(show-paren-mode 1)
(column-number-mode 1)
(line-number-mode 1)
(ido-mode 1)
(unless (daemonp) (server-mode 1))
(when (require 'whitespace nil t)
(setq whitespace-style '(
tab-mark
space-mark
newline-mark
empty
))
(global-set-key "\C-cw" 'global-whitespace-mode))
(setq minibuffer-prompt-properties '(
read-only t
point-entered minibuffer-avoid-prompt
face minibuffer-prompt
))
;;;; Early settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This isn't particularly important, but set it before doing a whole
;; lot (loading packages), so there isn't a weird change in text size.
(set-face-attribute 'default nil
:family "DejaVu Sans Mono"
:height 80
;:weight 'semi-bold
)
;;;; Package management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; package.el
(when (require 'package)
;; Don't clutter custom.el with `package-selected-packages`; I want
;; to exclusively use use-package for this.
(defun package--save-selected-packages--nocustom (&optional value)
"Set `package-selected-packages' to VALUE."
(when value
(setq package-selected-packages value)))
(advice-add 'package--save-selected-packages
:override #'package--save-selected-packages--nocustom)
;; Add Melpa repos.
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/") t)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
;; Always prefer versions from GNU > Melpa-Stable > Melpa, even if the
;; later have higher version numbers.
(setq package-archive-priorities
'(("gnu" . 99)
("melpa-stable" . 5)
("melpa" . 0)))
(package-initialize))
;; use-package.el
(eval-when-compile
(add-to-list 'load-path (concat user-emacs-directory "use-package"))
(require 'use-package)
(setq use-package-always-ensure t))
(require 'bind-key)
;; Themes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package modus-themes
:config (progn
;; Modus makes MMM regions almost impossible to see
(add-hook 'modus-themes-after-load-theme-hook
(lambda ()
(modus-themes-with-colors
(custom-set-faces
`(mmm-cleanup-submode-face ((,class :background ,yellow-refine-bg)))
`(mmm-code-submode-face ((,class :background ,bg-active)))
`(mmm-comment-submode-face ((,class :background ,blue-refine-bg)))
`(mmm-declaration-submode-face ((,class :background ,cyan-refine-bg)))
`(mmm-default-submode-face ((,class :background ,bg-alt)))
`(mmm-init-submode-face ((,class :background ,magenta-refine-bg)))
`(mmm-output-submode-face ((,class :background ,red-refine-bg)))
`(mmm-special-submode-face ((,class :background ,green-refine-bg)))))
))
;; Load the theme. Use this function instead of
;; load-theme in order to get the above hook.
(modus-themes-load-vivendi)
))
;; Minor modes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package editorconfig
:config (progn
(editorconfig-mode 1)
(add-to-list 'editorconfig-indentation-alist '(protobuf-mode c-basic-offset))
(add-to-list 'editorconfig-indentation-alist '(terraform-mode terra-indent-level
terraform-indent-level
hcl-indent-level))
))
(use-package jq-format
:commands (jq-format-json-buffer
jq-format-json-region
jq-format-json-on-save-mode
jq-format-jsonlines-buffer
jq-format-jsonlines-region
jq-format-jsonlines-on-save-mode))
(use-package multiple-cursors
:bind (("C-c m l" . mc/edit-lines)
("C-c m n" . mc/insert-numbers)))
(use-package outline-magic
:commands (outline-cycle
outline-next-line
outline-move-subtree-up
outline-move-subtree-down
outline-promote
outline-demote))
(use-package page-break-lines ;; Display form-feeds pretty
:init (advice-add 'page-break-lines-mode-maybe
:override #'page-break-lines-mode)
:config (global-page-break-lines-mode 1))
(use-package smart-tabs-mode ;; Indent with tabs, align with spaces
:config (progn
(smart-tabs-mode 1)
(apply 'smart-tabs-insinuate
(mapcar 'car smart-tabs-insinuate-alist))))
;; Major modes (non-HTML-related) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package bats-mode :mode "\\.bats\\'")
(use-package bazel
:mode (((rx "/" (or "BUILD" "BUILD.bazel") eos) . bazel-build-mode)
((rx "/" (or "WORKSPACE" "WORKSPACE.bazel") eos) . bazel-workspace-mode)
((rx "/" (+ nonl) ".bzl" eos) . bazel-starlark-mode)
((rx "/" (or "bazel.bazelrc" ".bazelrc") eos) . bazelrc-mode)
((rx "/.bazelignore" eos) . bazelignore-mode)))
(use-package bison-mode
:mode (("\\.l\\'" . bison-mode)
("\\.y\\'" . bison-mode)
("\\.jison\\'" . jison-mode)))
(use-package cmake-mode :mode ("CMakeLists\\.txt\\'" "\\.cmake\\'"))
(use-package dockerfile-mode
:mode "Dockerfile\\(?:\\..*\\)?\\'"
:commands (dockerfile-build-buffer
dockerfile-build-no-cache-buffer))
(use-package glsl-mode :mode ("\\.vert\\'" "\\.frag\\'" "\\.geom\\'" "\\.glsl\\'"))
(use-package go-mode :mode ("\\.go\\'" "go\\.mod"))
(use-package graphql-mode :mode ("\\.graphql\\'" "\\.gql\\'"))
(use-package graphviz-dot-mode
:mode ("\\.dot\\'" "\\.gv\\'")
:config (add-hook 'graphviz-dot-mode-hook
(lambda ()
(set (make-local-variable 'graphviz-dot-auto-indent-on-semi) nil)
)))
(use-package jq-mode
:mode "\\.jq\\'"
:interpreter "jq")
(use-package lua-mode
:mode "\\.lua\\'"
:interpreter "lua")
(use-package markdown-mode :mode ("\\.markdown\\'" "\\.md\\'" "\\.ronn\\'"))
(use-package meson-mode :mode "/meson\\(\\.build\\|_options\\.txt\\)\\'")
(use-package nginx-mode :mode ("nginx\\.conf\\'" "/nginx/.+\\.conf\\'"))
(use-package protobuf-mode :mode "\\.proto\\'")
(use-package terraform-mode :mode "\\.tf\\(vars\\)?\\'")
(use-package yaml-mode
:mode "\\.\\(e?ya?\\|ra\\)ml\\'"
:config (add-hook 'yaml-mode-hook
(lambda ()
(outline-minor-mode t)
(set (make-local-variable 'outline-regexp) "[ \t]*[A-Za-z-]")
)))
;; Major modes (HTML-related) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package coffee-mode
:mode ("\\.coffee\\'"
"\\.iced\\'"
"\\Cakefile\\'"
"\\.cson\\'")
:interpreter "coffee"
:config (add-hook 'coffee-mode-hook
(lambda ()
(set (make-local-variable 'tab-width) 2)
(set (make-local-variable 'indent-tabs-mode) nil)
)))
(use-package haml-mode :mode "\\.haml\\'")
(use-package less-css-mode :mode "\\.less\\'")
(use-package php-mode
:mode ("\\.php[s345t]?\\'" "/\\.php_cs\\(\\.dist\\)?\\'" "\\.phtml\\'" "/Amkfile\\'" "\\.amk\\'")
:interpreter "php\\(?:-?[3457]\\(?:\\.[0-9]+\\)*\\)?")
(use-package scss-mode :mode "\\.scss\\'")
(use-package typescript-mode :mode "\\.tsx?\\'")
(use-package web-mode
:mode ("\\.html\\'"
"\\.vue\\'"))
(use-package mmm-mode
:load mmm-auto
:config (progn
;; Define the class
(mmm-add-classes
'((js-graphql
:submode graphql-mode
:face mmm-code-submode-face
:front "[^a-zA-Z]graphql`"
:back "`")))
;; Add too mmm-mode-ext-classes-alist
(mmm-add-mode-ext-class 'js-mode nil 'js-graphql)
(setq
;; Enable MMM for modes/files named in
;; mmm-mode-ext-classes-alist, and only modes/files named
;; in mmm-mode-ext-classes-alist.
mmm-global-mode 'maybe
;; 0 = none, 1 = low, 2 = high
mmm-submode-decoration-level 2)
))
;; Email ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (file-exists-p "~/Maildir")
(use-package wanderlust
:commands (wl)
:config (progn
(define-mail-user-agent
'wl-user-agent
'wl-user-agent-compose
'wl-draft-send
'wl-draft-kill
'mail-send-hook)
(setq mail-user-agent 'wl-user-agent))))
;; Misc. crap
(when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(setq inhibit-startup-screen t)
(setq-default truncate-lines t)
(defun align-regexp--use-spaces (orig-fun &rest args)
"Use spaces for alignment"
(let ((indent-tabs-mode nil))
(apply orig-fun args)))
(advice-add 'align-regexp :around
#'align-regexp--use-spaces)
(defun sh-smie-sh-rules--fix (args)
"Replace :after \"then\" with :after \"if\" because Emacs 24
sh-script.el is broken."
(if (equal args (list :after "then"))
(list :after "if")
args))
(advice-add 'sh-smie-sh-rules :filter-args
#'sh-smie-sh-rules--fix)
;; Ideally, figuring this out should be done by uniquify, but I
;; haven't determined how to get uniquify to think that it manages the
;; term buffer.
(defun term-get-short-cwd ()
;; local base=$PWD
;; local suffix=''
;; # The regex here is a list of directory names
;; # that aren't really helpful, and that the
;; # parent directory should be included also.
;; if [[ $base =~ (/(src|pkg|doc|pkg-libre|src-libre|trunk|tags|branches))*$ ]]; then
;; suffix=$BASH_REMATCH
;; base=${base%$suffix}
;; fi
;; base=${base##*/}
;; echo ${base}${suffix}
(directory-file-name default-directory))
(defun term-handle-ansi-terminal-messages--uniquify (args)
(rename-buffer (concat
(replace-regexp-in-string "<.*>$" "" (buffer-name))
"<"
(term-get-short-cwd)
">")
t))
(advice-add 'term-handle-ansi-terminal-messages :after
#'term-handle-ansi-terminal-messages--uniquify)
;; Make the mouse work in an xterm
(when (fboundp 'xterm-mouse-mode)
(xterm-mouse-mode 1)
(add-hook 'after-make-frame-functions
(lambda (frame)
(if xterm-mouse-mode (xterm-mouse-mode 1))
)))
;; Make TRAMP obey ~/.ssh/config for ControlMaster. For some reason,
;; customize doesn't correctly set this.
(setq tramp-use-ssh-controlmaster-options nil)
;; Use mailcrypt to encrypt/decrypt email
(when (require 'mailcrypt nil t)
(mc-setversion "gpg")
(add-hook 'wl-summary-mode-hook 'mc-install-read-mode)
(add-hook 'wl-mail-setup-hook 'mc-install-write-mode)
(defun mc-wl-verify-signature ()
(interactive)
(save-window-excursion
(wl-summary-jump-to-current-message)
(mc-verify)))
(defun mc-wl-decrypt-message ()
(interactive)
(save-window-excursion
(wl-summary-jump-to-current-message)
(let ((inhibit-read-only t))
(mc-decrypt))))
(eval-after-load "mailcrypt"
'(setq mc-modes-alist
(append
(quote
((wl-draft-mode (encrypt . mc-encrypt-message)
(sign . mc-sign-message))
(wl-summary-mode (decrypt . mc-wl-decrypt-message)
(verify . mc-wl-verify-signature))))
mc-modes-alist)))
)
;; Indent settings
(setq-default
indent-tabs-mode t
tab-width 8
c-basic-offset 8
sh-basic-offset 8
sh-indent-comment t
)
;; Backup settings
(setq
backup-by-copying t ;; don't clobber symlinks
backup-directory-alist '(("." . "~/.cache/emacs/saves")) ;; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t ;; use versioned backups
create-lockfiles nil ;; don't litter my fs tree
)
;; Web browser settings
(setq
browse-url-generic-program (executable-find "v-www-browser")
browse-url-browser-function 'browse-url-generic
)
;; Ediff settings
(setq
ediff-window-setup-function 'ediff-setup-windows-plain
ediff-split-window-function 'split-window-horizontally
)
;; Automatically load smerge mode for merge files
(defun try-smerge-mode ()
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^<<<<<<< " nil t)
(smerge-mode 1))))
(add-hook 'find-file-hook 'try-smerge-mode t)
;; http://www.emacswiki.org/emacs/XModMapMode
(when (not (fboundp 'xmodmap-mode))
(define-generic-mode 'xmodmap-mode
'(?!)
'("add" "clear" "keycode" "keysym" "pointer" "remove")
nil
'("[xX]modmap\\(rc\\)?\\'")
nil
"Simple mode for xmodmap files."))
;; All my weird mode-specific settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'lisp-mode-hook
(lambda ()
(set (make-local-variable 'indent-tabs-mode) nil)
))
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(set (make-local-variable 'indent-tabs-mode) nil)
))
(add-hook 'term-mode-hook
(lambda ()
(auto-fill-mode -1)
(setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *")
(set (make-local-variable 'mouse-yank-at-point) t)
(setq tab-width 8 )
(setq truncate-lines nil)
(set (make-local-variable 'autopair-dont-activate) t) ;; Don't let autopair break ansi-term
))
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable 'indent-tabs-mode) t)
(set (make-local-variable 'ruby-indent-level) 4)
(set (make-local-variable 'tab-width) 4)
))
(add-hook 'tex-mode-hook
(lambda ()
(set (make-local-variable 'tab-always-indent) nil)
(set (make-local-variable 'indent-tabs-mode) t)
))
(add-hook 'sh-mode-hook
(lambda ()
(sh-electric-here-document-mode 0)
))
(add-hook 'erc-mode-hook
(lambda ()
(define-key erc-mode-map (kbd "C-c C-u") 'erc-cmd-QUERY)
))
(add-hook 'js-mode-hook
(lambda ()
(hs-minor-mode t)
(local-set-key [C-tab] 'hs-toggle-hiding)
))
(add-hook 'python-mode-hook
(lambda ()
(hs-minor-mode t)
(local-set-key [C-tab] 'hs-toggle-hiding)
))
(add-hook 'outline-minor-mode-hook
(lambda ()
(define-key outline-minor-mode-map [C-tab] 'outline-cycle)))
(add-hook 'web-mode-hook
(lambda ()
(setq web-mode-enable-auto-closing nil)
(setq web-mode-enable-auto-pairing nil)
(setq web-mode-enable-auto-opening nil)
(setq web-mode-enable-auto-quoting nil)
(setq web-mode-enable-auto-expanding nil)
(setq web-mode-enable-auto-indentation nil)
))
(add-to-list 'auto-mode-alist '("PKGBUILD" . sh-mode))
(add-to-list 'auto-mode-alist '("SRCBUILD" . sh-mode))
(add-to-list 'auto-mode-alist '("\\.mak\\'" . makefile-gmake-mode))
(add-to-list 'auto-mode-alist '("\\.jad\\'" . java-mode))
(add-to-list 'auto-mode-alist '("\\.schema\\'" . js-mode))
(eval-when-compile
(add-to-list 'load-path (concat user-emacs-directory "go-template-mode"))
(require 'go-template-mode))
;; Anything that gets magically appended ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|