-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
843 lines (731 loc) · 30.2 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
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
;;; package --- init.el -*- lexical-binding: t -*- --- My Emacs configuration.
;;; Commentary:
;;; This file is not part of GNU Emacs.
;;; Author: Aditya Athalye
;;; Created on: 30 June 2023
;;; Copyright (c) 2023 Aditya Athalye
;;; License:
;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the MIT license, which is included
;;; with this distribution. See the LICENCE.txt file.
;;; Code:
;; Set the low bar Emacs compatibility high
(defvar adi/dotemacs-min-version "28.1")
(when (version< emacs-version adi/dotemacs-min-version)
(error "We demand spiffy new Emacs, at least v%s, but you have v%s"
adi/dotemacs-min-version
emacs-version))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DIRECTORY STRUCTURE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Take clues from bbatsov/prelude, except keep structure relative to our
;; initial adi/dotemacs-dir path. This way we can start the user's emacs via
;; ~/.emacs.d symlinked to the dotemacs repo, and develop/debug against
;; the repo without potentially overwriting transient state files of the
;; daily driver .emacs.d.
(defvar adi/dotemacs-dir
(file-name-directory (or load-file-name (buffer-file-name)))
"The dotemacs' root. Normally it should be ~/.emacs.d.")
(defvar adi/dotemacs-custom-file (expand-file-name "custom.el" adi/dotemacs-dir)
"Make Emacs add customisations here, instead of the init file.
Usually customisations made from the UI go into `custom-file'.")
(setq custom-file adi/dotemacs-custom-file)
(unless (file-exists-p adi/dotemacs-custom-file)
(make-empty-file adi/dotemacs-custom-file))
(load-file custom-file) ; load *now*, instead of unpredictable load sequence
(defvar adi/dotemacs-savefile-dir (file-name-as-directory
(expand-file-name "savefile" adi/dotemacs-dir))
"This folder stores all the automatically generated save/history-files.")
(unless (file-exists-p adi/dotemacs-savefile-dir)
(make-directory adi/dotemacs-savefile-dir))
(defvar adi/dotemacs-backup-files-dir (file-name-as-directory
(expand-file-name "autosaves"
adi/dotemacs-savefile-dir))
"Store backup file copies Emacs makes when editing files,
and for auto-saves we can restore from.")
(unless (file-exists-p adi/dotemacs-backup-files-dir)
(make-directory adi/dotemacs-backup-files-dir))
(defvar adi/dotemacs-cache-dir (file-name-as-directory
(expand-file-name ".cache" adi/dotemacs-dir))
"Store things like lsp servers that lsp-mode can auto-download.")
(unless (file-exists-p adi/dotemacs-cache-dir)
(make-directory adi/dotemacs-cache-dir))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BETTER DEFAULTS
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; via
;; - technomancy/better-defaults
;; - bbatsov/prelude
;; - vedang/emacs-up
;; - suvratapte/dot-emacs-dot-d
;; SPACES OVER TABS,
;; but keep up conventional appearances of 8 character wide tabs.
;; NOTE: Use `C-q TAB` to insert literal tabs.
(setq-default indent-tabs-mode nil
tab-width 8
fill-column 80)
(setq
;; PERFORMANCE
;; gc ~100MB for better overall performance. ~50-100MB is recommended
;; these days over the long-obsolete default of ~8MB.
gc-cons-threshold (* 100 1024 1024)
;; Large files freeze Emacs. Warn for files over ~100MB.
large-file-warning-threshold (* 100 1024 1024)
;; Always load newest byte code. cf. bbatsov/prelude
load-prefer-newer t
;; LSP-mode performance tweaks
read-process-output-max (* 1024 1024) ; 1mb
;; FILE BACKUP RESTORE
;; cf. https://www.emacswiki.org/emacs/BackupDirectory
;; and https://www.emacswiki.org/emacs/BackupFiles
;; and https://www.emacswiki.org/emacs/AutoSave
;; To also configure local backups for tramp,
;; use `tramp-backup-directory-alist'
backup-by-copying t ; don't clobber symlinks
backup-directory-alist ; put backup files here, e.g. `file~' and `#file#' copies
`(("." . ,adi/dotemacs-backup-files-dir))
;; INTERACTIONS
inhibit-startup-message t
ring-bell-function 'ignore ; no beeps
require-final-newline t ; always well-form files
confirm-kill-emacs 'y-or-n-p ; instead of disabling 'C-x C-c'
use-dialog-box nil ; no popups please
create-lockfiles nil
tab-always-indent 'complete
tab-first-completion 'word
enable-recursive-minibuffers t
minibuffer-depth-indicate-mode t
uniquify-buffer-name-style 'forward
uniquify-after-kill-buffer-p t ; rename after killing uniquified
uniquify-ignore-buffers-re "^\\*") ; spare special buffers
;; MORE INTERACTIONS
;; http://ergoemacs.org/emacs/emacs_save_restore_opened_files.html
(global-auto-revert-mode 1) ; auto-revert buffer if file-on-disk changes
(delete-selection-mode t) ; delete selection for any keypress
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(fset 'yes-or-no-p 'y-or-n-p) ; typing "yes/no" gets annoying fast
(global-unset-key (kbd "C-z")) ; avoid fat fingering `suspend-frame'
;; UTF-8 as default encoding
;; ref: http://ergoemacs.org/emacs/emacs_encoding_decoding_faq.html
(set-language-environment "UTF-8")
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; VISUAL AESTHETICS
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Go easy on the eyes. This high-contrast darkmode theme is built
;; into Emacs, as of Emacs version 28.1
(load-theme 'modus-vivendi)
;; More screen real estate
(scroll-bar-mode 0)
(tool-bar-mode 0)
(tooltip-mode 0) ; disable popup, make help text appear in echo area
(menu-bar-mode 0)
(column-number-mode t)
(set-fringe-mode '(5 . 13)) ;; describe variable fringe-mode
(global-hl-line-mode +1)
(global-visual-line-mode +1) ; prefer Visual Line Mode
;; (add-hook 'text-mode-hook #'visual-line-mode) ; selectively, instead of global visual line mode
;; (add-hook 'org-mode-hook #'visual-line-mode) ; selectively, instead of global visual line mode
;; Tweak Font sizes globally, and also set line number mode
(defun adi/set-frame-font--default ()
"Interactively set default frame font for day to day work."
(interactive)
(set-frame-font "-PfEd-DejaVu Sans Mono-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1")
(global-display-line-numbers-mode -1))
(defun adi/set-frame-font--pair-prog ()
"Interactively set frame font for pair programming."
(interactive)
(set-frame-font "-PfEd-DejaVu Sans Mono-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1")
(global-display-line-numbers-mode 1))
(defun adi/set-frame-font--code-demo ()
"Interactively set frame font for presentations and demos."
(interactive)
(set-frame-font "-1ASC-Liberation Mono-normal-normal-normal-*-28-*-*-*-m-0-iso10646-1")
(global-display-line-numbers-mode -1))
;; Ensure we always start Emacs with the default font.
(adi/set-frame-font--default)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package management
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'package)
;; Explicitly set the exact package archives list
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("elpa" . "https://elpa.gnu.org/packages/")))
;; Set package download directory relative to the adi/dotemacs-dir
(setq package-user-dir (file-name-as-directory
(expand-file-name "elpa" adi/dotemacs-dir)))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;; PATH Setting
;;
;; Make the environment variables inside Emacs look the same as my shell
;; ref: https://github.com/purcell/exec-path-from-shell
;; e.g. LSP server installation requires nvm path that is not available
;; in PATH if we start Emacs from the GUI.
(unless (package-installed-p 'exec-path-from-shell)
(package-install 'exec-path-from-shell))
(require 'exec-path-from-shell)
;; Set list of vars to look up from shell env. Do so _before_ initialising.
(dolist (var '("SSH_AUTH_SOCK" "SSH_AGENT_PID" "GPG_AGENT_INFO" "LANG" "LC_CTYPE"))
(add-to-list 'exec-path-from-shell-variables var))
;; Set $MANPATH, $PATH and exec-path from shell, when executed in a GUI
;; frame on OS X and Linux.
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize))
(when (daemonp)
(exec-path-from-shell-initialize))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Use use-package
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Ian Y.E. Pan's tutorial is a nice quick overview.
;; https://ianyepan.github.io/posts/setting-up-use-package/
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(eval-when-compile
(add-to-list 'load-path package-user-dir)
(require 'use-package))
(setq use-package-always-ensure t
use-package-expand-minimally t ; set nil to debug use-package forms
use-package-verbose t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; All the packages!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Packages useful to configure packages
;; radian-software/blackout to tune major/minor mode names
;; in modeline. It unifies functionality of the mutually
;; confusing modeline lighters delight, diminish, and dim.
;; It integrates seamlessly with use-package.
(use-package blackout)
(use-package helpful ; h/t systemcrafters.net
;; https://github.com/Wilfred/helpful
:config
(setq helpful-max-buffers 1) ; but actually we want it to reuse buffer
:bind (("C-h f" . #'helpful-callable)
("C-h F" . #'helpful-function) ; exclude macros
("C-h v" . #'helpful-variable)
("C-h k" . #'helpful-key)
("C-h x" . #'helpful-command)
;; Lookup the current symbol at point. C-c C-d is
;; a common keybinding for this in lisp modes.
("C-c C-d" . #'helpful-at-point))
:blackout)
(use-package command-log-mode
:blackout)
(use-package esup
;; emacs startup profiler
:blackout)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Remember states of files, buffer, desktop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package recentf
:config
(setq recentf-save-file (expand-file-name "recentf"
adi/dotemacs-savefile-dir)
recentf-max-saved-items 1000
recentf-max-menu-items 10
recentf-auto-cleanup 'never)
(recentf-mode +1)
:blackout)
(use-package savehist
:config
(setq savehist-additional-variables
'(search-ring regexp-search-ring)
savehist-autosave-inerval 60
savehist-file (expand-file-name "savehist"
adi/dotemacs-savefile-dir)))
(use-package saveplace
:config
(setq save-place-file
(expand-file-name "saveplace" adi/dotemacs-savefile-dir))
(save-place-mode +1))
(use-package desktop
;; Restore Emacs buffers, windows, placement to how it was at shutdown
;; ref: https://www.emacswiki.org/emacs/Desktop
:init
;; Reduce startup slowdown due to side effects like Language Servers being
;; started synchronously due to eager restores of programming buffers.
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Saving-Emacs-Sessions.html
(setq desktop-restore-eager 1)
:config
(add-to-list 'desktop-path adi/dotemacs-savefile-dir)
(setq desktop-dirname adi/dotemacs-savefile-dir
desktop-auto-save-timeout 30)
(defun adi/desktop-read-after-emacs-startup ()
(when (file-exists-p
(expand-file-name desktop-base-file-name desktop-dirname))
(desktop-read)))
;; does not work with 'after-init-hook
(add-hook 'emacs-startup-hook #'adi/desktop-read-after-emacs-startup)
(desktop-save-mode 1))
(use-package super-save ; h/t bbatsov/prelude
:config
(super-save-mode +1)
:blackout)
(use-package amx ; h/t Protesilaos Stavrou
;; NOTES: When amx is active:
;; - "C-h f" calls describe-function
;; - "M-." jumps to definition
;; - "C-h w" shows keybindings for thing at point
:config
(setq amx-save-file
(expand-file-name "amx-items" adi/dotemacs-savefile-dir))
(setq amx-backend 'ivy) ; integrates with counsel-M-x
(setq amx-show-key-bindings t) ; t by default
;; (add-to-list 'amx-ignored-command-matchers "") ; to ignore commands
(amx-mode +1)
:blackout)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Manage windows, buffers, movement, navigation and create a more
;; "heads up display" kind of experience.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package counsel ; brings in ivy, and swiper too
:config
(ivy-mode +1)
:bind
(:map counsel-find-file-map
("C-l" . counsel-up-directory)
:map global-map
("M-x" . counsel-M-x)
("C-c c" . counsel-company)
("C-c i" . counsel-imenu)
("C-x C-f" . counsel-find-file)
;; because counsel find file does not let us edit results
("C-M-y" . ivy-insert-current-full)
("C-c C-f" . counsel-recentf)
("C-c g" . counsel-git) ; find files respecting gitignore
("C-c k" . counsel-ag)
("C-c l" . counsel-locate)
("C-c b" . counsel-switch-buffer-other-window))
:blackout)
(use-package swiper
:bind
(:map
global-map
("C-s" . swiper)
("C-c t" . swiper-thing-at-point) ; swiper-map prefix key is "C-c"
("C-c a t" . swiper-all-thing-at-point)))
;; Note: Use "M-o" after "C-x C-f" or "C-s" for additional options
;; for the context for the thing selected in the minibuffer.
(use-package ivy
:config
(ivy-mode t)
(setq ivy-use-virtual-buffers t
ivy-count-format "%d/%d: " ; per the docs
;; don't start ivy prompts with '^' regex match,
;; because we want fuzzier matching by default
ivy-initial-inputs-alist nil
;; fix annoying problem of ivy not letting us rename file
;; that has partial completion
;; https://www.reddit.com/r/emacs/comments/e02lup/ivy_swiper_doesnt_let_me_rename_or_save_a_file/
ivy-use-selectable-prompt t)
:blackout)
(use-package ivy-rich ; h/t suvratapte/dot-emacs-dot-d
:custom
(ivy-rich-path-style 'abbreviate)
:config
(ivy-rich-mode +1)
;; perf. Caching:
;; ref: https://github.com/Yevgnen/ivy-rich#project-performance
;; ref: https://github.com/syl20bnr/spacemacs/issues/10101
;; ivy-rich slows down a lot if many buffers are open
;; `M-x profiler-start' revealed lots of busy work by ivy-rich.
;; This is super annoying, but the workaround is to add a cache.
(ivy-rich-project-root-cache-mode +1)
:blackout)
(use-package ibuffer
:bind (:map global-map
("C-x C-b" . ibuffer-other-window))
:blackout)
(use-package which-key
:config (which-key-mode t)
(setq which-key-idle-delay 0.5)
;; Sort based on the key description ignoring case (default
;; is 'which-key-key-order).
(setq which-key-sort-order 'which-key-description-order)
:blackout)
(use-package ace-window
:bind
(:map global-map
("s-w" . 'ace-window)
([remap other-window] . 'ace-window))
:blackout)
(use-package avy
:blackout)
(use-package key-chord
:config
(key-chord-mode +1)
(setq key-chord-one-key-delay 0.2) ; e.g. "jj", default 0.2
(setq key-chord-two-keys-delay 0.2) ; e.g. "jk", default 0.1
(setq key-chord-safety-interval-backward 0.5) ; default 0.1 is too close to key delays
(setq key-chord-safety-interval-forward 0) ; default 0.35 causes laggy experience
(key-chord-define-global "jj" 'avy-goto-word-1)
(key-chord-define-global "jl" 'avy-goto-line)
(key-chord-define-global "jk" 'avy-goto-char)
(key-chord-define-global "XX" 'execute-extended-command)
(key-chord-define-global "yy" 'counsel-yank-pop)
(key-chord-define-global "g;" 'ace-window)
(key-chord-define-global ";g" 'ace-window)
:blackout)
(use-package golden-ratio
;; https://github.com/roman/golden-ratio.el
;; See also slightly modified version h/t github.com/nebkor
;; https://git.sr.ht/~wklew/golden
:config
(golden-ratio-mode +1)
;; Set auto scale to `t' for wide screens, but not for 16:10, 1900px HD displays
(setq golden-ratio-auto-scale nil
;; golden-ratio-wide-adjust-factor 1
;; golden-ratio-adjust-factor .8
)
;; Make golden ratio play nice with other modes
(dolist (cmd '(ace-window
magit-status
avy-goto-char
avy-goto-char-2
avy-goto-word-0
avy-goto-word-1
avy-goto-line))
(add-to-list 'golden-ratio-extra-commands
cmd))
:blackout)
(use-package rotate
;; https://github.com/daichirata/emacs-rotate
:blackout)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; General text viewing and editing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Enable narrowings to enhance focus, and reduce accidental
;; edits of nonfocus areas (thanks to save-restrictions).
;; h/t bbatsov/prelude
;; Note: `C-x n w` makes all visible again.
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-defun 'disabled nil)
;; COMplete ANYthing, please!
;; TODO: instead try radian's completion system
;;; ref: https://github.com/radian-software/radian
(use-package company
:bind (:map global-map
("TAB" . company-indent-or-complete-common)
;; Got to love the name hippie-expand. Use this for general
;; expansions, because company-complete is good for the
;; current/narrow-case expansions. By default, `M-/` binds
;; to the less powerful `dabbrev-expand`. To alter search
;; options, :config the hippie-expand-try-functions-list.
("M-/" . hippie-expand))
:config (setq company-idle-delay 0.3
company-minimum-prefix-length 2)
(global-company-mode t)
:blackout)
;; Selections
(use-package expand-region
:bind
(("C-=" . er/expand-region)
("C-M-=" . er/contract-region)))
;; Multiple cursors
(use-package multiple-cursors
:config
(setq mc/list-file (expand-file-name ".mc-lists.el"
adi/dotemacs-savefile-dir))
;; Idea taken from "Emacs: Define Key Sequence"
;; ref: http://ergoemacs.org/emacs/emacs_keybinding_power_of_keys_sequence.html
;; define prefix keymap for multiple cursors
(define-prefix-command 'adi/multi-cursor-keymap)
(define-key adi/multi-cursor-keymap (kbd "e") 'mc/edit-lines)
(define-key adi/multi-cursor-keymap (kbd "a") 'mc/mark-all-like-this-dwim)
(define-key adi/multi-cursor-keymap (kbd "r") 'mc/mark-all-in-region-regexp)
(define-key adi/multi-cursor-keymap (kbd "s") 'mc/mark-all-symbols-like-this-in-defun)
(define-key adi/multi-cursor-keymap (kbd "w") 'mc/mark-all-words-like-this-in-defun)
(define-key adi/multi-cursor-keymap (kbd "C-n") 'mc/mark-next-like-this)
(define-key adi/multi-cursor-keymap (kbd "C-p") 'mc/mark-previous-like-this)
(define-key adi/multi-cursor-keymap (kbd "C-a") 'mc/mark-all-like-this)
:bind-keymap ("C-c m" . adi/multi-cursor-keymap))
(use-package wgrep ; editable grep buffers FTW!
:blackout)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Lispy editing support
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Tweak settings of built-in paren package
(use-package paren
:ensure nil ; it already exists, don't try to search online
:init
(setq show-paren-delay 0)
:config
(show-paren-mode t)
:blackout)
(use-package smartparens ; h/t bbatsov/prelude use it like paredit
:config
(require 'smartparens-config)
(setq sp-base-key-bindings 'paredit
sp-autoskip-closing-pair 'always
sp-hybrid-kill-entire-symbol nil)
(sp-use-paredit-bindings)
(show-smartparens-global-mode +1)
:hook ((emacs-lisp-mode
lisp-mode
lisp-interaction-mode
ielm-mode
clojure-mode
cider-repl-mode) . smartparens-strict-mode)
:blackout)
(use-package eldoc
:config
(global-eldoc-mode t)
:custom ; h/t jwiegley/dot-emacs
(eldoc-echo-area-use-multiline-p t)
(eldoc-echo-area-display-truncation-message nil)
;; for hooks, ref: https://www.emacswiki.org/emacs/ElDoc
:hook ((emacs-lisp-mode lisp-interaction-mode ielm-mode)
. eldoc-mode)
:blackout)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Programming and Writing workflow support
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package magit
:blackout)
(use-package projectile
:blackout)
(use-package yasnippet
:config
(defvar adi/dotemacs-yasnippets-dir
(file-name-as-directory (expand-file-name "snippets" adi/dotemacs-dir)))
(unless (file-exists-p adi/dotemacs-yasnippets-dir)
(make-directory adi/dotemacs-yasnippets-dir))
(setq yas-snippet-dirs
(list adi/dotemacs-yasnippets-dir))
(add-to-list 'hippie-expand-try-functions-list
'yas-hippie-try-expand)
(yas-global-mode +1) ; nb. global mode can slow down emacs startup
:blackout yas-minor-mode)
(use-package yasnippet-snippets
:requires yasnippet
:config
(yasnippet-snippets-initialize)
:blackout)
(use-package flyspell
;; "C-," to goto next error,
;; "C-M-i" to auto-fix current error (cycles options)
:ensure nil ; built in
:hook ((text-mode org-mode) . flyspell-mode)
:hook ((prog-mode) . flyspell-prog-mode)
:blackout)
(use-package flycheck
:config (global-flycheck-mode +1)
:blackout)
(use-package zeal-at-point
;; ref: https://github.com/jinzhu/zeal-at-point
:bind (:map global-map
("\C-c z" . 'zeal-at-point)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Programming languages
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package lsp-mode
;; ref: https://emacs-lsp.github.io/lsp-mode/page/installation/#use-package
:init
(setq lsp-keymap-prefix "C-c C-l")
:hook ((clojure-mode clojurescript-mode clojurec-mode) . lsp-deferred)
:hook (lsp-mode . lsp-enable-which-key-integration)
:custom
;; LSP "workspace" dirs:
;; nb. "workspace" seems to be a confusing concept. It is a VSCode concept
;; that lsp-mode superseded as "session", because lsp-mode was already using
;; the word "workspace" in some other context. See: `lsp-describe-session'.
;; https://github.com/emacs-lsp/lsp-mode/discussions/3095
;; "workspace" directories still seem to server some purpose (no idea what),
;; and seem to be language specific.
(lsp-clojure-workspace-dir
(file-name-as-directory (expand-file-name "workspace"
adi/dotemacs-dir)))
:config
(setq lsp-server-install-dir (file-name-as-directory ; install local to dotemacs
(expand-file-name "lsp" adi/dotemacs-cache-dir))
;; Perf. tweaks. Ref: https://emacs-lsp.github.io/lsp-mode/page/performance/
lsp-idle-delay 0.500 ; bump higher if lsp-mode gets sluggish
lsp-log-io nil
; lsp-enable-indentation nil ; set 'nil' to use cider indentation instead of lsp
; lsp-enable-completion-at-point nil; set 'nil' to use cider completion instead of lsp
;; No semgrep. https://emacs-lsp.github.io/lsp-mode/page/lsp-semgrep/
;; IDK why semgrep is on by default, docs are thin on configuring it
;; I don't want the error 'Command "semgrep lsp" is not present on the path.'
;; because I don't want to "pip install semgrep --user".
lsp-semgrep-server-command nil)
;; LANGUAGE SPECIFIC SETTINGS
;; clojure-lsp: cf. https://clojure-lsp.io/clients/#emacs
(add-to-list 'lsp-language-id-configuration
`(clojurex-mode . "clojure"))
:commands (lsp lsp-deferred))
(use-package lsp-ui
:after lsp-mode
:commands lsp-ui-mode
:bind (:map lsp-ui-mode-map ; h/t github.com/bbatsov/prelude
([remap xref-find-definitions] . #'lsp-ui-peek-find-definitions)
([remap xref-find-references] . #'lsp-ui-peek-find-references)
("C-c C-l ." . 'lsp-ui-peek-find-definitions)
("C-c C-l ," . 'lsp-ui-peek-find-references)
("C-c C-l r" . 'lsp-rename)
("C-c C-l x" . 'lsp-workspace-restart)
("C-c C-l w" . 'lsp-ui-peek-find-workspace-symbol)
("C-c C-l i" . 'lsp-ui-peek-find-implementation)
("C-c C-l d" . 'lsp-describe-thing-at-point)
("C-c C-l e" . 'lsp-execute-code-action))
:config
; h/t github.com/bbatsov/prelude
(setq lsp-ui-sideline-enable t
lsp-ui-doc-enable t
lsp-ui-peek-enable t
lsp-ui-peek-always-show t))
(use-package lsp-ivy
:after lsp-mode
:commands lsp-ivy-workspace-symbol)
;; treemacs is cool, but I'm not sure I want it yet.
;; cf: https://github.com/emacs-lsp/lsp-treemacs
;; and https://github.com/Alexander-Miller/treemacs
;; (use-package lsp-treemacs
;; :after lsp-mode
;; :commands lsp-treemacs-errors-list
;; :config
;; (setq treemacs-space-between-root-nodes nil))
;; dap-mode, optionally to use LANGUAGE-specific debuggers
;; cf. https://emacs-lsp.github.io/lsp-mode/page/installation/#use-package
;; (use-package dap-mode)
;; (use-package dap-LANGUAGE :ensue t :after dap-mode) ; load dap adapter for LANGUAGE
(use-package clojure-mode
;; Brings in clojure-mode for Clj, clojurescript-mode for Cljs,
;; and clojurec-mode for Cljc
;; Hook into subword-mode to work with CamelCase tokens like Java classes
;; h/t suvratapte/dot-emacs-dot-d
:hook ((clojure-mode . subword-mode)
(clojure-mode . yas-minor-mode))
:config
(setq clojure-indent-style 'align-arguments)
:blackout "Clj")
(use-package cider
;; Note: Ensure CIDER and lsp-mode play well together, as we use both.
;; - LSP for more static-analysis-y services (completions, lookups, errors etc.),
;; - CIDER for "live" runtime services (enhanced REPL, interactive debugger etc.).
:after clojure-mode
:init
;; Use clojure-lsp for eldoc and completions
;; h/t cider docs and ericdallo/dotfiles/.config/doom/config.el
(remove-hook 'eldoc-documentation-functions #'cider-eldoc)
(remove-hook 'completion-at-point-functions #'cider-complete-at-point)
:custom
(cider-preferred-build-tool 'clj)
:bind
(:map cider-mode-map
("C-c C-l" . nil))
:config
;; settings h/t suvratapte/dot-emacs-dot-d
(setq cider-repl-pop-to-buffer-on-connect nil
cider-show-error-buffer t
cider-auto-select-error-buffer t
cider-repl-history-file (expand-file-name "cider-history"
adi/dotemacs-savefile-dir)
cider-repl-wrap-history t
cider-prompt-for-symbol nil
cider-repl-use-pretty-printing t
nrepl-log-messages nil
;; play nice with lsp-mode
;; h/t ericdallo/dotfiles/.config/doom/config.el
cider-font-lock-dynamically nil ; use lsp semantic tokens
cider-eldoc-display-for-symbol-at-point nil ; use lsp
cider-prompt-for-symbol nil ; use lsp
cider-use-xref nil ; use lsp
;; Maybe customize variables for cider-jack-in
;; https://docs.cider.mx/cider/basics/up_and_running.html
)
:blackout)
;; clj-refactor can go where clojure-lsp refactor can't go
(use-package clj-refactor
;; config h/t ericdallo/dotfiles doom emacs config
:after clojure-mode
:config
(setq cljr-warn-on-eval nil
cljr-eagerly-build-asts-on-startup nil
cljr-add-ns-to-blank-clj-files nil ; use lsp
cljr-magic-require-namespaces
'(("s" . "schema.core")
("pp" . "clojure.pprint"))))
(use-package clj-deps-new
;; Emacs interface to deps-new (like lein new for Leiningen, or clj-new for Boot)
;; ref: https://github.com/jpe90/emacs-clj-deps-new
:blackout)
;; WEB DEVELOPMENT
(use-package web-mode
:config
;; for config ref: bbatsov/prelude/modules/prelude-web.el
;; e.g. to set web-mode for templating languages,
;; to define new smartparen pairs etc.
(setq web-mode-enable-auto-pairing nil) ; play nice with smartparens
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
:blackout)
(use-package json-mode
:blackout)
(use-package js2-mode
:blackout)
;; DOCUMENTATION FORMATS
(use-package adoc-mode
:blackout)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Org Mode specials
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Enable org babel languages
;; ref: https://orgmode.org/manual/Languages.html#Languages
;; and: https://orgmode.org/worg/org-contrib/babel/languages.html
;;
;; NOTE: If org-babel appears to be broken, it may be an org 9+ compile issue.
;; If so, purging org mode .elc files helps.
;; ref: "Org-Mode Evaluation of code disabled #7641"
;; https://github.com/syl20bnr/spacemacs/issues/7641#issuecomment-259701129
;; and: "Org-mode 9: unable to eval code-blocks"
;; https://emacs.stackexchange.com/a/28448
;; Purge this way:
;; - shut down emacs
;; - find ~/.emacs.d/elpa/org-9.* -name "*elc" # ensure only orgmode files found
;; - find ~/.emacs.d/elpa/org-9.* -name "*elc" -delete # re-execute, but with delete
;; - start emacs
;; - profit!
(use-package ob-http
:blackout)
(use-package ob-sql-mode
:blackout)
(use-package ob-clojurescript
:blackout)
(use-package ob-kotlin
:blackout)
(use-package org
:ensure nil
:config
(setq org-export-coding-system 'utf-8
org-babel-clojure-backend 'cider)
(org-babel-do-load-languages
'org-babel-load-languages
'((shell . t)
(awk . t)
(sed . t)
(http . t)
(clojure . t)
(clojurescript . t)
(python . t)
(kotlin . t)
(groovy . t)
(sql .t )
(sqlite . t)
(plantuml . t))))
(use-package ox-asciidoc
;; Org export backend for org to asciidoc
:blackout)
(use-package org-tree-slide
;; Simple org outline based presentation mode
;; ref: https://github.com/takaxp/org-tree-slide
:bind (("<f8>" . 'org-tree-slide-mode)
("S-<f8>" . 'org-tree-slide-skip-done-toggle)
:map org-tree-slide-mode-map
("<f9>" . 'org-tree-slide-move-previous-tree)
("<f10>" . 'org-tree-slide-move-next-tree)
("<f11>" . 'org-tree-slide-content))
:config
(setq org-tree-slide-skip-outline-level 4))
(provide 'init)
;;; init.el ends here