~idmyn/dotfiles

ref: 536be88983b1e258975f298b3e9df89bf6daf692 dotfiles/emacs/.doom.d/config.org -rw-r--r-- 15.8 KiB
536be889 — David Mynors Remove deft config a month ago
                                                                                
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
* My [[https://github.com/hlissner/doom-emacs][Doom]] Config
This [[https://en.wikipedia.org/wiki/Literate_programming][literate]] config file is [[https://orgmode.org/manual/Extracting-source-code.html][tangled]] into =~/.doom.d/config.el= when the file is
saved. To achieve this behaviour, I had to [[https://github.com/idmyn/dotfiles/commit/42ea6a64575565c1e9c9807e359d80161ab8fb91][enable the literate config module]] in
=~/.doom.d/init.el=.

#+BEGIN_SRC emacs-lisp
;;; -*- lexical-binding: t; -*-

(setq user-full-name "David Mynors"
      user-mail-address "hello@davidmyno.rs")

(show-smartparens-global-mode 1)

(setq display-line-numbers-type nil)

;; load secrets (encrypted with git-crypt)
(load "~/.doom.d/secrets.el")

;; when I open emacs I want it to fill my screen
(add-to-list 'default-frame-alist '(fullscreen . maximized))
#+END_SRC

** Theme
I use an [[https://github.com/maio/eink-emacs][eink theme]] and the [[https://input.fontbureau.com][Input font family]]. My use of the `:custom` and
`:custom-face` keywords is inspired by [[https://github.com/a13/emacs.d][a13's literate emacs config]]. I think it's
pretty neat! I struggled at first to figure out how to change faces without `M-x
customize-face`, but with this method I first use `M-x customize-face` to see
what attributes I need to change (and whether the specific face inherits from
any others) and then I add those details as below.
#+BEGIN_SRC emacs-lisp
(use-package! eink-theme
  :custom
  (doom-theme 'eink)
  (doom-font (font-spec :family "Input Mono Narrow" :size 15))
  (doom-variable-pitch-font (font-spec :family "Input Sans Narrow"))
  :config
  (hl-line-mode)
  (column-number-mode)
  :custom-face
  (hl-line ((t (:inherit highlight :background "lavender"))))
  (lsp-ui-sideline-code-action ((t (:foreground "limegreen"))))
  (rustic-string-interpolation-face ((t)))
  (diredfl-file-name ((t)))
  (diredfl-file-suffix ((t)))
  (diredfl-symlink ((t)))
  (diredfl-date-time ((t)))
  (diredfl-number ((t)))
  (diredfl-dir-heading ((t)))
  (diredfl-no-priv ((t)))
  (diredfl-dir-priv ((t)))
  (diredfl-read-priv ((t)))
  (diredfl-write-priv ((t)))
  (diredfl-exec-priv ((t)))
  (diredfl-rare-priv ((t)))
  (diredfl-ignored-file-name ((t)))
  (diredfl-compressed-file-suffix ((t)))
  (diredfl-dir-name ((t (:weight bold)))))
#+END_SRC
remove minor modes from the mode line
#+BEGIN_SRC emacs-lisp
(define-minor-mode minor-mode-blackout-mode
  "Hides minor modes from the mode line."
  t)

(catch 'done
  (mapc (lambda (x)
          (when (and (consp x)
                     (equal (cadr x) '("" minor-mode-alist)))
            (let ((original (copy-sequence x)))
              (setcar x 'minor-mode-blackout-mode)
              (setcdr x (list "" original)))
            (throw 'done t)))
        mode-line-modes))
#+END_SRC

** Nifty functions
#+BEGIN_SRC emacs-lisp
(defun xah-paste-or-paste-previous ()
  "Paste. When called repeatedly, paste previous.
This command calls `yank', and if repeated, call `yank-pop'.

When `universal-argument' is called first with a number arg, paste that many times.

URL `http://ergoemacs.org/emacs/emacs_paste_or_paste_previous.html'
Version 2017-07-25"
  (interactive)
  (progn
    (when (and delete-selection-mode (region-active-p))
      (delete-region (region-beginning) (region-end)))
    (if current-prefix-arg
        (progn
          (dotimes ($i (prefix-numeric-value current-prefix-arg))
            (yank)))
      (if (eq real-last-command this-command)
          (yank-pop 1)
        (yank)))))

(require 'edit-indirect)
(defun md/narrow-dwim (p)
  "Widen if buffer is narrowed, narrow-dwim otherwise.
  Dwim means: region, org-src-block, org-subtree, or
  defun, whichever applies first. Narrowing to
  org-src-block actually calls `org-edit-src-code'.
  With prefix P, don't widen, just narrow even if buffer
  is already narrowed."
  (interactive "P")
  (declare (interactive-only))
  (cond ((and (buffer-narrowed-p) (not p)) (widen))
        ((region-active-p)
         (edit-indirect-region (region-beginning)
                               (region-end)
                               t))
        (edit-indirect--overlay
         (edit-indirect-commit))
        (org-src-mode
         (org-edit-src-exit))
        ((derived-mode-p 'org-mode)
         ;; `org-edit-src-code' is not a real narrowing
         ;; command. Remove this first conditional if
         ;; you don't want it.
         (cond ((ignore-errors (org-edit-src-code) t))
               ((ignore-errors (org-narrow-to-block) t))
               (t (org-narrow-to-subtree))))
        ((derived-mode-p 'latex-mode)
         (LaTeX-narrow-to-environment))
        ((derived-mode-p 'restclient-mode)
         (restclient-narrow-to-current))
        (t (narrow-to-defun))))
;; Don't ask for confirmation on narrow-to-region
(put 'narrow-to-region 'disabled nil)

(map!
 :leader
 :prefix "t"
 :desc "Narrow" "n" 'md/narrow-dwim)
#+END_SRC

** Keybindings
change vimkeys from hjkl to jkl: (I use karabiner to swap my ; and : keys)
#+BEGIN_SRC emacs-lisp
(map!
 (:after evil
   :nv "j" 'evil-backward-char
   :nv "k" 'evil-next-line
   :nv "l" 'evil-previous-line
   :nv ":" 'evil-forward-char

   :nv "h" 'evil-paste-after
   :nv "H" 'evil-paste-before))
#+END_SRC
adjust magit vimkeys accordingly
#+BEGIN_SRC emacs-lisp
(map!
 (:after magit
   :map magit-mode-map
   :nv "k" 'magit-section-forward
   :nv "l" 'magit-section-backward))
#+END_SRC
adjust treemacs vimkeys accordingly
#+BEGIN_SRC emacs-lisp
(after! treemacs
 (general-def 'treemacs treemacs-mode-map
   ":" 'treemacs-RET-action
   "k" 'treemacs-next-line
   "l" 'treemacs-previous-line
   "M-j" 'evil-window-left
   "M-k" 'evil-window-down
   "M-l" 'evil-window-up
   "M-;" 'evil-window-right))
#+END_SRC
adjust ivy minibuffer vimkeys accordingly (I was having issues with this but
found out through `M-x which-key-show-keymap` that there is an
`ivy-posframe-mode-map`, which turned out to be the missing link!)
#+BEGIN_SRC emacs-lisp
(map!
 (:after ivy
   :map (ivy-minibuffer-map ivy-posframe-mode-map)
   "C-j" 'ivy-backward-delete-char
   "C-k" 'ivy-next-line
   "C-l" 'ivy-previous-line
   "C-;" 'ivy-done))
#+END_SRC
same thing for comint mode
#+BEGIN_SRC emacs-lisp
(map!
 :map comint-mode-map
 :i "C-k" 'comint-next-matching-input-from-input
 :i "C-l" 'comint-previous-matching-input-from-input)
#+END_SRC
easier motion around lines and paragraphs
#+BEGIN_SRC emacs-lisp
(map!
 :after evil
 :nvm "J" 'evil-first-non-blank
 :nvm "K" 'forward-paragraph
 :nvm "L" 'backward-paragraph
 :nvm ";" 'evil-last-non-blank)
#+END_SRC
easier movement between windows and frames (taken from [[https://github.com/Brettm12345/doom-emacs-literate-config/blob/master/config.org#easy-window-navigation][here]])
#+BEGIN_SRC emacs-lisp
(use-package! framemove
  :custom (framemove-hook-into-windmove t))
(map!
 (:after evil
   :ni "M-j" 'evil-window-left
   :ni "M-k" 'evil-window-down
   :ni "M-l" 'evil-window-up
   :ni "M-;" 'evil-window-right)

 (:after evil-org
   :map evil-org-mode-map
   :ni "M-j" 'evil-window-left
   :ni "M-k" 'evil-window-down
   :ni "M-l" 'evil-window-up
   :ni "M-;" 'evil-window-right)

 (:after evil-markdown
   :map evil-markdown-mode-map
   :ni "M-j" 'evil-window-left
   :ni "M-k" 'evil-window-down
   :ni "M-l" 'evil-window-up
   :ni "M-;" 'evil-window-right)

 (:after vterm
   :map vterm-mode-map
   :ni "M-j" 'evil-window-left
   :ni "M-k" 'evil-window-down
   :ni "M-l" 'evil-window-up
   :ni "M-;" 'evil-window-right))
#+END_SRC
bind jump-backward and jump-forward to more intuitive keys
#+BEGIN_SRC emacs-lisp
(map!
 (:after evil
   :n "C-j" 'better-jumper-jump-backward
   :n "C-;" 'better-jumper-jump-forward))
#+END_SRC
handy to have an insert-mode binding to jump to a new line above
#+BEGIN_SRC emacs-lisp
(map!
 (:after evil
   :i "C-o" '+default/newline-above))
#+END_SRC
restore original emacs binding for paste, `save-buffer`, `delete-char`
#+BEGIN_SRC emacs-lisp
(map!
 (:after evil
   :i "C-y" 'xah-paste-or-paste-previous
   :i "C-d" 'delete-char
   :i "C-x C-s" 'save-buffer)

 (:after evil-org
   :map evil-org-mode-map
   :i "C-d" 'delete-char))
#+END_SRC
only use text-scale-increase and text-scale-decrease to change font size (bound by default
to C-- and C-=)
#+BEGIN_SRC emacs-lisp
(map!
 "s--" 'text-scale-decrease
 "s-=" 'text-scale-increase)
#+END_SRC
fix "#" input on UK MacBook keyboard
#+BEGIN_SRC emacs-lisp
(cond
 ((string-equal system-type "darwin")
  (progn
    (map!
     "M-3" (lambda () (interactive) (insert "#")))
    )))
#+END_SRC

** Evil
tweak a couple of evil behaviours
#+BEGIN_SRC emacs-lisp
(after! evil
  (setq evil-insert-state-map (make-sparse-keymap)) ; emacs bindings in evil insert state
  (define-key evil-insert-state-map (kbd "<escape>") 'evil-normal-state)
  (setq evil-split-window-below t)
  (setq evil-vsplit-window-right t)
  (setq evil-insert-state-message nil)
  (setq +evil-want-o/O-to-continue-comments nil)
  (advice-remove #'newline-and-indent #'+default--newline-indent-and-continue-comments-a))
#+END_SRC
undo-tree bindings
#+BEGIN_SRC emacs-lisp
(map!
 :after undo-tree
 :map undo-tree-visualizer-mode-map
 :m "k" 'undo-tree-visualize-redo
 :m "l" 'undo-tree-visualize-undo
 :m ":" 'undo-tree-visualize-switch-branch-right
 :m "j" 'undo-tree-visualize-switch-branch-left)
#+END_SRC
evil-multiedit bindings
#+BEGIN_SRC emacs-lisp
(map!
 :after evil
 :n "C-k" 'evil-multiedit-match-symbol-and-next
 :n "C-l" 'evil-multiedit-match-symbol-and-prev)
#+END_SRC
** Search
*** Ivy
instruct ivy-posframe to appear right under cursor with no border
#+BEGIN_SRC emacs-lisp
(after! ivy-posframe
    (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-point)))
    (setq ivy-posframe-border-width 0))
#+END_SRC
exceptions to the fuzzy search rule set in init.el
#+BEGIN_SRC emacs-lisp
(after! ivy
  (setq ivy-re-builders-alist
        '((counsel-imenu . ivy--regex-plus)
          (t . ivy--regex-fuzzy))))
#+END_SRC
*** Deadgrep
adjust the size of the deadgrep buffer, and give it a sensible keybinding
#+BEGIN_SRC emacs-lisp
(set-popup-rule! "^\\*deadgrep" :size 0.4)
(map!
   :leader
   :prefix "s"
   :desc "Search project" "p" 'deadgrep)
#+END_SRC
*** Dash
#+BEGIN_SRC emacs-lisp
(map! :n "D" 'dash-at-point)
#+END_SRC
** Company
I tend to find the company auto-complete popup quite intrusive, so I disable it
globally. I do occasionaly find it useful, though, so I have a toggle mapped to
"SPC t c".
#+BEGIN_SRC emacs-lisp
(global-company-mode -1)
(after! company
  (add-to-list 'company-global-modes 'eshell-mode t)
  (add-to-list 'company-global-modes 'js2-mode t)
  (add-to-list 'company-global-modes 'org-mode t))

(setq company-idle-delay 0)

(map! :leader
        :prefix "t"
        :desc "Company" "c" 'company-mode)
#+END_SRC
** Eldoc
I want to eldoc disabled in most modes
#+BEGIN_SRC emacs-lisp
(global-eldoc-mode -1)
(remove-hook 'org-mode-hook #'org-eldoc-load)
#+END_SRC
** Org
#+BEGIN_SRC emacs-lisp
(setq org-directory "~/Dropbox/org")
(setq org-imenu-depth 10)
#+END_SRC
*** Keybindings
#+BEGIN_SRC emacs-lisp
(map!
 :after evil-org
 :map evil-org-mode-map
 :ni "C-j" 'org-metaleft
 :ni "C-;" 'org-metaright)
#+END_SRC
*** Agenda
#+BEGIN_SRC emacs-lisp
(map!
 (:after evil-org-agenda
   :map evil-org-agenda-mode-map
   :m "k" 'org-agenda-next-line
   :m "l" 'org-agenda-previous-line))
#+END_SRC
** Eshell
*** Keybindings
adjust history navigation bindings to match my adjusted vimkeys, and add
bindings to move between windows
#+BEGIN_SRC emacs-lisp
(defun eshell-setup-keys() ; implementation inspired by evil-collection
  "Set up `evil' bindings for `eshell'."
  (map!
   :map eshell-mode-map
   :i "C-l" 'eshell-previous-matching-input-from-input
   :i "C-k" 'eshell-next-matching-input-from-input
   :i "C-;" 'eshell-send-input

   :ni "M-j" 'evil-window-left
   :ni "M-k" 'evil-window-down
   :ni "M-l" 'evil-window-up
   :ni "M-;" 'evil-window-right))
(add-hook 'eshell-first-time-mode-hook 'eshell-setup-keys)
#+END_SRC
*** Aliases
#+BEGIN_SRC emacs-lisp
(set-eshell-alias!
 "e" "find-file $1"
 "git" "hub $*"
 "doom" "~/.emacs.d/bin/doom $1")
#+END_SRC
*** eshell-z
[[https://github.com/xuchunyang/eshell-z][eshell-z]] is an emacs port of [[https://github.com/rupa/z][z]], which "keeps track of where you’ve been and how
many commands you invoke there, and provides a convenient way to jump to the
directories you actually use". I also have [[https://github.com/idmyn/dotfiles/blob/53fc9e60f8b9eeafce3fa36df88dfd3424d30198/shell/.zsh_plugins.txt#L1][it]] [[https://github.com/idmyn/dotfiles/blob/53fc9e60f8b9eeafce3fa36df88dfd3424d30198/shell/.zshrc#L10][installed]] in my zsh config (via
[[https://getantibody.github.io][antibody]]) and both installations share the same data file, which is pretty
sweet. I had it configured here but later found out that it's already [[https://github.com/hlissner/doom-emacs/blob/f3a75004e07b847c7d0efc8b38885297a081a828/modules/term/eshell/config.el#L172][included
in doom]] by default!
*** Other settings
tell CLI applications that it's ok to dump really long output into the buffer
#+BEGIN_SRC emacs-lisp
(setenv "PAGER" "cat")
#+END_SRC

** Dired
#+BEGIN_SRC emacs-lisp
(map!
 :leader
 :prefix "f"
 :desc "Browse files" "d" 'dired-jump)

(after! dired
  (add-hook 'dired-mode-hook #'dired-show-readme-mode)

  (map!
   :map dired-mode-map
   :n "j" 'dired-up-directory
   :n "k" 'dired-next-line
   :n "l" 'dired-previous-line
   :n ":" 'dired-find-file

   :n "W" 'wdired-change-to-wdired-mode))
#+END_SRC
** Olivetti
[[https://github.com/rnkn/olivetti][Olivetti]] is "a simple Emacs minor mode for a nice writing environment".
#+BEGIN_SRC emacs-lisp
(map!
 :leader
 :prefix "t"
 :desc "Olivetti" "o" 'olivetti-mode)
#+END_SRC
** Ebuku
set the path to my [[https://github.com/jarun/buku][buku]] bookmarks
#+BEGIN_SRC emacs-lisp
(setq ebuku-db-path "~/Dropbox/System/bookmarks.db")
#+END_SRC
** JavaScript
Use two spaces for indentation
#+BEGIN_SRC emacs-lisp
(after! js2-mode
  (setq js2-basic-offset 2)
  (require 'prettier-js)

  (map!
   :map js2-mode-map
   :ni "C-c i" 'js-doc-insert-function-doc))
#+END_SRC
configure flycheck to use eslint
#+BEGIN_SRC emacs-lisp
(after! flycheck
  (add-to-list 'flycheck-disabled-checkers 'javascript-jshint)
  (add-to-list 'flycheck-disabled-checkers 'javascript-standard)
  (add-to-list 'flycheck-disabled-checkers 'lsp-ui)
  (setq flycheck-javascript-eslint-executable "eslint_d"))
#+END_SRC
** Web (& Svelte)
some web-mode config
#+BEGIN_SRC emacs-lisp
(setq css-indent-offset 2)
(add-hook 'css-mode-hook (lambda () (flycheck-mode -1)))

(use-package! web-mode
  :mode "\\.svelte\\'"
  :config (after! flycheck (flycheck-add-mode 'javascript-eslint 'web-mode))
  :custom
  (web-mode-enable-current-element-highlight t)
  (web-mode-markup-indent-offset 2)
  (web-mode-css-indent-offset 2)
  (web-mode-style-padding 0)
  (web-mode-code-indent-offset 2)
  (web-mode-script-padding 0))
#+END_SRC
browser-refresh
#+BEGIN_SRC emacs-lisp
(use-package! browser-refresh
  :bind ("s-r" . browser-refresh)
  :custom
  (browser-refresh-default-browser 'brave)
  (browser-refresh-save-buffer nil)
  (browser-refresh-activate nil))
#+END_SRC

** Markdown & Org
set the =grip-binary-path= for [[https://github.com/seagle0128/grip-mode][grip-mode]], fix some keybinds
#+BEGIN_SRC emacs-lisp
(setq grip-binary-path "/usr/local/bin/grip")

(map!
 (:after markdown-mode
   :map evil-markdown-mode-map
   :i "C-d" 'delete-char
   :ni "C-;" 'self-insert-command))
#+END_SRC
** Common Lisp
#+BEGIN_SRC emacs-lisp
(map!
 (:after sly
   :map sly-mrepl-mode-map
   :i "C-k" 'sly-mrepl-next-input-or-button
   :i "C-l" 'sly-mrepl-previous-input-or-button))
#+END_SRC
** Rust
#+BEGIN_SRC emacs-lisp
(setq rustic-lsp-server 'rust-analyzer)
#+END_SRC
** Eglot
because I don't want [[https://github.com/emacs-lsp/lsp-mode][lsp-mode]]'s bells and whistles
#+BEGIN_SRC emacs-lisp
(add-hook! eglot--managed-mode #'(flymake-mode (lambda () (eldoc-mode -1))))
(use-package flymake-diagnostic-at-point
  :after flymake
  :config (add-hook 'flymake-mode-hook #'flymake-diagnostic-at-point-mode))
#+END_SRC