-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.el
2886 lines (2556 loc) · 98.6 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
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; -*- lexical-binding: t -*-
;; #+options: prop:t
;;; init.el --- My personal emacs configuration.
;;; Author: Ovidiu Stoica
;;; Commentary:
;;; The entire configuration is kept here.
;;; Currently written for Emacs 29.
;;; Code:
;; * PACKAGE MANAGEMENT
(defmacro comment (&rest body)
"Ignore forms in BODY, returning nil. Used for rich comments."
nil)
(setq custom-file (concat user-emacs-directory "custom.el"))
(load custom-file :no-error-if-file-is-missing)
;; DEBUG
;; (setq debug-on-error t)
;; (setq debug-on-quit t)
;; ** ELPA
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
;; ** USE-PACKAGE
(when (< emacs-major-version 29)
(unless (package-installed-p 'use-package)
(unless package-archive-contents
(package-refresh-contents))
(package-install 'use-package)))
;; Don't show byte compilation warnings when installing packages
(add-to-list 'display-buffer-alist
'("\\`\\*\\(Warnings\\|Compile-Log\\)\\*\\'"
(display-buffer-no-window)
(allow-no-window . t)))
(require 'use-package)
(use-package use-package
:no-require
:custom
(use-package-enable-imenu-support t))
(defvar os/emacs-tmp-dir (concat user-emacs-directory "tmp/")
"Scratch space for stuff...")
(setq package-user-dir (concat user-emacs-directory "elpa"))
(setq package-native-compile t)
;; ** STRAIGHT
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name
"straight/repos/straight.el/bootstrap.el"
(or (bound-and-true-p straight-base-dir)
user-emacs-directory)))
(bootstrap-version 7))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
;; * PRIVATE CONFIG
(defvar os/private-config-file (concat user-emacs-directory "emacs-private.el")
"File with configuration info that can't be in public repository.")
(if (file-readable-p os/private-config-file)
(progn
(load-library os/private-config-file)
(message "Loaded private config")))
;; * BUILTIN
(use-package early-init
:no-require
:unless (featurep 'early-init)
:config
(load-file (locate-user-emacs-file "early-init.el")))
(use-package delight
:ensure t)
(use-package compile
:preface
(defun os/compile-autoclose (buffer string)
"Hide successful builds window with BUFFER and STRING."
(if (string-match "finished" string)
(progn
(message "Build finished: ")
(run-with-timer 3 nil
(lambda ()
(when-let* ((multi-window (> (count-windows) 1))
(live (buffer-live-p buffer))
(window (get-buffer-window buffer t)))
(delete-window window))))
(message "Compilation %s" string))))
:config
(setq compilation-scroll-output t)
(setq compilation-auto-jump-to-first-error t
compilation-max-output-line-length nil
compilation-finish-functions (list #'os/compile-autoclose)))
(use-package emacs
:config
(push (expand-file-name "plugins/" user-emacs-directory) load-path)
(push (expand-file-name "lisp/" user-emacs-directory) load-path))
;; ** MAC STUFF
(when (eq system-type 'darwin)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)
(setq browse-url-browser-function 'browse-url-default-macosx-browser)
(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
(add-to-list 'default-frame-alist '(ns-appearance . dark)))
(use-package local-config
:no-require
:preface
(defgroup local-config ()
"Customization group for local settings."
:prefix "local-config-"
:group 'emacs)
(defcustom local-config-dark-theme 'modus-vivendi
"Dark theme to use."
:tag "Dark theme"
:type 'symbol
:group 'local-config)
(defcustom local-config-light-theme 'modus-operandi
"Light theme to use."
:tag "Light theme"
:type 'symbol
:group 'local-config)
(defcustom no-hscroll-modes '(term-mode)
"Major modes to disable horizontal scrolling."
:tag "Modes to disable horizontal scrolling"
:type '(repeat symbol)
:group 'local-config)
(provide 'local-config))
;; ** FUNCTIONS
(use-package functions
:no-require
:functions (dbus-color-theme-dark-p)
:init (require 'bind-key)
:bind (("M-Q" . split-pararagraph-into-lines)
("C-M-;" . mark-end-of-sentence)
("C-g" . os/keyboard-quit-dwim)
(:map prog-mode-map
("C-<return>" . os/open-line-below)
("M-<return>" . os/open-line-above)))
:preface
(require 'subr-x)
(defun os/pfa-invoices-path ()
"Returns current invoices path"
(interactive)
(insert "~/Dropbox/Stoica Ovidiu/2024/chitante"))
(defun os/create-file-in-project-root (filename content)
(interactive)
(let ((file-path (expand-file-name filename (project-root (project-current)))))
(with-temp-file file-path
(insert content))))
(defun os-clear-xcode-simulator-cache ()
(interactive)
(shell-command "rm -rf ~/Library/Developer/Xcode/DerivedData")
(shell-command "rm -rf ~/Library/Caches/com.apple.dt.Xcode")
(shell-command "rm -rf ~/Library/Developer/CoreSimulator/Caches/")
(message "Simulator cache cleared succesfully!"))
(defun os/project-shell-command (command)
"Runs COMMAND in the current project root"
(let ((default-directory (project-root (project-current))))
(shell-command command)))
(defun os/project-file-exists-p (filename)
"Checks if FILENAME exists in the project root"
(let ((project-file (expand-file-name filename (project-root (project-current)))))
(file-exists-p project-file)))
(defun os/initialize-python-venv ()
"Initiate python venv and load it with specified Python version"
(interactive)
(let* ((python-version (or (completing-read "Python version: " '("python3" "python3.9" "python3.10" "python3.11" "python3.12" "python3.13") nil nil "python3"))))
(os/project-shell-command (format "%s -m venv .venv" python-version))
(os/create-file-in-project-root ".envrc"
"export VIRTUAL_ENV=.venv\nlayout python3")
(envrc-allow)
(envrc-reload)
(when (os/project-file-exists-p "requirements.txt")
(os/project-shell-command "pip install -r requirements.txt"))
(message "Python venv initialization finished!")))
(defun os-code-radio ()
(interactive)
(browse-url "https://coderadio.freecodecamp.org/"))
(defun os/open-line-below ()
"Open a line below the current line."
(interactive)
(end-of-line)
(newline)
(indent-for-tab-command))
(defun os/open-line-above ()
"Open a line above the current line."
(interactive)
(beginning-of-line)
(newline)
(forward-line -1)
(indent-for-tab-command))
(defun split-pararagraph-into-lines ()
"Split the current paragraph into lines with one sentence each."
(interactive)
(save-excursion
(let ((fill-column most-positive-fixnum))
(fill-paragraph))
(let ((auto-fill-p auto-fill-function)
(end (progn (end-of-line) (backward-sentence) (point))))
(back-to-indentation)
(unless (= (point) end)
(auto-fill-mode -1)
(while (< (point) end)
(forward-sentence)
(delete-horizontal-space)
(newline-and-indent))
(deactivate-mark)
(when auto-fill-p
(auto-fill-mode t))
(when (looking-at "^$")
(delete-char -1))))))
(defun in-termux-p ()
"Detect if Emacs is running in Termux."
(executable-find "termux-info"))
(defun dark-mode-enabled-p ()
"Check if dark mode is enabled."
(cond ((file-exists-p (expand-file-name "~/.dark-mode")) t)
((featurep 'dbus) (dbus-color-theme-dark-p))
(t nil)))
(defun memoize (fn)
"Create a storage for FN's args.
Checks if FN was called with set args before. If so, return the
value from the storage and don't call FN. Otherwise calls FN,
and saves its result in the storage. FN must be referentially
transparent."
(let ((memo (make-hash-table :test 'equal)))
(lambda (&rest args)
;; `memo' is used as a singleton to check for absense of value
(let ((value (gethash args memo memo)))
(if (eq value memo)
(puthash args (apply fn args) memo)
value)))))
(defmacro defmemo (name &rest funtail)
(declare (doc-string 3) (indent 2) (debug defun))
`(defalias ',name (memoize (lambda ,@funtail))))
(font-lock-add-keywords
'emacs-lisp-mode
'(("(\\(defmemo\\)\\_>\\s *\\(\\(?:\\sw\\|\\s_\\)+\\)?"
(1 font-lock-keyword-face nil t)
(2 font-lock-function-name-face nil t))))
(defvar-local ssh-tunnel-port nil)
(put 'ssh-tunnel-port 'safe-local-variable #'numberp)
(defun ssh-tunnel (host port &optional local-port)
"Start an SSH tunnel from localhost to HOST:PORT.
If LOCAL-PORT is nil, PORT is used as local port."
(interactive (list (read-string "host: " nil 'ssh-host-history)
(read-number "port: " ssh-tunnel-port 'ssh-port-history)
(when current-prefix-arg
(read-number "local port: " ssh-tunnel-port 'ssh-port-history))))
(let ((name (if (and local-port (not (= local-port port)))
(format "*ssh-tunnel:%s:%s:%s" local-port host port)
(format "*ssh-tunnel:%s:%s" host port))))
(async-shell-command
(format "ssh -4 -N -L %s:localhost:%s %s" (or local-port port) port host)
(concat " " name))))
(defun os/keyboard-quit-dwim ()
"Do-What-I-Mean behaviour for a general `keyboard-quit'
The generic `keyboard-quit' does not do the expected thing when
the minibuffer is open. Whereas we want it to close the
minibuffer, even without explicitly focusing it.
The DWIM behaviour of this command is as follows:
- When the region is active, disable it.
- When a minibuffer is open, but not focused, close the minibuffer.
- When the Completions buffer is selected, close it.
- In every other case use the regular `keyboard-quit'."
(interactive)
(cond
((region-active-p) (keyboard-quit))
((derived-mode-p 'completion-list-mode) (delete-completion-window))
((> (minibuffer-depth) 0) (abort-recursive-edit))
(t (keyboard-quit))))
(provide 'functions))
;; ** DEFAULTS
(use-package defaults
:no-require
:preface
(setq-default
indent-tabs-mode nil
load-prefer-newer t
truncate-lines t
bidi-paragraph-direction 'left-to-right
frame-title-format
'((:eval
(if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
(buffer-name))))
auto-window-vscroll nil
mouse-highlight t
hscroll-step 1
hscroll-margin 1
scroll-margin 0
scroll-preserve-screen-position nil
frame-resize-pixelwise window-system
window-resize-pixelwise window-system
fill-column 80)
(when (window-system)
(setq-default
x-gtk-use-system-tooltips nil
cursor-type 'box
blink-cursor-mode 0
cursor-in-non-selected-windows nil))
(setq
ring-bell-function 'ignore
mode-line-percent-position nil
enable-recursive-minibuffers t)
(when (version<= "27.1" emacs-version)
(setq bidi-inhibit-bpa t))
(global-visual-line-mode t)
(custom-set-variables
'(safe-local-variable-values
'((eval progn
(make-variable-buffer-local 'cider-jack-in-nrepl-middlewares)
(add-to-list 'cider-jack-in-nrepl-middlewares "shadow.cljs.devtools.server.nrepl/middleware"))
(cider-clojure-cli-aliases . "-A:dev:test:reveal")
(eval progn
(setq cider-clojure-cli-aliases ":dev:test")
(make-variable-buffer-local 'cider-jack-in-nrepl-middlewares)
(add-to-list 'cider-jack-in-nrepl-middlewares "shadow.cljs.devtools.server.nrepl/middleware")
(setq cider-format-code-options
'(("indents"
(("$"
(("block" 1))))))))
(cider-default-cljs-repl . custom)
(cider-clojure-cli-aliases . ":dev:test")
(cider-preferred-build-tool . clojure-cli))))
(provide 'defaults))
;; * WINDOW MANAGEMENT
;; ** WINDMOVE
(use-package windmove
:config
(setq windmove-wrap-around t)
(windmove-default-keybindings))
;; ** POPPER
(defvar os/occur-grep-modes-list '(occur-mode
grep-mode
xref--xref-buffer-mode
ivy-occur-grep-mode
ivy-occur-mode
locate-mode
flymake-diagnostics-buffer-mode
rg-mode)
"List of major-modes used in occur-type buffers.")
;; This does not work at buffer creation since the major-mode for
;; REPLs is not yet set when `display-buffer' is called, but is
;; useful afterwards
(defvar os/repl-modes-list '(matlab-shell-mode
eshell-mode
geiser-repl-mode
shell-mode
eat-mode
vterm-mode
inferior-python-mode
cider-repl-mode
fennel-repl-mode
jupyter-repl-mode
inferior-ess-julia-mode)
"List of major-modes used in REPL buffers.")
(defvar os/repl-names-list
'("^\\*\\(?:.*?-\\)\\{0,1\\}e*shell[^z-a]*\\(?:\\*\\|<[[:digit:]]+>\\)$"
"\\*.*REPL.*\\*"
"\\*MATLAB\\*"
"\\*Python\\*"
"^\\*jupyter-repl.*?\\(\\*\\|<[[:digit:]]>\\)$"
"\\*Inferior .*\\*$"
"^\\*julia.*\\*$"
"\\*cider-repl.*\\*$"
"\\*ielm\\*"
"\\*nodejs\\*"
"\\*edebug\\*")
"List of buffer names used in REPL buffers.")
(defvar os/help-modes-list '(helpful-mode
help-mode
pydoc-mode
TeX-special-mode)
"List of major-modes used in documentation buffers.")
(defvar os/man-modes-list '(Man-mode woman-mode)
"List of major-modes used in Man-type buffers.")
(defvar os/message-modes-list '(compilation-mode
edebug-eval-mode)
"List of major-modes used in message buffers.")
(use-package popper
:straight '(:type git :host github :repo "karthink/popper")
:bind (("C-`" . popper-toggle)
("M-`" . popper-cycle)
("C-M-`" . popper-toggle-type))
:init
(setq popper-reference-buffers
(append os/help-modes-list
os/man-modes-list
os/repl-modes-list
os/repl-names-list
os/occur-grep-modes-list
;; my/man-modes-list
'(Custom-mode
compilation-mode
messages-buffer-mode)
'(("^\\*Warnings\\*$" . hide)
("^\\*Compile-Log\\*$" . hide)
"^\\*Matlab Help.*\\*$"
;; "^\\*Messages\\*$"
"^\\*Backtrace\\*"
"^\\*evil-registers\\*"
"^\\*Apropos"
"^Calc:"
"^\\*eldoc\\*"
"^\\*TeX errors\\*"
"^\\*ielm\\*"
"^\\*TeX Help\\*"
"^\\*ChatGPT\\*"
"^\\*Input History\\*"
"^\\*gptel-ask\\*"
"^\\*clojure-compilation\\*"
"\\*Shell Command Output\\*"
"\\*Async Shell Command\\*"
("\\*Detached Shell Command\\*" . hide)
"\\*Completions\\*"
;; "\\*scratch.*\\*$"
"[Oo]utput\\*")))
(add-to-list 'display-buffer-alist '("\\*ielm\\*"
(display-buffer-in-side-window)
(side . left)
(window-width . 50)))
(add-to-list 'display-buffer-alist '("\\*cider-repl.*\\*$"
(display-buffer-in-side-window)
(side . left)
(window-width . 50)))
(add-to-list 'display-buffer-alist
'("^\\*cider-repl .+\\*"
(display-buffer-in-side-window)
(side . left)
(window-width . 70)))
(add-to-list 'display-buffer-alist
'("^\\*cider-repl .*\\*"
(display-buffer-in-side-window)
(side . left)
(window-width . 120)))
(popper-mode +1)
(popper-echo-mode +1))
;; ** CORE PACKAGES
(use-package delsel
:ensure nil ;; no need to install it as it is built-in
:hook (after-init . delete-selection-mode))
(use-package re-builder
:ensure nil
:config
(setq reb-re-syntax 'string))
(use-package bind-key
:ensure t)
(require 'bind-key)
(use-package window
:config
(add-to-list
'display-buffer-alist
'("\\*Calendar*" (display-buffer-at-bottom))))
(use-package mouse
:bind (("<mode-line> <mouse-2>" . nil)
("<mode-line> <mouse-3>" . nil)))
(use-package mode-line
:no-require
:preface
(defvar mode-line-interactive-position
`(line-number-mode
(:propertize " %l:%C"
help-echo "mouse-1: Goto line"
mouse-face mode-line-highlight
local-map ,(let ((map (make-sparse-keymap)))
(define-key map [mode-line down-mouse-1] 'goto-line)
map)))
"Mode line position with goto line binding.")
(put 'mode-line-interactive-position 'risky-local-variable t)
(setq-default mode-line-format ; Sets the default mode-line format for all buffers
'( ; List of elements to display in the mode-line
"%e" ; Shows error message if there's not enough space
mode-line-front-space ; Space at beginning
mode-line-modified ; Shows if buffer is modified (*) or read-only (%)
mode-line-remote ; Shows @ if file is remote
mode-line-frame-identification ; Shows - if windowed, or terminal name if in terminal
; Custom project display section
(:propertize ; Adds face properties to the following expression
(:eval ; Evaluates the expression each time mode-line updates
(when-let ((project (project-current))) ; If in a project
(format "[%s] " (project-name project)))) ; Shows [project-name]
face warning) ; Displays in warning face color
; Buffer name section
(:propertize "%b" face mode-line-buffer-id) ; Current buffer name with special face
" " ; Space
mode-line-position ; Shows position in buffer (line number, %)
(vc-mode vc-mode) ; Version control information
" " ; Space
mode-line-modes ; Major and minor modes
mode-line-misc-info ; Misc information
mode-line-end-spaces)) ; Spaces at end
(provide 'mode-line))
(use-package font
:no-require
:hook (after-init . setup-fonts)
:preface
(defun font-installed-p (font-name)
"Check if a font with FONT-NAME is available."
(find-font (font-spec :name font-name)))
(defun setup-fonts ()
(cond ((font-installed-p "JetBrainsMono Nerd Font Mono")
(set-face-attribute 'default nil :font "JetBrainsMono Nerd Font Mono"))
((font-installed-p "Source Code Pro")
(set-face-attribute 'default nil :font "Source Code Pro")))
(when (font-installed-p "DejaVu Sans")
(set-face-attribute 'variable-pitch nil :font "DejaVu Sans")))
(provide 'font))
(use-package cus-edit
:custom
(custom-file (locate-user-emacs-file "custom.el"))
:init
(load custom-file :noerror))
(use-package novice
:preface
(defvar disabled-commands (locate-user-emacs-file "disabled.el")
"File to store disabled commands, that were enabled permanently.")
(define-advice enable-command (:around (fn command) use-disabled-file)
(let ((user-init-file disabled-commands))
(funcall fn command)))
:init
(load disabled-commands 'noerror))
(use-package files
:preface
(defvar backup-dir
(locate-user-emacs-file ".cache/backups")
"Directory to store backups.")
(defvar auto-save-dir
(locate-user-emacs-file ".cache/auto-save/")
"Directory to store auto-save files.")
:custom
(backup-by-copying t)
(create-lockfiles nil)
(backup-directory-alist
`(("." . ,backup-dir)))
(auto-save-file-name-transforms
`((".*" ,auto-save-dir t)))
(auto-save-no-message t)
(auto-save-interval 100)
(require-final-newline t)
:bind ("<f5>" . revert-buffer-quick)
:init
(unless (file-exists-p auto-save-dir)
(make-directory auto-save-dir t)))
(use-package subr
:no-require
:init
(if (boundp 'use-short-answers)
(setq-default use-short-answers t)
(fset 'yes-or-no-p 'y-or-n-p)))
(use-package savehist
:ensure nil
:hook (after-init . savehist-mode))
(use-package simple
:bind (("M-z" . zap-up-to-char)
("M-S-z" . zap-to-char)
("C-x k" . kill-current-buffer)
("C-h C-f" . describe-face)
([remap undo] . undo-only))
:hook ((before-save . delete-trailing-whitespace)
(overwrite-mode . overwrite-mode-set-cursor-shape)
(after-init . column-number-mode)
(prog-mode . display-line-numbers-mode)
(after-init . line-number-mode))
:custom
(yank-excluded-properties t)
(blink-matching-delay 0)
(blink-matching-paren t)
(copy-region-blink-delay 0)
(shell-command-default-error-buffer "*Shell Command Errors*")
:config
(defun overwrite-mode-set-cursor-shape ()
(when (display-graphic-p)
(setq cursor-type (if overwrite-mode 'hollow 'box))))
:preface
(unless (fboundp 'minibuffer-keyboard-quit)
(autoload #'minibuffer-keyboard-quit "delsel" nil t))
(define-advice keyboard-quit
(:around (quit) quit-current-context)
"Quit the current context.
When there is an active minibuffer and we are not inside it close
it. When we are inside the minibuffer use the regular
`minibuffer-keyboard-quit' which quits any active region before
exiting. When there is no minibuffer `keyboard-quit' unless we
are defining or executing a macro."
(if (active-minibuffer-window)
(if (minibufferp)
(minibuffer-keyboard-quit)
(abort-recursive-edit))
(unless (or defining-kbd-macro
executing-kbd-macro)
(funcall-interactively quit)))))
(use-package minibuffer
:hook (eval-expression-minibuffer-setup . common-lisp-modes-mode)
:bind ( :map minibuffer-inactive-mode-map
("<mouse-1>" . ignore))
:custom
(completion-styles '(partial-completion basic))
(read-buffer-completion-ignore-case t)
(read-file-name-completion-ignore-case t)
:custom-face
(completions-first-difference ((t (:inherit unspecified)))))
(use-package diminish
:config
(diminish 'whole-line-or-region-local-mode)
(diminish 'visual-line-mode))
(use-package bindings
:bind ( :map ctl-x-map
("DEL" . nil)
("C-d" . dired-jump))
:init
(setq mode-line-end-spaces nil))
(use-package frame
:requires seq
:bind (("C-z" . ignore)
("C-x C-z" . ignore)))
(use-package startup
:no-require
:custom
(inhibit-splash-screen t))
(use-package menu-bar
:unless (display-graphic-p)
:config
(menu-bar-mode -1))
(use-package tooltip
:when (window-system)
:custom
(tooltip-x-offset 0)
(tooltip-y-offset (line-pixel-height))
(tooltip-frame-parameters
`((name . "tooltip")
(internal-border-width . 2)
(border-width . 1)
(no-special-glyphs . t))))
(use-package uniquify
:defer t
:custom
(uniquify-buffer-name-style 'forward))
(use-package display-line-numbers
:hook (display-line-numbers-mode . toggle-hl-line)
:custom
(display-line-numbers-width 4)
(display-line-numbers-grow-only t)
(display-line-numbers-width-start t)
:config
(defun toggle-hl-line ()
(hl-line-mode (if display-line-numbers-mode 1 -1))))
(use-package pixel-scroll
:when (fboundp #'pixel-scroll-precision-mode)
:hook (after-init . pixel-scroll-precision-mode)
:custom
(scroll-margin 0))
(use-package paren
:hook (prog-mode . show-paren-mode))
(use-package vc-hooks
:defer t
:custom
(vc-follow-symlinks t))
(use-package eldoc
:delight eldoc-mode
:defer t
:custom
(eldoc-echo-area-use-multiline-p nil))
(use-package dired
:preface
(defun dired-back-to-top ()
"Jump to the top file in a Dired buffer."
(interactive)
(goto-char (point-min))
;; because the number of header lines varies depending on whether
;; mode info is shown or hidden, find the double-dot directory entry
;; and go forward one line -- heuristic, but will always work.
(search-forward "..")
(dired-next-line 1))
(defun dired-jump-to-bottom ()
"Jump to the last file in a Dired buffer."
(interactive)
(goto-char (point-max))
(dired-next-line -1))
(defun dired-home-directory ()
(interactive)
(dired (expand-file-name "~/")))
:commands
dired
dired-jump
dired-next-line
dired-up-directory
:bind (:map dired-mode-map
("-" . dired-up-directory)
("~" . dired-home-directory)
("E" . wdired-change-to-wdired-mode)
([remap beginning-of-buffer] . dired-back-to-top)
([remap end-of-buffer] . dired-jump-to-bottom))
:config
(setq insert-directory-program "gls"
dired-use-ls-dired t
dired-listing-switches "-lAXGh --group-directories-first --sort=extension" ;; directories first
dired-hide-details-mode t
dired-recursive-copies 'always
dired-recursive-copies 'always
delete-by-moving-to-trash t
dired-dwim-target t))
(use-package dired-subtree
:ensure t
:after dired
:bind (:map dired-mode-map
("<tab>" . dired-subtree-toggle)
("TAB" . dired-subtree-toggle)
("<backtab>" . dired-subtree-remove)
("S-TAB" . dired-subtree-remove))
:config
(setq dired-subtree-use-backgrounds nil))
;; Dired extra font locking
(use-package diredfl
:after (dired)
:hook (dired-mode .diredfl-mode))
(use-package trashed
:ensure t
:commands (trashed)
:config
(setq trashed-action-confirmer 'y-or-n-p)
(setq trashed-use-header-line t)
(setq trashed-sort-key '("Date deleted" . t))
(setq trashed-date-format "%Y-%m-%d %H:%M:%S"))
(use-package json-hs-extra
:after json
:hook (json-ts-mode . json-hs-extra-setup)
:preface
(defun json-hs-extra-create-overlays (overlay)
"Creates overlays for block beginning, hiding whitespace.
Sets OVERLAY `json-hs-extra-overlays' property to the list of created
overlays."
(let ((end (point)))
(save-excursion
(forward-sexp -1)
(when-let ((overlays (ov-regexp "{[[:space:]\n]*" (point) end)))
(mapc (lambda (ov) (overlay-put ov 'display "{")) overlays)
(overlay-put overlay 'json-hs-extra-overlays overlays)))))
(defun json-hs-extra-delete-overlays (fn overlay)
"Deletes overlays for block beginning created earlier.
Deletes overlays in the `json-hs-extra-overlays' property of OVERLAY,
created with `json-hs-extra-create-overlays'."
(mapc #'delete-overlay (overlay-get overlay 'json-hs-extra-overlays))
(funcall fn overlay))
(defun json-hs-extra-setup ()
"Special settings for JSON buffers."
(setq-local hs-block-start-regexp "\\(?:{[[:space:]\n]*\\|\\[\\)"
hs-set-up-overlay #'json-hs-extra-create-overlays))
(provide 'json-hs-extra)
:config
(advice-add 'delete-overlay :around #'json-hs-extra-delete-overlays))
(use-package help
:custom
(help-window-select t))
(use-package flycheck
:ensure t
:init (global-flycheck-mode)
:bind (:map flycheck-mode-map
("M-n" . flycheck-next-error)
("M-p" . flycheck-previous-error)))
(use-package flyspell
:ensure t
:when (or (executable-find "ispell")
(executable-find "aspell")
(executable-find "hunspell"))
:hook ((org-mode git-commit-mode markdown-mode) . flyspell-mode))
(use-package autorevert
:hook (after-init . global-auto-revert-mode))
(use-package outline
:hook (common-lisp-modes-mode . lisp-outline-minor-mode)
:delight outline-minor-mode
:custom
(outline-minor-mode-cycle t)
:preface
(defun lisp-outline-minor-mode ()
(setq-local outline-regexp "^;;;;*[[:space:]]\\w")
(outline-minor-mode)))
(use-package browse-url
:when (fboundp 'xwidget-webkit-browse-url)
:custom (browse-url-browser-function #'xwidget-webkit-browse-url))
(use-package centered-window :ensure t)
(use-package repeat
:hook (after-init . repeat-mode))
;; TODO Document on this further, possibly disable LSP on very long files
(use-package so-long
:init (global-so-long-mode 1))
;; * COMPLETION
(use-package orderless
:ensure t
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles basic partial-completion))))
(orderless-matching-styles
'(orderless-literal
orderless-prefixes
orderless-initialism
orderless-regexp
orderless-flex)))
(use-package vertico
:ensure t
:custom
(vertico-count 20) ; Number of candidates to display
(vertico-cycle t) ; Go from last to first candidate and first to last (cycle)?
(vertico-resize t)
:bind ( :map vertico-map
("M-RET" . vertico-exit-input))
:hook (after-init . vertico-mode))
(use-package vertico-directory
:after vertico
:bind ( :map vertico-map
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word))
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
(use-package marginalia
:ensure t
:hook (after-init . marginalia-mode))
(use-package corfu
:ensure t
:hook (after-init . global-corfu-mode)
:bind (:map corfu-map
("<tab>" . corfu-complete)
([remap completion-at-point] . corfu-complete))
:config
(setq tab-always-indent 'complete)
(setq corfu-preview-current nil)
(setq corfu-min-width 20)
(setq corfu-auto t
corfu-auto-prefix 1
corfu-auto-delay 0
corfu-cycle t
corfu-on-exact-match nil) ;; Don't auto insert
(corfu-popupinfo-mode 1) ; shows documentation after `corfu-popupinfo-delay'
;; Sort by input history (no need to modify `corfu-sort-function').
(with-eval-after-load 'savehist
(corfu-history-mode 1)
(add-to-list 'savehist-additional-variables 'corfu-history)))
(use-package corfu-popupinfo
:bind ( :map corfu-popupinfo-map
("M-p" . corfu-popupinfo-scroll-down)
("M-n" . corfu-popupinfo-scroll-up))
:hook (corfu-mode . corfu-popupinfo-mode)
:config (setq corfu-popupinfo-delay '(0.5 . 0.2))
:custom-face
(corfu-popupinfo ((t :height 1.0))))
(use-package corfu-terminal
:ensure t
:unless (display-graphic-p)
:commands (corfu-terminal-mode)
:hook (after-init . corfu-terminal-mode))
(use-package cape
:ensure t
:after corfu
:config
(setq completion-at-point-functions '(cape-file)))
(use-package ov
:ensure t
:commands (ov-regexp))
(use-package abbrev
:delight abbrev-mode
:custom
(save-abbrevs nil))
(use-package consult
:ensure t
:defines
consult-customize
;; Replace bindings. Lazily loaded due by `use-package'.
:bind (;; C-c bindings in `mode-specific-map'
("C-c M-x" . consult-mode-command)
("C-c h" . consult-history)