blob: 9c46633b719f8c8a1ae96b6f3ec561e94dc10c80 (
plain)
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
|
;; This config requires Emacs 24.4(+?)
;; Hey, Emacs: -*- Indent-tabs-mode: nil -*-
;; 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 :height 80)
;;;; Package management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; package.el
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(setq package-enable-at-startup nil)
(package-initialize)
;; use-package.el
(setq use-package-always-ensure t)
(add-to-list 'load-path (concat user-emacs-directory "use-package"))
(require 'use-package)
(require 'bind-key)
;; Themes
(use-package abyss-theme
:config (load-theme 'abyss t))
;; Minor modes
;(use-package dtrt-indent ;; Detect indent style for existing files
; :config (dtrt-indent-mode 1))
(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))))
(use-package editorconfig
:config (editorconfig-mode 1))
(use-package outline-magic
:commands (outline-cycle
outline-next-line
outline-move-subtree-up
outline-move-subtree-down
outline-promote
outline-demote))
;; Major modes (non-HTML-related)
(use-package bats-mode :mode "\\.bats\\'")
(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 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 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 "\\.ts\\'")
(use-package web-mode :mode "\\.html\\'")
;;(use-package nxhtml) ; nxhtml is invasive, only enable if actively using
;; IDK? I guess I decided that plain php-mode had improved?
;;
;;(use-package php-mode-improved
;; :mode (("\\.php[s34]?\\'" . php-mode)
;; ("\\.phtml\\'" . php-mode)
;; ("\\.inc\\'" . php-mode))
;; :config (add-hook 'php-mode-hook
;; '(lambda ()
;; (c-set-offset 'cpp-macro 0)
;; )))
(if (file-exists-p "~/Maildir")
;;'(apel flim semi wanderlust)
(use-package wanderlust
: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
)
;; 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 'outline-minor-mode-hook
(lambda ()
(define-key outline-minor-mode-map [C-tab] 'outline-cycle)))
(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))
;; Anything that gets magically appended ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|