forked from skeeto/.emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
469 lines (406 loc) · 13.4 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
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
;;; init.el --- -*- lexical-binding: t; -*-
;;; Commentary:
;; Use this at the top of your .emacs file for local overrides:
;; (let ((init "~/.emacs.d/init.elc"))
;; (if (file-exists-p init)
;; (load-file init)
;; (load-file (substring init 0 -1))))
;;; Code:
(make-directory (locate-user-emacs-file "local") :no-error)
(add-to-list 'load-path "~/.emacs.d/lisp")
(add-to-list 'load-path
(format "~/.emacs.d/site-lisp/%s" emacs-version))
(add-to-list 'load-path
(format "~/.emacs.d/site-lisp/%s/lisp" emacs-version))
(add-to-list 'load-path
(format "~/.emacs.d/site-lisp/%s/etc" emacs-version))
;; Package bootstrap
(load-file "~/.emacs.d/packages.el")
(require 'autoloads)
(setf package-enable-at-startup nil)
(require 'use-package)
;; "Local" packages
(require 'unannoy)
(require 'extras)
(require 'ctags)
;; Some global keybindings
(global-set-key (kbd "C-x k") #'kill-this-buffer)
;;; auto-mode-alist entries
(add-to-list 'auto-mode-alist '("\\.mom$" . nroff-mode))
(add-to-list 'auto-mode-alist '("[._]bash.*" . shell-script-mode))
(add-to-list 'auto-mode-alist '("Cask" . emacs-lisp-mode))
(add-to-list 'auto-mode-alist '("[Mm]akefile" . makefile-gmake-mode))
(add-to-list 'auto-mode-alist '("\\.mak$" . makefile-gmake-mode))
(add-to-list 'auto-mode-alist '("\\.make$" . makefile-gmake-mode))
;; Frames and fonts
(defvar my-preferred-fonts
'("Noto Mono-10"
"Inconsolata-12"))
(defun my-set-preferred-font (&optional frame)
"Set the first available font from `my-preferred-fonts'."
(catch 'done
(with-selected-frame (or frame (selected-frame))
(dolist (font my-preferred-fonts)
(when (ignore-errors (x-list-fonts font))
(set-frame-font font)
(throw 'done nil))))))
(defun my-set-frame-fullscreen (&optional frame)
(set-frame-parameter frame 'fullscreen 'fullheight))
(add-hook 'after-make-frame-functions #'my-set-preferred-font)
(add-hook 'after-make-frame-functions #'my-set-frame-fullscreen t)
;;; Individual package configurations
(use-package dabbrev
:defer t
:init (setf abbrev-file-name (locate-user-emacs-file "local/abbrev_defs"))
:config (setf dabbrev-case-fold-search nil))
(use-package impatient-mode
:defer t
:config
(defun imp-markdown-filter (in)
(let ((out (current-buffer)))
(with-current-buffer in
(markdown out))))
(push (cons 'markdown-mode #'imp-markdown-filter)
imp-default-user-filters))
(use-package dired
:defer t
:config
(progn
(add-hook 'dired-mode-hook #'toggle-truncate-lines)
(setf dired-listing-switches "-alhG"
dired-guess-shell-alist-user
'(("\\.pdf\\'" "evince")
("\\(\\.ods\\|\\.xlsx?\\|\\.docx?\\|\\.csv\\)\\'" "libreoffice")
("\\(\\.png\\|\\.jpe?g\\)\\'" "qiv")
("\\.gif\\'" "animate")))))
(use-package elfeed
:defer t
:bind ("C-x w" . elfeed)
:init (setf url-queue-timeout 30)
:config
(require 'feed-setup)
(push "-k" elfeed-curl-extra-arguments)
(setf bookmark-default-file (locate-user-emacs-file "local/bookmarks")))
(use-package youtube-dl
:defer t
:bind ("C-x y" . youtube-dl-list))
(use-package lisp-mode
:defer t
:config
(progn
(defun ert-all ()
(interactive)
(ert t))
(defun ielm-repl ()
(interactive)
(pop-to-buffer (get-buffer-create "*ielm*"))
(ielm))
(define-key emacs-lisp-mode-map (kbd "C-c C-z") #'ielm-repl)
(defalias 'lisp-interaction-mode 'emacs-lisp-mode)))
(use-package undo-tree
:init
(setf undo-tree-mode-lighter ""))
(use-package evil
:init
(setf evil-want-C-u-scroll t)
:config
(evil-mode)
(defvar my-leader-map
(let ((map (make-sparse-keymap)))
(prog1 map
(define-key map "w" 'elfeed))))
(define-key evil-normal-state-map "\\" my-leader-map)
(define-key evil-normal-state-map (kbd "M-.") #'ctags-find)
(define-key evil-normal-state-map (kbd "M-?") #'ctags-find-reference)
(add-to-list 'evil-emacs-state-modes 'elfeed-search-mode)
(add-to-list 'evil-emacs-state-modes 'elfeed-show-mode)
(add-to-list 'evil-emacs-state-modes 'special-mode)
(add-to-list 'evil-emacs-state-modes 'youtube-dl-list-mode)
(add-to-list 'evil-emacs-state-modes 'process-menu-mode)
(evil-select-search-module 'evil-search-module 'evil-search)
(setf evil-ex-search-highlight-all nil)
(add-hook 'with-editor-mode-hook 'evil-insert-state)
(add-hook 'emacs-lisp-mode-hook (lambda () (modify-syntax-entry ?- "w")))
(add-hook 'c-mode-common-hook (lambda () (modify-syntax-entry ?_ "w"))))
(use-package evil-smartparens
:defer t
:init
(add-hook 'smartparens-enabled-hook #'evil-smartparens-mode)
(add-hook 'emacs-lisp-mode-hook #'smartparens-strict-mode)
:config
(sp-local-pair '(emacs-lisp-mode) "'" "'" :actions nil)
(sp-local-pair '(emacs-lisp-mode) "`" "`" :actions nil)
(sp-use-paredit-bindings))
(use-package time
:config
(progn
(setf display-time-default-load-average nil
display-time-use-mail-icon t
display-time-24hr-format t)
(display-time-mode t)))
(use-package comint
:defer t
:config
(progn
(define-key comint-mode-map (kbd "<down>") #'comint-next-input)
(define-key comint-mode-map (kbd "<up>") #'comint-previous-input)
(define-key comint-mode-map (kbd "C-n") #'comint-next-input)
(define-key comint-mode-map (kbd "C-p") #'comint-previous-input)
(define-key comint-mode-map (kbd "C-r") #'comint-history-isearch-backward)
(setf comint-prompt-read-only t
comint-history-isearch t)))
(use-package tramp
:defer t
:config
(setf tramp-persistency-file-name
(concat temporary-file-directory "tramp-" (user-login-name))))
(use-package diff-mode
:defer t
:config (add-hook 'diff-mode-hook #'read-only-mode))
(use-package color-theme-sanityinc-tomorrow
:config
(setf custom-safe-themes t)
(color-theme-sanityinc-tomorrow-night)
(global-hl-line-mode 1)
(custom-set-faces
'(cursor ((t :background "#eebb28")))))
(use-package simple
:defer t
:config
(progn
;; disable so I don't use it by accident
(define-key visual-line-mode-map (kbd "M-q") (expose (lambda ())))
(add-hook 'tabulated-list-mode-hook #'hl-line-mode)))
(use-package uniquify
:defer t
:config
(setf uniquify-buffer-name-style 'post-forward-angle-brackets))
(use-package winner
:config
(winner-mode 1)
(windmove-default-keybindings))
(use-package calc
:defer t
:config (setf calc-display-trail nil))
(use-package eshell
:defer t
:bind ([f1] . eshell-as)
:init
(setf eshell-directory-name (locate-user-emacs-file "local/eshell"))
:config
(add-hook 'eshell-mode-hook ; Bad, eshell, bad!
(lambda ()
(define-key eshell-mode-map (kbd "<f1>") #'quit-window))))
(use-package gitconfig-mode
:defer t
:config (add-hook 'gitconfig-mode-hook
(lambda ()
(setf indent-tabs-mode nil
tab-width 4))))
(use-package markdown-mode
:defer t
:mode ("\\.md$" "\\.markdown$" "vimperator-.+\\.tmp$")
:config
(add-hook 'markdown-mode-hook
(lambda ()
(remove-hook 'fill-nobreak-predicate
'markdown-inside-link-p t)))
(setf sentence-end-double-space nil
markdown-indent-on-enter nil
markdown-command
"pandoc -f markdown -t html5 -s --self-contained --smart"))
(use-package octave
:defer t
:config
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
(setf octave-block-offset 4))
(use-package simple-httpd
:defer t
:functions httpd-send-header
:config
(defservlet uptime "text/plain" ()
(princ (emacs-uptime)))
(defun httpd-here ()
(interactive)
(setf httpd-root default-directory))
(defadvice httpd-start (after httpd-query-on-exit-flag activate)
(let ((httpd-process (get-process "httpd")))
(when httpd-process
(set-process-query-on-exit-flag httpd-process nil))))
(setf httpd-host "0.0.0.0"))
(use-package js2-mode
:defer t
:mode "\\.js$"
:config
(add-hook 'js2-mode-hook (lambda () (setq mode-name "js2")))
(setf js2-skip-preprocessor-directives t)
(setq-default js2-additional-externs
'("$" "unsafeWindow" "localStorage" "jQuery"
"setTimeout" "setInterval" "location" "skewer"
"console" "phantom")))
(use-package skewer-mode
:defer t
:init
(skewer-setup))
(use-package skewer-repl
:defer t
:config (define-key skewer-repl-mode-map (kbd "C-c C-z") #'quit-window))
(use-package ps-print
:defer t
:config (setf ps-print-header nil))
(use-package erc
:defer t
:config
(when (eq 0 (string-match "wello" (user-login-name)))
(setf erc-nick "skeeto")))
(use-package cc-mode
:defer t
:init
(defun skeeto/c-hook ()
(setf c-basic-offset 4)
(c-set-offset 'case-label '+)
(c-set-offset 'access-label '/)
(c-set-offset 'label '/))
:config
(progn
(define-key java-mode-map (kbd "C-x I") 'add-java-import)
(add-hook 'c-mode-hook #'skeeto/c-hook)
(add-hook 'c++-mode-hook #'skeeto/c-hook)
(add-to-list 'c-default-style '(c-mode . "k&r"))
(add-to-list 'c-default-style '(c++-mode . "k&r"))))
(use-package ctags
:init
(global-set-key (kbd "M-.") #'ctags-find)
(global-set-key (kbd "M-?") #'ctags-find-reference))
(use-package nasm-mode
:defer t
:mode ("\\.nasm$" "\\.asm$" "\\.s$")
:config
(add-hook 'nasm-mode-hook (lambda () (setf indent-tabs-mode t))))
(use-package asm-mode
:defer t
:init
(add-hook 'asm-mode-hook (lambda () (setf indent-tabs-mode t
tab-always-indent t))))
(use-package x86-lookup
:defer t
:bind ("C-h x" . x86-lookup)
:functions x86-lookup-browse-pdf-evince
:config
(let ((pdf-regexp ".*sdm-vol-2abcd\\.pdf$")
(pdf-dir "~/doc/"))
(setf x86-lookup-browse-pdf-function #'x86-lookup-browse-pdf-evince
x86-lookup-pdf (ignore-errors
(car (directory-files pdf-dir t pdf-regexp))))))
(use-package ielm
:defer t
:config
(define-key ielm-map (kbd "C-c C-z") #'quit-window))
(use-package paren
:config (show-paren-mode))
(use-package rainbow-delimiters
:defer t
:init
(add-hook 'emacs-lisp-mode-hook #'rainbow-delimiters-mode)
(add-hook 'ielm-mode-hook #'rainbow-delimiters-mode)
:config
(set-face-foreground 'rainbow-delimiters-depth-1-face "snow4")
(setf rainbow-delimiters-max-face-count 1)
(set-face-attribute 'rainbow-delimiters-unmatched-face nil
:foreground 'unspecified
:inherit 'error)
(set-face-foreground 'rainbow-delimiters-depth-1-face "snow4"))
(use-package icomplete
:init
(icomplete-mode)
:bind (:map icomplete-minibuffer-map
("<C-tab>" . minibuffer-force-complete)))
(use-package etags
:defer t
:config
(defun etags-build (directory)
(interactive "DDirectory: ")
(let* ((results ())
(head (list directory))
(tail head))
(while head
(dolist (file (directory-files (car head) t nil t))
(cond ((and (not (string-match "\\.$" file))
(not (string-match "\\.\\.$" file))
(file-directory-p file))
(let ((new-tail (list file)))
(setf (cdr tail) new-tail
tail new-tail)))
((string-match "\\.[ch]$" file)
(push file results))))
(pop head))
(let ((default-directory directory))
(apply #'call-process "etags" nil nil nil results)))))
(use-package javadoc-lookup
:defer t
:bind ("C-h j" . javadoc-lookup)
:config
(ignore-errors
(setf javadoc-lookup-cache-dir (locate-user-emacs-file "local/javadoc"))))
(use-package browse-url
:defer t
:init
(setf url-cache-directory (locate-user-emacs-file "local/url"))
:config
(when (executable-find "firefox")
(setf browse-url-browser-function #'browse-url-firefox)))
(use-package uuid-simple
:demand t
:bind ("C-x !" . uuid-insert)
:config (random (make-uuid)))
(use-package compile-bind
:demand t
:bind (("C-h g" . compile-bind-set-command)
("C-h G" . compile-bind-set-root-file))
:config
(progn
(setf compilation-always-kill t
compilation-ask-about-save nil
compilation-scroll-output 'first-error
compile-bind-command (format "make -kj%d " (numcores)))
(when (executable-find "nmake.exe")
(compile-bind-set-command "nmake -nologo "))
(compile-bind* (current-global-map)
("C-x c" ""
"C-x t" 'test
"C-x C" 'clean))))
(use-package jekyll
:demand t
:functions httpd-send-header
:config
(progn
(setf jekyll-home "~/src/skeeto.github.com/")
(when (file-exists-p jekyll-home)
(require 'simple-httpd)
(setf httpd-root (concat jekyll-home "_site"))
(ignore-errors
(httpd-start)
(jekyll/start))
(defservlet robots.txt text/plain ()
(insert "User-agent: *\nDisallow: /\n")))))
(use-package help-mode
:defer t
:config
(define-key help-mode-map (kbd "f") #'push-first-button))
(use-package gamegrid
:defer t
:init
(setf gamegrid-user-score-file-directory (locate-user-emacs-file "games")))
(use-package ospl-mode
:defer t
:init
(autoload 'ospl-mode "ospl-mode"))
(use-package sql
:defer t
:init
(setf sql-product 'sqlite))
(use-package enriched
:defer t
:config
(define-key enriched-mode-map "\C-m" nil))
(provide 'init) ; make (require 'init) happy