This repository has been archived by the owner on Jul 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
645 lines (542 loc) · 18.9 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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
;;; init.el --- My personal Emacs configuration. -*- lexical-binding: t; -*-
;; Time-stamp: <2019-08-28 13:35:08 glucas>
;; Author: Greg Lucas <[email protected]>
;; Keywords: dotemacs,init,local
;;; Code:
;; init logging
(message "Starting Emacs %s" emacs-version)
(add-hook 'after-init-hook (lambda () (message "Initialization complete after %s" (emacs-init-time))) t)
;; minimal UI
(setq-default visible-bell t)
(setq inhibit-startup-message t)
(dolist (mode '(tool-bar-mode scroll-bar-mode))
(when (fboundp mode) (funcall mode -1)))
;; trust me
(setq disabled-command-function nil)
(defalias 'yes-or-no-p 'y-or-n-p)
;; prefer UTF-8
(prefer-coding-system 'utf-8)
;; load custom settings
(defgroup my/host nil
"Customizations local to a specific host."
:group 'initialization)
(defcustom my/source-root-dir "~/src" "Root directory for source repositories." :group 'my/host)
(setq custom-file (locate-user-emacs-file "custom.el"))
(load custom-file nil t)
;; load use-package
(setq use-package-compute-statistics t)
(setq use-package-enable-imenu-support t)
(require 'use-package)
;; keep .emacs.d organized
(use-package no-littering
:config
(setq auto-save-file-name-transforms `((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))
(setq custom-theme-directory (no-littering-expand-etc-file-name "themes/"))
(with-eval-after-load 'recentf
(add-to-list 'recentf-exclude (file-truename no-littering-var-directory))
(add-to-list 'recentf-exclude (file-truename no-littering-etc-directory))))
;; load OS- or host-specific themes
(dolist (theme (list system-type (intern (downcase (system-name)))))
(condition-case
nil (load-theme theme t)
(error (message "Cannot load theme: %s" theme))))
;; Configure mode line
(load (locate-user-emacs-file "init.d/my-mode-line"))
;;; Configure Packages
(use-package package
:bind
(:map package-menu-mode-map
("s" . my/package-menu-filter-by-status)
("a" . my/package-menu-find-marks))
:config
(defun my/package-menu-find-marks ()
"Find packages marked for action in *Packages*."
(interactive)
(occur "^[A-Z]"))
(defun my/package-menu-filter-by-status (status)
"Filter the *Packages* buffer by status."
(interactive
(list (completing-read
"Status: " '("new" "installed" "dependency" "obsolete"))))
(package-menu-filter (concat "status:" status))))
(use-package recentf ; Recent files
:hook
(emacs-startup . recentf-mode)
:custom
(recentf-max-saved-items 100)
:config
(run-at-time t (* 5 60) (lambda () (let ((inhibit-message t)) (recentf-save-list))))
(add-to-list 'recentf-exclude ".*autoloads.el$")
(add-to-list 'recentf-exclude (file-truename (file-name-as-directory package-user-dir))))
(use-package dired ; Directory listings
:bind
("C-x C-j" . dired-jump)
("C-x 4 j" . dired-jump-other-window)
(:map dired-mode-map
("C-k" . my/dired-kill-line))
:config
(defun my/dired-kill-line ()
"Kill the current line or subdirectory."
(interactive)
(if (dired-get-subdir)
(dired-kill-subdir)
(dired-kill-line 1))))
(use-package dired-collapse
:hook
(dired-mode . dired-collapse-mode))
(use-package eww ; Emacs Web Wowser
:custom
(shr-use-fonts nil)
:bind
(:map eww-mode-map
("I" . my/eww-toggle-images))
(:map eww-link-keymap
("I" . my/eww-toggle-images))
(:map goto-map
("B" . eww-list-bookmarks))
:config
(setq-default shr-inhibit-images t)
(defun my/eww-toggle-images ()
"Toggle whether images are loaded and reload the current page from cache."
(interactive)
(setq-local shr-inhibit-images (not shr-inhibit-images))
(eww-reload t)
(message "Images are now %s"
(if shr-inhibit-images "off" "on"))))
(load (locate-user-emacs-file "init.d/my-browser"))
(use-package ediff ; Ediff
:bind
("C-c =" . ediff-current-file)
:config
(load (locate-user-emacs-file "init.d/my-ediff")))
(use-package try ; Try packages without installing
:commands (try try-and-refresh)
:config
(add-to-list 'recentf-exclude ".*/try.+.el$"))
(use-package hydra) ; Key bindings that stick around
(use-package use-package-hydra ; Define hydras with use-package
:after hydra)
(use-package buffer-protect ; Keep buffers from being killed
:preface
(add-to-list 'load-path (expand-file-name "github.com/glucas/buffer-protect" my/source-root-dir)))
(use-package yank-temp ; Copy text to temp buffer
:preface
(add-to-list 'load-path (expand-file-name "github.com/glucas/yank-temp" my/source-root-dir))
:bind ("C-c y" . yank-temp-from-clipboard)
:config
(add-hook 'window-setup-hook
(lambda () (when (get-buffer "*scratch*")
(with-current-buffer "*scratch*"
(yank-temp-set-revert-point)))))
:config
(defhydra hydra-setup-yank-temp (:color blue :timeout 3 :post (yank-temp-set-revert-point))
("l" lisp-interaction-mode "lisp")
("j" (progn (js-mode) (json-pretty-print-buffer)) "json")
("x" (progn (nxml-mode)) "xml")
("t" (progn (turn-on-orgtbl) (org-table-convert-region (point-min) (point-max) nil)) "table")
("c" (ansi-color-apply-on-region (point-min) (point-max)) "color"))
(add-hook 'yank-temp-initialized-hook #'hydra-setup-yank-temp/body))
;;;; Appearance
(use-package stripe-buffer ; Row highlighting in tables/lists
:hook
((archive-moden
bookmark-bmenu-mode
dired-mode
eww-bookmark-mode
ibuffer-mode
package-menu-mode
occur-mode
vc-dir-mode)
. stripe-listify-buffer)
:custom-face
(stripe-highlight ((t (:background "ghost white"))))
(stripe-hl-line ((t (:inherit hl-line)))))
(use-package hl-line ; Highlight line
:commands
(hl-line-mode)
:custom-face
(hl-line ((t (:background "lavender")))))
(use-package show-eol
:commands
(show-eol-mode global-show-eol-mode))
;;;; Ivy
(use-package smex) ; Track command frequency
(use-package ivy ; Incremental Vertical completYon
:custom
(ivy-use-virtual-buffers t)
(projectile-completion-system 'ivy)
:bind
([remap isearch-backward-regexp] . ivy-resume)
:init
(ivy-mode))
(use-package ivy-hydra ; Additional key bindings for Ivy
:requires (ivy hydra))
(use-package swiper ; Ivy-based incremental search
:requires ivy
:custom
(swiper-action-recenter t)
(swiper-include-line-number-in-search t)
:bind
([remap isearch-forward-regexp] . swiper-isearch)
(:map isearch-mode-map
("SPC" . my/swiper-from-isearch))
:config
(defun my/swiper-from-isearch ()
"Invoke swiper from isearch, adding a space to the query."
(interactive)
(let*
((query-string (concat isearch-string " "))
(query (if isearch-regexp
query-string
(regexp-quote query-string))))
(isearch-exit)
(swiper-isearch query))))
(use-package counsel ; Ivy commands
:requires ivy
:bind
("C-c m" . counsel-semantic-or-imenu)
("C-c e" . counsel-register)
:init
(counsel-mode))
;;;; Jump Around
(use-package avy ; jump to visible text
:bind
("M-M" . avy-goto-word-or-subword-1)
;; (:map search-map
;; ("SPC" . avy-goto-word-or-subword-1))
)
(use-package avy-zap ; jump + zap
:bind
([remap goto-line] . avy-goto-line)
("M-z" . zap-up-to-char)
("M-Z" . avy-zap-up-to-char))
(use-package jump-char ; jump to char
:bind ("M-m" . jump-char-forward))
(use-package ace-link ; jump to links
:init (ace-link-setup-default))
(use-package ace-window ; jump to windows
:custom
(aw-keys '(?a ?s ?d ?f ?j ?k ?l))
:bind
("C-c o" . ace-window))
(use-package goto-last-change ; jump to last change
:commands goto-last-change-with-auto-marks)
(use-package hl-todo ; jump to TODOs
:hook
(prog-mode . hl-todo-mode)
:bind
(:map hl-todo-mode-map
("M-s t" . hydra/hl-todo/body))
:hydra
(hydra/hl-todo
(:hint nil)
"
TODOs:
_j_: prevoius _o_ccur
_k_: next _q_uit
"
("o" hl-todo-occur)
("j" hl-todo-previous)
("k" hl-todo-next)
("q" nil nil :color blue)))
;;;; Editing
(use-package iedit ; edit all occurences
:bind
("C-;" . iedit-mode))
(use-package change-inner ; replace semantic units
:bind
("C-c i" . change-inner)
("C-c I" . change-outer))
(use-package hilit-chg ; highlight recent changes
:custom
(highlight-changes-visibility-initial-state nil)
:hook
(find-file . highlight-changes-mode-turn-on))
(use-package diff-hl ; highlight uncommited changes
:hook
(emacs-startup . global-diff-hl-mode)
(dired-mode . diff-hl-dired-mode-unless-remote)
(magit-post-refresh . diff-hl-magit-post-refresh))
;;;; Completion
(use-package company ; Complete anything
:commands
(company-mode company-complete)
:hook
((prog-mode nxml-mode) . company-mode)
:custom
(company-backends '(company-semantic
company-capf
company-files
(company-dabbrev-code company-gtags company-etags company-keywords)
company-dabbrev))
:bind
(:map company-mode-map
([remap indent-for-tab-command] . company-indent-or-complete-common))
(:map company-active-map
("<tab>" . company-complete-common-or-cycle)
("M-." . company-show-location)
("C-o" . company-other-backend)
("C-n" . company-select-next)
("C-p" . company-select-previous))
:init
(add-hook 'nxml-mode-hook
(lambda ()
(add-to-list (make-local-variable 'company-backends) '(company-nxml))))
(add-hook 'css-mode-hook
(lambda ()
(add-to-list (make-local-variable 'company-backends) '(company-css)))))
(use-package company-quickhelp
:after company
:commands (company-quickhelp-mode)
:config (company-quickhelp-mode 1))
;;;; Org
(use-package org ; Org mode
:custom
(org-log-done 'time)
(org-startup-indented t)
(org-use-speed-commands t)
(org-directory "~/Dropbox/org")
(org-default-notes-file (expand-file-name "inbox.org" org-directory))
(org-refile-targets '((nil . (:maxlevel . 10)) (org-agenda-files . (:maxlevel . 5))))
(org-agenda-files (list org-directory))
(org-todo-keywords '((sequence "TODO(t)" "NEXT(n!)" "DOING(g!)" "WAITING(w@)" "SOMEDAY(x)" "|" "DONE(d!)")
(sequence "|" "CANCELLED(c@/!)")))
:custom-face
(org-meta-line ((t (:height 0.85))))
:bind
("C-c c" . org-capture)
("C-c a" . org-agenda)
("C-c l" . org-store-link)
(:map org-mode-map
("C-c C-8" . org-ctrl-c-star))
(:map org-src-mode-map
("C-c C-c" . org-edit-src-exit))
:config
(load (locate-user-emacs-file "init.d/my-org")))
;;;; Projects
(use-package projectile
:custom
(projectile-indexing-method 'alien)
(projectile-switch-project-action 'projectile-commander)
:bind-keymap
("C-c p" . projectile-command-map)
:hook
(prog-mode . projectile-mode)
:init
;; Allow dir-locals to configure projectile
(put 'projectile-project-name 'safe-local-variable #'stringp)
(put 'projectile-enable-caching 'safe-local-variable #'booleanp)
(put 'projectile-indexing-method 'safe-local-variable
(lambda (arg) (memq arg '(native alien)))))
(use-package bug-reference
:hook
(org-mode . bug-reference-mode)
(prog-mode . bug-reference-prog-mode)
:init
(defcustom bug-reference-url-format nil
"Format used to turn a bug number into a URL."
:group 'bug-reference)
(put 'bug-reference-bug-regexp 'safe-local-variable #'stringp)
(put 'bug-reference-url-format 'safe-local-variable #'stringp))
(use-package eyebrowse
:after
hydra
:custom
(eyebrowse-new-workspace t)
(eyebrowse-wrap-around t)
(eyebrowse-default-workspace-slot 0)
:bind
("C-c g" . hydra/eyebrowse/body)
:hydra
;; https://www.wisdomandwonder.com/article/10596/screencast-building-a-little-ui-to-manage-buffers
(hydra/eyebrowse (:color blue :hint nil :body-pre (eyebrowse-mode 1))
"
current eyebrowse slot: %(eyebrowse--get 'current-slot)
_j_ previous _k_ next _l_ last _u_ close _i_ choose _o_ rename _q_ quit
_a_ 00 _s_ 01 _d_ 02 _f_ 03 _g_ 04 _z_ 05 _x_ 06 _c_ 07 _v_ 08 _b_ 09"
("j" #'eyebrowse-prev-window-config :exit nil)
("k" #'eyebrowse-next-window-config :exit nil)
("l" #'eyebrowse-last-window-config)
("u" #'eyebrowse-close-window-config :exit nil)
("i" #'eyebrowse-switch-to-window-config)
("o" #'eyebrowse-rename-window-config :exit nil)
("q" nil)
("a" #'eyebrowse-switch-to-window-config-0)
("s" #'eyebrowse-switch-to-window-config-1)
("d" #'eyebrowse-switch-to-window-config-2)
("f" #'eyebrowse-switch-to-window-config-3)
("g" #'eyebrowse-switch-to-window-config-4)
("z" #'eyebrowse-switch-to-window-config-5)
("x" #'eyebrowse-switch-to-window-config-6)
("c" #'eyebrowse-switch-to-window-config-7)
("v" #'eyebrowse-switch-to-window-config-8)
("b" #'eyebrowse-switch-to-window-config-9))
)
;;;; External Tools
(use-package magit ; git
:if (executable-find "git")
:custom
(magit-repository-directories `((,my/source-root-dir . 3)))
:bind
(("C-x g" . magit-status)))
(use-package forge
:after magit
:init
(setq emacsql-sqlite-c-compilers '("gcc")))
(use-package deadgrep ; ripgrep
:if (executable-find "rg")
:commands (deadgrep)
:init
(defalias 'rg 'deadgrep))
(use-package docker
:if (executable-find "docker")
:bind ("C-c d" . docker))
;;; Editing Modes
(load (locate-user-emacs-file "init.d/my-file-modes"))
;;;; Server
(use-package server ; Emacs daemon
:bind (("C-x C-3" . server-edit))) ; C-x C-#
(use-package edit-server
:hook
(emacs-startup . edit-server-start))
;;;; Help
(use-package which-key
:custom
(which-key-idle-delay 2.0)
:hook
(emacs-startup . which-key-mode))
;;; Key Bindings
(use-package unfill ; toggle fill/unfill
:bind ([remap fill-paragraph] . unfill-toggle))
(use-package transpose-frame ; rotate windows in frame
:bind ("C-c t" . transpose-frame))
(use-package easy-kill ; enhanced kill-ring-save
:disabled t
:bind ([remap kill-ring-save] . easy-kill))
(defmacro new-split-command (f)
"Switch to new window after a split command."
`(lambda ()
(interactive)
(funcall ,f)
(set-window-buffer (next-window) (other-buffer))
(other-window 1)))
(bind-key [remap split-window-below] (new-split-command 'split-window-below))
(bind-key [remap split-window-right] (new-split-command 'split-window-right))
(bind-keys
("M-`" . pop-global-mark)
([remap delete-char] . delete-forward-char)
([remap list-buffers] . ibuffer-other-window)
([remap kill-buffer] . kill-this-buffer)
([remap upcase-word] . upcase-dwim)
([remap downcase-word] . downcase-dwim)
([remap capitalize-word] . capitalize-dwim) ;; TODO frees up C-x C-u and C-x C-l
([remap view-hello-file] . (lambda () (interactive) (find-file user-init-file))) ; C-h h
)
(bind-keys*
:filter (not (minibufferp))
("M-o" . other-window)
("M-i" . mode-line-other-buffer))
(defun my/clean-buffer ()
(interactive)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))
(defun my/revert-buffer ()
"Revert buffer, prompting for confirmation only if the buffer is modified."
(interactive)
(revert-buffer :ignore-auto (not (buffer-modified-p)) :preserve-modes))
(bind-keys
("C-c w" . my/clean-buffer)
("C-c r" . my/revert-buffer))
;; Navigate up/down columns
;; https://emacs.stackexchange.com/a/22094/780
(defun my/down-column (arg)
"Find next line, on the same column, skipping those that would
end up leaving point on a space or newline character."
(interactive "p")
(let* ((hpos (- (point) (point-at-bol)))
(re (format "^.\\{%s\\}[^[:space:]\n]" hpos)))
(cond ((> arg 0)
(forward-char 1) ; don't match current position (can only happen at column 0)
(re-search-forward re))
((< arg 0)
(forward-char -1) ; don't match current position.
(re-search-backward re)
(goto-char (match-end 0))))
;; now point is after the match, let's go back one column.
(forward-char -1)))
(defun my/up-column (arg)
""
(interactive "p")
(my/down-column (- arg)))
(bind-keys
("C-S-n" . my/down-column) ; move up/down current column
("C-S-p" . my/up-column))
;; Navigate errors
(defhydra hydra-next-error
(global-map "C-x")
"
Errors:
_j_: next error _h_: first error _q_uit
_k_: previous error _l_: last error
"
("`" next-error nil)
("j" next-error nil :bind nil)
("k" previous-error nil :bind nil)
("h" first-error nil :bind nil)
("l" (condition-case err
(while t
(next-error))
(user-error nil))
nil :bind nil)
("q" nil nil :color blue))
;; Navigate changes
(defhydra hydra/goto-changes
(global-map "C-c" :hint nil
:pre (highlight-changes-visible-mode 1)
:post (highlight-changes-visible-mode 0))
"
Changes:
"
("h" goto-last-change-with-auto-marks)
("j" diff-hl-previous-hunk)
("k" diff-hl-next-hunk)
("J" highlight-changes-previous-change)
("K" highlight-changes-next-change)
("q" nil nil :color blue :bind nil))
(defhydra hydra/page (ctl-x-map "" :pre (widen))
"page"
("]" forward-page "next")
("[" backward-page "prev")
("n" narrow-to-page "narrow" :bind nil :exit t))
;; Windows and buffers
(defun flip-window ()
(interactive)
(let ((win (get-mru-window 'visible t t)))
(if win
(progn
(select-frame-set-input-focus (window-frame win))
(select-window win))
(mode-line-other-buffer))))
(defun kill-buffer-and-window-dwim ()
"Kill the current window and/or buffer.
If the current buffer is visible in multiple windows, kill the
current window. Otherwise call `kill-buffer-and-window'."
(interactive)
(if (= 1 (length (get-buffer-window-list (current-buffer))))
(kill-buffer-and-window)
(delete-window)))
(bind-keys
("M-\\" . flip-window)
("C-c C-k" . kill-buffer-and-window-dwim))
;; Experimentation
;; TODO not working...
;; (setq ellocate-scan-dirs '(
;; ("/fbcdev" "~/ellocate-fbc-db")
;; ))
;; (use-package edwina
;; :config
;; (setq display-buffer-base-action '(display-buffer-below-selected))
;; ;; (edwina-setup-dwm-keys)
;; (edwina-mode 1))
;;; init.el ends here