-
Notifications
You must be signed in to change notification settings - Fork 56
/
init.el
931 lines (773 loc) · 27.8 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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
;;; init.el --- Bozhidar's Emacs configuration
;;
;; Copyright (c) 2016-2023 Bozhidar Batsov
;;
;; Author: Bozhidar Batsov <bozhidar@batsov.dev>
;; URL: https://github.com/bbatsov/emacs.d
;; Keywords: convenience
;; This file is not part of GNU Emacs.
;;; Commentary:
;; This is my personal Emacs configuration. Nothing more, nothing less.
;;; License:
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
;; keep the installed packages in .emacs.d
(setq package-user-dir (expand-file-name "elpa" user-emacs-directory))
(package-initialize)
;; update the package metadata is the local cache is missing
(unless package-archive-contents
(package-refresh-contents))
(setq user-full-name "Bozhidar Batsov"
user-mail-address "bozhidar@batsov.com")
;; Always load newest byte code
(setq load-prefer-newer t)
;; reduce the frequency of garbage collection by making it happen on
;; each 50MB of allocated data (the default is on every 0.76MB)
(setq gc-cons-threshold 50000000)
;; warn when opening files bigger than 100MB
(setq large-file-warning-threshold 100000000)
;; quit Emacs directly even if there are running processes
(setq confirm-kill-processes nil)
(defconst bozhidar-savefile-dir (expand-file-name "savefile" user-emacs-directory))
;; create the savefile dir if it doesn't exist
(unless (file-exists-p bozhidar-savefile-dir)
(make-directory bozhidar-savefile-dir))
;; the toolbar is just a waste of valuable screen estate
;; in a tty tool-bar-mode does not properly auto-load, and is
;; already disabled anyway
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
;; the blinking cursor is nothing, but an annoyance
(blink-cursor-mode -1)
;; disable the annoying bell ring
(setq ring-bell-function 'ignore)
;; disable startup screen
(setq inhibit-startup-screen t)
;; nice scrolling
(setq scroll-margin 0
scroll-conservatively 100000
scroll-preserve-screen-position 1)
(when (fboundp 'pixel-scroll-precision-mode)
(pixel-scroll-precision-mode t))
;; let's pick a nice font
(cond
((find-font (font-spec :name "Cascadia Code"))
(set-frame-font "Cascadia Code-14"))
((find-font (font-spec :name "Menlo"))
(set-frame-font "Menlo-14"))
((find-font (font-spec :name "DejaVu Sans Mono"))
(set-frame-font "DejaVu Sans Mono-14"))
((find-font (font-spec :name "Inconsolata"))
(set-frame-font "Inconsolata-14")))
;; mode line settings
(line-number-mode t)
(column-number-mode t)
(size-indication-mode t)
;; enable y/n answers
(fset 'yes-or-no-p 'y-or-n-p)
;; maximize the initial frame automatically
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
;; more useful frame title, that show either a file or a
;; buffer name (if the buffer isn't visiting a file)
(setq frame-title-format
'((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))))
;; Emacs modes typically provide a standard means to change the
;; indentation width -- eg. c-basic-offset: use that to adjust your
;; personal indentation width, while maintaining the style (and
;; meaning) of any files you load.
(setq-default indent-tabs-mode nil) ;; don't use tabs to indent
(setq-default tab-width 8) ;; but maintain correct appearance
;; Newline at end of file
(setq require-final-newline t)
;; Wrap lines at 80 characters
(setq-default fill-column 80)
;; delete the selection with a keypress
(delete-selection-mode t)
;; store all backup and autosave files in the tmp dir
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
;; revert buffers automatically when underlying files are changed externally
(global-auto-revert-mode t)
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; hippie expand is dabbrev expand on steroids
(setq hippie-expand-try-functions-list '(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
try-expand-list
try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol))
;; use hippie-expand instead of dabbrev
(global-set-key (kbd "M-/") #'hippie-expand)
(global-set-key (kbd "s-/") #'hippie-expand)
;; replace buffer-menu with ibuffer
(global-set-key (kbd "C-x C-b") #'ibuffer)
;; Start proced in a similar manner to dired
(global-set-key (kbd "C-x p") #'proced)
;; align code in a pretty way
(global-set-key (kbd "C-x \\") #'align-regexp)
(define-key 'help-command (kbd "C-i") #'info-display-manual)
;; misc useful keybindings
(global-set-key (kbd "s-<") #'beginning-of-buffer)
(global-set-key (kbd "s->") #'end-of-buffer)
(global-set-key (kbd "s-q") #'fill-paragraph)
(global-set-key (kbd "s-x") #'execute-extended-command)
;; smart tab behavior - indent or complete
(setq tab-always-indent 'complete)
;; enable some commands that are disabled by default
(put 'erase-buffer 'disabled nil)
;; make it possible to navigate to the C source of Emacs functions
(setq find-function-C-source-directory "~/projects/emacs")
;; auto-create missing folders
(defun er-auto-create-missing-dirs ()
"Make missing parent directories automatically."
(let ((target-dir (file-name-directory buffer-file-name)))
(unless (file-exists-p target-dir)
(make-directory target-dir t))))
(add-to-list 'find-file-not-found-functions #'er-auto-create-missing-dirs)
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(setq use-package-verbose t)
;;; built-in packages
(use-package paren
:config
(show-paren-mode +1))
(use-package elec-pair
:config
(electric-pair-mode +1))
(use-package calendar
:config
;; weeks in Bulgaria start on Monday
(setq calendar-week-start-day 1))
(use-package time
:config
;; TZs to display with `world-clock'
(setq world-clock-list
'(("America/Los_Angeles" "Seattle")
("America/New_York" "New York")
("America/Sao_Paulo" "Sao Paulo")
("America/Argentina/Buenos_Aires" "Buenos Aires")
("Europe/London" "London")
("Europe/Paris" "Paris")
("Europe/Sofia" "Sofia")
("Asia/Istanbul" "Istanbul")
("Israel" "Tel Aviv")
("Asia/Calcutta" "Bangalore")
("Asia/Tokyo" "Tokyo"))))
(use-package dictionary
:bind (("C-c l" . dictionary-lookup-definition))
:config
(setq dictionary-server "dict.org"))
;; highlight the current line
(use-package hl-line
:config
(global-hl-line-mode +1))
(use-package abbrev
:config
(setq save-abbrevs 'silently)
(setq-default abbrev-mode t))
(use-package uniquify
:config
(setq uniquify-buffer-name-style 'forward)
(setq uniquify-separator "/")
;; rename after killing uniquified
(setq uniquify-after-kill-buffer-p t)
;; don't muck with special buffers
(setq uniquify-ignore-buffers-re "^\\*"))
;; saveplace remembers your location in a file when saving files
(use-package saveplace
:config
(setq save-place-file (expand-file-name "saveplace" bozhidar-savefile-dir))
;; activate it for all buffers
(setq-default save-place t))
(use-package savehist
:config
(setq savehist-additional-variables
;; search entries
'(search-ring regexp-search-ring)
;; save every minute
savehist-autosave-interval 60
;; keep the home clean
savehist-file (expand-file-name "savehist" bozhidar-savefile-dir))
(savehist-mode +1))
;; (use-package desktop
;; :config
;; (desktop-save-mode +1))
(use-package recentf
:config
(setq recentf-save-file (expand-file-name "recentf" bozhidar-savefile-dir)
recentf-max-saved-items 500
recentf-max-menu-items 15
;; disable recentf-cleanup on Emacs start, because it can cause
;; problems with remote files
recentf-auto-cleanup 'never)
(recentf-mode +1))
(use-package windmove
:config
;; use shift + arrow keys to switch between visible buffers
(windmove-default-keybindings))
(use-package dired
:config
;; dired - reuse current buffer by pressing 'a'
(put 'dired-find-alternate-file 'disabled nil)
;; always delete and copy recursively
(setq dired-recursive-deletes 'always)
(setq dired-recursive-copies 'always)
;; if there is a dired buffer displayed in the next window, use its
;; current subdir, instead of the current subdir of this dired buffer
(setq dired-dwim-target t)
;; enable some really cool extensions like C-x C-j(dired-jump)
(require 'dired-x))
(use-package whitespace
:init
(dolist (hook '(prog-mode-hook text-mode-hook))
(add-hook hook #'whitespace-mode))
(add-hook 'before-save-hook #'whitespace-cleanup)
:config
(setq whitespace-line-column 80) ;; limit line length
(setq whitespace-style '(face tabs empty trailing lines-tail)))
(use-package lisp-mode
:config
(defun bozhidar-visit-ielm ()
"Switch to default `ielm' buffer.
Start `ielm' if it's not already running."
(interactive)
(crux-start-or-switch-to 'ielm "*ielm*"))
(add-hook 'emacs-lisp-mode-hook #'rainbow-delimiters-mode)
(define-key emacs-lisp-mode-map (kbd "C-c C-z") #'bozhidar-visit-ielm)
(define-key emacs-lisp-mode-map (kbd "C-c C-c") #'eval-defun)
(define-key emacs-lisp-mode-map (kbd "C-c C-b") #'eval-buffer))
(use-package ielm
:config
(add-hook 'ielm-mode-hook #'rainbow-delimiters-mode))
;;; third-party packages
(use-package zenburn-theme
:ensure t
:config
(load-theme 'zenburn t))
(use-package diminish
:ensure t
:config
(diminish 'abbrev-mode)
(diminish 'flyspell-mode)
(diminish 'flyspell-prog-mode)
(diminish 'eldoc-mode))
(use-package avy
:ensure t
:bind (("s-." . avy-goto-word-or-subword-1)
("s-," . avy-goto-char)
("C-c ." . avy-goto-word-or-subword-1)
("C-c ," . avy-goto-char)
("M-g f" . avy-goto-line)
("M-g w" . avy-goto-word-or-subword-1))
:config
(setq avy-background t))
(use-package magit
:ensure t
:bind (("C-x g" . magit-status)))
(use-package git-timemachine
:ensure t
:bind (("s-g" . git-timemachine)))
(use-package ag
:ensure t)
(use-package projectile
:ensure t
:init
(setq projectile-project-search-path '("~/projects/" "~/work/" "~/playground"))
:config
;; I typically use this keymap prefix on macOS
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
;; On Linux, however, I usually go with another one
(define-key projectile-mode-map (kbd "C-c C-p") 'projectile-command-map)
(global-set-key (kbd "C-c p") 'projectile-command-map)
(projectile-mode +1))
(use-package pt
:ensure t)
(use-package expand-region
:ensure t
:bind ("C-=" . er/expand-region))
(use-package elisp-slime-nav
:ensure t
:config
(dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))
(add-hook hook #'elisp-slime-nav-mode))
(diminish 'elisp-slime-nav-mode))
(use-package paredit
:ensure t
:config
(define-key paredit-mode-map (kbd "RET") nil)
(add-hook 'emacs-lisp-mode-hook #'paredit-mode)
;; enable in the *scratch* buffer
(add-hook 'lisp-interaction-mode-hook #'paredit-mode)
(add-hook 'ielm-mode-hook #'paredit-mode)
(add-hook 'lisp-mode-hook #'paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'paredit-mode)
(diminish 'paredit-mode "()"))
(use-package anzu
:ensure t
:bind (("M-%" . anzu-query-replace)
("C-M-%" . anzu-query-replace-regexp))
:config
(global-anzu-mode))
(use-package easy-kill
:ensure t
:config
(global-set-key [remap kill-ring-save] 'easy-kill))
(use-package exec-path-from-shell
:ensure t
:config
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize)))
(use-package move-text
:ensure t
:bind
(([(meta shift up)] . move-text-up)
([(meta shift down)] . move-text-down)))
(use-package rainbow-delimiters
:ensure t)
(use-package rainbow-mode
:ensure t
:config
(add-hook 'prog-mode-hook #'rainbow-mode)
(diminish 'rainbow-mode))
;; (use-package evil
;; :ensure t
;; :bind (("C-z" . evil-local-mode)))
(use-package inf-ruby
:ensure t
:config
(add-hook 'ruby-mode-hook #'inf-ruby-minor-mode))
(use-package ruby-mode
:config
(setq ruby-insert-encoding-magic-comment nil)
(add-hook 'ruby-mode-hook #'subword-mode))
(use-package clojure-mode
:ensure t
:config
;; teach clojure-mode about some macros that I use on projects like
;; nREPL and Orchard
(define-clojure-indent
(returning 1)
(testing-dynamic 1)
(testing-print 1))
(add-hook 'clojure-mode-hook #'paredit-mode)
(add-hook 'clojure-mode-hook #'subword-mode)
(add-hook 'clojure-mode-hook #'rainbow-delimiters-mode))
(use-package inf-clojure
:ensure t
:config
(add-hook 'inf-clojure-mode-hook #'paredit-mode)
(add-hook 'inf-clojure-mode-hook #'rainbow-delimiters-mode))
(use-package cider
:ensure t
:config
(setq nrepl-log-messages t)
(add-hook 'cider-repl-mode-hook #'paredit-mode)
(add-hook 'cider-repl-mode-hook #'rainbow-delimiters-mode))
(use-package flycheck-joker
:ensure t)
(use-package elixir-mode
:ensure t
:config
(add-hook 'elixir-mode #'subword-mode))
(use-package erlang
:ensure t
:config
(when (eq system-type 'windows-nt)
(setq erlang-root-dir "C:/Program Files/erl7.2")
(add-to-list 'exec-path "C:/Program Files/erl7.2/bin")))
(use-package haskell-mode
:ensure t
:config
(add-hook 'haskell-mode-hook #'subword-mode)
(add-hook 'haskell-mode-hook #'interactive-haskell-mode)
(add-hook 'haskell-mode-hook #'haskell-doc-mode))
(use-package rust-mode
:ensure t)
(use-package eglot
:ensure t)
;;;; OCaml support
(use-package tuareg
:ensure t
:mode (("\\.ocamlinit\\'" . tuareg-mode)))
(use-package dune
:ensure t)
;; Merlin configuration
(use-package merlin
:ensure t
:config
(add-hook 'tuareg-mode-hook #'merlin-mode)
;; (add-hook 'merlin-mode-hook #'company-mode)
;; we're using flycheck instead
(setq merlin-error-after-save nil))
(use-package merlin-eldoc
:ensure t
:hook ((tuareg-mode) . merlin-eldoc-setup))
;; This uses Merlin internally
(use-package flycheck-ocaml
:ensure t
:config
(flycheck-ocaml-setup))
;; utop configuration
(use-package utop
:ensure t
:config
(add-hook 'tuareg-mode-hook #'utop-minor-mode))
;;;; Markup languages support
(use-package web-mode
:ensure t
:mode (("\\.html?\\'" . web-mode)
("\\.erb\\'" . web-mode)
("\\.hbs\\'" . web-mode))
:custom
(web-mode-markup-indent-offset 2)
(web-mode-css-indent-offset 2)
(web-mode-code-indent-offset 2))
(use-package markdown-mode
:ensure t
:mode (("\\.md\\'" . gfm-mode)
("\\.markdown\\'" . gfm-mode))
:config
(setq markdown-fontify-code-blocks-natively t)
:preface
(defun jekyll-insert-image-url ()
(interactive)
(let* ((files (directory-files "../assets/images"))
(selected-file (completing-read "Select image: " files nil t)))
(insert (format "![%s](/assets/images/%s)" selected-file selected-file))))
(defun jekyll-insert-post-url ()
(interactive)
(let* ((project-root (projectile-project-root))
(posts-dir (expand-file-name "_posts" project-root))
(default-directory posts-dir))
(let* ((files (remove "." (mapcar #'file-name-sans-extension (directory-files "."))))
(selected-file (completing-read "Select article: " files nil t)))
(insert (format "{%% post_url %s %%}" selected-file))))))
(use-package adoc-mode
:ensure t
:mode "\\.adoc\\'")
(use-package yaml-mode
:ensure t)
(use-package cask-mode
:ensure t)
(use-package eask-mode
:ensure t)
;; Enable rich annotations using the Marginalia package
(use-package marginalia
:ensure t
;; Either bind `marginalia-cycle' globally or only in the minibuffer
:bind (("M-A" . marginalia-cycle)
:map minibuffer-local-map
("M-A" . marginalia-cycle))
;; The :init configuration is always executed (Not lazy!)
:init
;; Must be in the :init section of use-package such that the mode gets
;; enabled right away. Note that this forces loading the package.
(marginalia-mode))
;; Enable vertico
(use-package vertico
:ensure t
:init
(vertico-mode)
;; Different scroll margin
;; (setq vertico-scroll-margin 0)
;; Show more candidates
;; (setq vertico-count 20)
;; Grow and shrink the Vertico minibuffer
;; (setq vertico-resize t)
;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
;; (setq vertico-cycle t)
)
;; A few more useful configurations for Vertico
(use-package emacs
:init
;; Add prompt indicator to `completing-read-multiple'.
;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
(defun crm-indicator (args)
(cons (format "[CRM%s] %s"
(replace-regexp-in-string
"\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
crm-separator)
(car args))
(cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)
;; Do not allow the cursor in the minibuffer prompt
(setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
;; Emacs 28: Hide commands in M-x which do not work in the current mode.
;; Vertico commands are hidden in normal buffers.
;; (setq read-extended-command-predicate
;; #'command-completion-default-include-p)
;; Enable recursive minibuffers
(setq enable-recursive-minibuffers t))
;; use the `orderless' completion style.
(use-package orderless
:ensure t
:init
;; Configure a custom style dispatcher (see the Consult wiki)
;; (setq orderless-style-dispatchers '(+orderless-dispatch)
;; orderless-component-separator #'orderless-escapable-split-on-space)
(setq completion-styles '(orderless basic)
completion-category-defaults nil
completion-category-overrides '((file (styles partial-completion)))))
(use-package consult
:ensure t
:bind (
;; C-x bindings (ctl-x-map)
("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
("C-x b" . consult-buffer) ;; orig. switch-to-buffer
("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
;; Custom M-# bindings for fast register access
("M-#" . consult-register-load)
("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
("C-M-#" . consult-register)
;; Other custom bindings
("M-y" . consult-yank-pop) ;; orig. yank-pop
("<help> a" . consult-apropos) ;; orig. apropos-command
;; M-g bindings (goto-map)
("M-g e" . consult-compile-error)
("M-g f" . consult-flycheck)
("M-g g" . consult-goto-line) ;; orig. goto-line
("M-g M-g" . consult-goto-line) ;; orig. goto-line
("M-g o" . consult-outline) ;; Alternative: consult-org-heading
("M-g m" . consult-mark)
("M-g k" . consult-global-mark)
("M-g i" . consult-imenu)
("M-g I" . consult-imenu-multi)
;; M-s bindings (search-map)
("M-s f" . consult-find)
("M-s F" . consult-locate)
("M-s g" . consult-grep)
("M-s G" . consult-git-grep)
("M-s r" . consult-ripgrep)
("M-s l" . consult-line)
("M-s L" . consult-line-multi)
("M-s m" . consult-multi-occur)
("M-s k" . consult-keep-lines)
("M-s u" . consult-focus-lines)))
(use-package corfu
:ensure t
;; Optional customizations
:custom
(corfu-cycle t) ;; Enable cycling for `corfu-next/previous'
(corfu-auto t) ;; Enable auto completion
;; (corfu-separator ?\s) ;; Orderless field separator
;; (corfu-quit-at-boundary nil) ;; Never quit at completion boundary
;; (corfu-quit-no-match nil) ;; Never quit, even if there is no match
;; (corfu-preview-current nil) ;; Disable current candidate preview
;; (corfu-preselect 'prompt) ;; Preselect the prompt
;; (corfu-on-exact-match nil) ;; Configure handling of exact matches
;; (corfu-scroll-margin 5) ;; Use scroll margin
;; Enable Corfu only for certain modes.
;; :hook ((prog-mode . corfu-mode)
;; (shell-mode . corfu-mode)
;; (eshell-mode . corfu-mode))
;; Recommended: Enable Corfu globally.
;; This is recommended since Dabbrev can be used globally (M-/).
;; See also `corfu-excluded-modes'.
:init
(global-corfu-mode))
;; Use Dabbrev with Corfu!
(use-package dabbrev
;; Swap M-/ and C-M-/
:bind (("M-/" . dabbrev-completion)
("C-M-/" . dabbrev-expand))
;; Other useful Dabbrev configurations.
:custom
(dabbrev-ignored-buffer-regexps '("\\.\\(?:pdf\\|jpe?g\\|png\\)\\'")))
;; (use-package company
;; :ensure t
;; :config
;; (setq company-idle-delay 0.5)
;; (setq company-show-numbers t)
;; (setq company-tooltip-limit 10)
;; (setq company-minimum-prefix-length 2)
;; (setq company-tooltip-align-annotations t)
;; ;; invert the navigation direction if the the completion popup-isearch-match
;; ;; is displayed on top (happens near the bottom of windows)
;; (setq company-tooltip-flip-when-above t)
;; (global-company-mode)
;; (diminish 'company-mode))
(use-package hl-todo
:ensure t
:config
(setq hl-todo-highlight-punctuation ":")
(global-hl-todo-mode +1))
(use-package zop-to-char
:ensure t
:bind (("M-z" . zop-up-to-char)
("M-Z" . zop-to-char)))
;; TODO: can be removed in favor of consult
(use-package imenu-anywhere
:ensure t
:bind (("C-c i" . imenu-anywhere)
("s-i" . imenu-anywhere)))
(use-package flyspell
:config
(when (eq system-type 'windows-nt)
(add-to-list 'exec-path "C:/Program Files (x86)/Aspell/bin/"))
(setq ispell-program-name "aspell" ; use aspell instead of ispell
ispell-extra-args '("--sug-mode=ultra"))
(add-hook 'text-mode-hook #'flyspell-mode)
(add-hook 'prog-mode-hook #'flyspell-prog-mode))
(use-package flycheck
:ensure t
:config
(add-hook 'after-init-hook #'global-flycheck-mode))
(use-package flycheck-eldev
:ensure t
:config
(setq flycheck-eldev-whitelist
'("~/projects/cider"
"~/projects/projectile")))
(use-package super-save
:ensure t
:config
;; add integration with ace-window
(add-to-list 'super-save-triggers 'ace-window)
(super-save-mode +1)
(diminish 'super-save-mode))
(use-package crux
:ensure t
:bind (("C-c o" . crux-open-with)
("M-o" . crux-smart-open-line)
("C-c n" . crux-cleanup-buffer-or-region)
("C-c f" . crux-recentf-find-file)
("C-M-z" . crux-indent-defun)
("C-c u" . crux-view-url)
("C-c e" . crux-eval-and-replace)
("C-c w" . crux-swap-windows)
("C-c D" . crux-delete-file-and-buffer)
("C-c r" . crux-rename-buffer-and-file)
("C-c t" . crux-visit-term-buffer)
("C-c k" . crux-kill-other-buffers)
("C-c TAB" . crux-indent-rigidly-and-copy-to-clipboard)
("C-c I" . crux-find-user-init-file)
("C-c S" . crux-find-shell-init-file)
("s-r" . crux-recentf-find-file)
("s-j" . crux-top-join-line)
("C-^" . crux-top-join-line)
("s-k" . crux-kill-whole-line)
("C-<backspace>" . crux-kill-line-backwards)
("s-o" . crux-smart-open-line-above)
([remap move-beginning-of-line] . crux-move-beginning-of-line)
([(shift return)] . crux-smart-open-line)
([(control shift return)] . crux-smart-open-line-above)
([remap kill-whole-line] . crux-kill-whole-line)
("C-c s" . crux-ispell-word-then-abbrev)))
(use-package diff-hl
:ensure t
:config
(global-diff-hl-mode +1)
(add-hook 'dired-mode-hook 'diff-hl-dired-mode)
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh))
(use-package which-key
:ensure t
:config
(which-key-mode +1)
(diminish 'which-key-mode))
(use-package undo-tree
:ensure t
:config
;; autosave the undo-tree history
(setq undo-tree-history-directory-alist
`((".*" . ,temporary-file-directory)))
(setq undo-tree-auto-save-history t)
(global-undo-tree-mode +1)
(diminish 'undo-tree-mode))
(use-package ace-window
:ensure t
:config
(global-set-key (kbd "s-w") 'ace-window)
(global-set-key [remap other-window] 'ace-window))
;; FIXME: Figure out why the vterm module stopped compiling properly
;; (use-package vterm
;; :ensure t
;; :config
;; (setq vterm-shell "/bin/bash")
;; ;; macOS
;; (global-set-key (kbd "s-v") 'vterm)
;; ;; Linux
;; (global-set-key (kbd "C-c v") 'vterm))
;; super useful for demos
(use-package keycast
:ensure t)
(use-package gif-screencast
:ensure t
:config
;; To shut up the shutter sound of `screencapture' (see `gif-screencast-command').
(setq gif-screencast-args '("-x"))
;; Optional: Used to crop the capture to the Emacs frame.
(setq gif-screencast-cropping-program "mogrify")
;; Optional: Required to crop captured images.
(setq gif-screencast-capture-format "ppm"))
;; temporarily highlight changes from yanking, etc
(use-package volatile-highlights
:ensure t
:config
(volatile-highlights-mode +1)
(diminish 'volatile-highlights-mode))
;; WSL-specific setup
(when (and (eq system-type 'gnu/linux)
(getenv "WSLENV"))
;; pgtk is only available in Emacs 29+
;; without it Emacs fonts don't scale properly on
;; HiDPI display
(when (< emacs-major-version 29)
(set-frame-font "Inconsolata 28" t t))
;; Teach Emacs how to open links in your default Windows browser
(let ((cmd-exe "/mnt/c/Windows/System32/cmd.exe")
(cmd-args '("/c" "start")))
(when (file-exists-p cmd-exe)
(setq browse-url-generic-program cmd-exe
browse-url-generic-args cmd-args
browse-url-browser-function 'browse-url-generic
search-web-default-browser 'browse-url-generic))))
;; Windows-specific setup
(when (eq system-type 'windows-nt)
(setq w32-pass-lwindow-to-system nil)
(setq w32-lwindow-modifier 'super) ; Left Windows key
(setq w32-pass-rwindow-to-system nil)
(setq w32-rwindow-modifier 'super) ; Right Windows key
(setq w32-pass-apps-to-system nil)
(setq w32-apps-modifier 'hyper) ; Menu/App key
(set-frame-font "Cascadia Code 14")
(add-to-list 'exec-path "C:/Program Files/Git/bin")
(add-to-list 'exec-path "C:/Program Files/Git/mingw64/bin")
(setenv "PATH" (concat "C:/Program Files/Git/bin;" "C:/Program Files/Git/mingw64/bin;" (getenv "PATH")))
;; needed for arc-mode
(add-to-list 'exec-path "C:/Program Files/7-Zip"))
;; config changes made through the customize UI will be stored here
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
(load custom-file))
;;; init.el ends here