-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinit.el
5511 lines (5016 loc) · 209 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
; -*- coding: utf-8; lexical-binding: t -*-
(defvar my-start-time (current-time)
"Time when Emacs was started")
;; Bootstrap elpaca
(defvar elpaca-installer-version 0.7)
(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory))
(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory))
(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory))
(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git"
:ref nil
:files (:defaults "elpaca-test.el" (:exclude "extensions"))
:build (:not elpaca--activate-package)))
(let* ((repo (expand-file-name "elpaca/" elpaca-repos-directory))
(build (expand-file-name "elpaca/" elpaca-builds-directory))
(order (cdr elpaca-order))
(default-directory repo))
(add-to-list 'load-path (if (file-exists-p build) build repo))
(unless (file-exists-p repo)
(make-directory repo t)
(when (< emacs-major-version 28) (require 'subr-x))
(condition-case-unless-debug err
(if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*"))
((zerop (call-process "git" nil buffer t "clone"
(plist-get order :repo) repo)))
((zerop (call-process "git" nil buffer t "checkout"
(or (plist-get order :ref) "--"))))
(emacs (concat invocation-directory invocation-name))
((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch"
"--eval" "(byte-recompile-directory \".\" 0 'force)")))
((require 'elpaca))
((elpaca-generate-autoloads "elpaca" repo)))
(progn (message "%s" (buffer-string)) (kill-buffer buffer))
(error "%s" (with-current-buffer buffer (buffer-string))))
((error) (warn "%s" err) (delete-directory repo 'recursive))))
(unless (require 'elpaca-autoloads nil t)
(require 'elpaca)
(elpaca-generate-autoloads "elpaca" repo)
(load "./elpaca-autoloads")))
(add-hook 'after-init-hook #'elpaca-process-queues)
(elpaca `(,@elpaca-order))
;; Install 'use-package' support
(elpaca elpaca-use-package
;; Enable :elpaca use-package keyword.
(elpaca-use-package-mode))
;; 'always-defer' means that for a package to load we need a ':hook' or using a ':general' keybinding
;; if there is none, we need to explicitly add ':demand' to load the package
;; can also load with ':defer time'
(setq use-package-verbose nil ; don't print anything
use-package-compute-statistics t ; compute statistics about package initialization
use-package-minimum-reported-time 0.0001
use-package-always-ensure t ; always ensure the package is installed, unless :ensure nil
use-package-expand-minimally t ; minimal expanded macro
use-package-always-defer t) ; always defer, don't "require", except when :demand
;; Block until current queue processed.
(elpaca-process-queues)
;; general for keybinding
(use-package general
:ensure (:wait t)
:demand t
:config
;; keybinding on 'override' keymap are not overridden by a minor-mode.
(general-override-mode))
;; control minor-mode indication in the mode-line
(use-package diminish
:ensure (:wait t)
:demand t)
;; ':general' and ':diminish' add keywords to 'use-package'
;; need to process before continue
(elpaca-process-queues)
;; minimizes GC interference with user activity
(use-package gcmh
:diminish gcmh-mode
:defer 1
:config
(setq gcmh-idle-delay 0.5
gcmh-high-cons-threshold (* 64 1024 1024))
(gcmh-mode 1))
;; basics and better default
(use-package emacs
:ensure nil
:defer 1
:general
('normal "gy" 'revert-buffer-quick)
('insert "C-v" 'yank) ; for helping in minibuffer.
("C-<tab>" 'next-window-any-frame)
("C-M-o" 'up-list)
("<backtab>" 'previous-window-any-frame)
("C-x C-M-e" 'pp-macroexpand-last-sexp)
("C-x C-e" 'eval-defun)
("C-x e" 'eval-last-sexp)
("C-h j" 'describe-keymap)
;; some sexp moving commads (treesit changes some)
('normal :prefix "z"
"u" 'backward-up-list
"b" 'backward-sexp
"f" 'forward-sexp)
:config
(setq-default fill-column 88) ; column length (88 python black default, I think is good)
(column-number-mode t) ; show column number in the mode line
(setq-default indicate-empty-lines nil) ; cleaner
(setq warning-minimum-level :error) ;avoid warning buffer
;; scroll
(setq auto-window-vscroll nil ; avoid next-line to trigger line-move-partial
mouse-wheel-scroll-amount '(1 ((shift) . 1) ((control) . nil)) ; 1 line at a time
mouse-wheel-progressive-speed nil ; proportional to scroll speed
fast-but-imprecise-scrolling t
jit-lock-defer-time nil
jit-lock-stealth-time nil
mouse-wheel-follow-mouse 't
;; scroll-conservatively 0
;; scroll-step 0
)
(setq ring-bell-function 'ignore)
;; (setq inhibit-startup-screen t) ; start at scratch buffer
(setq custom-file "~/.emacs.d/emacs-custom.el")
(load custom-file)
;; UTF-8 encoding
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; create backups in separate folder
(setq backup-directory-alist `(("." . "~/.saves")))
(setq create-lockfiles nil) ; files with # problem with onedrive...
;; ;; answering just 'y' or 'n' will do
(setopt use-short-answers t)
(setq-default
completion-cycle-threshold nil ; show all candidates
completions-detailed t ; add details in completions as prefix/sufix
enable-recursive-minibuffers t ; Enable recursive minibuffers
visible-bell t ; Don't beep at me
kill-buffer-query-functions nil) ; don't ask if it is ok to kill a process when killing a buffer
;; 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)
;; don't need to confirm to revert buffer
(setq revert-without-query t)
(setq-default
indent-tabs-mode nil ; don't insert tab when indent
;; this is giving me problems when creating new lines in org-mode source blocks
tab-always-indent 'complete ; tab indents first, then tries to complete
help-window-select t ; focus on help window when openend, then quit with `q'
window-combination-resize t) ; resize windows proportionaly
(setq yank-pop-change-selection t) ;change selection when using yank pop
;; overwrite over active region, useful when pasting to substitute text
(delete-selection-mode 1)
(blink-cursor-mode -1) ; don't blink the cursor.
;; each line on its own, otherwise use 'visual-line-mode'
(setq-default truncate-lines t)
;; narrow to region 'C-x n n' and widen with 'C-x n w'
(put 'narrow-to-region 'disabled nil))
(use-package bookmark
:ensure nil
:defer 1
:config
(setq bookmark-file "~/Sync/news/bookmarks"))
(use-package pixel-scroll
:defer 1
:ensure nil
:if (string-greaterp emacs-version "29") ; need emacs > 29
:bind
([remap evil-scroll-down] . pixel-scroll-interpolate-down)
([remap evil-scroll-page-up] . pixel-scroll-interpolate-up)
:custom
(pixel-scroll-precision-interpolate-page t)
:config
;; text scroll pixel by pixel
(pixel-scroll-precision-mode t)
;; never recenter point when scrolling, but keep in view
(setq scroll-conservatively 1000))
;; My custom emacs theme
(use-package seralk-theme :disabled
:ensure nil
:general
("<f5>"'toggle-dark-theme)
:init
(load-theme 'seralk t)
(defun toggle-dark-theme ()
(interactive)
(if (eq frame-background-mode 'dark)
(setq frame-background-mode 'light)
(setq frame-background-mode 'dark))
(invert-face 'default)))
;; Move between windows configuration
(use-package winner
:ensure nil
:defer 1
:config
(setq winner-ring-size 10)
(winner-mode))
;; Visit file from where you left
(use-package saveplace :disabled ; slow to quit emacs
:ensure nil
:defer 1
:config
(save-place-mode))
;; typeface
(use-package custom-typefaces
;; :defer 1
:ensure nil
:preface
(setq default-monospace '("Monaspace Neon"))
(setq default-unicode '("Noto Color Emoji"))
(setq default-proportional '("Iosevka Etoile"))
(setq default-comments '("Monaspace Radon"))
:custom-face
;; "Victor Mono" sometimes is nice for comments or "Recursive Mono Casual Static".
;; Monospace favorites are "JetBrains Mono NF", "MesloLGS Nerd Font Mono" and "Iosevka NF", or "Recursive Mono Linear Static".
;; Variable pitch favorites "Iosevka Etoile", "Recursive Sans Linear Static"
;; 'constant'
(default ((t (:family ,(car default-monospace)))))
(variable-pitch ((t (:family ,(car default-proportional)))))
(variable-pitch-text ((t (:inherit variable-pitch :height unspecified))))
;; comment
(font-lock-comment-face ((t (:family ,(car default-comments) :slant italic))))
(font-lock-constant-face ((t (:family ,(car default-monospace)))))
;; outline 4 inherits from comment face... make it oblique instead of italic
(outline-4 ((t (:inherit font-lock-doc-face))))
;; so summary line aligned
(gnus-summary-normal-unread ((t (:family ,(car default-monospace)))))
;; when using variable pitch in org mode, use monospace for code blocks
(org-block ((t (:family ,(car default-monospace)))))
(org-table ((t (:family ,(car default-monospace)))))
(org-meta-line ((t (:family ,(car default-monospace)))))
(org-verbatim ((t (:family ,(car default-monospace)))))
(org-code ((t (:slant italic :inherit org-verbatim :box nil))))
(tree-sitter-hl-face:comment ((t (:inherit font-lock-comment-face))))
:init
(set-fontset-font t 'unicode (car default-unicode) nil 'prepend))
;; change typeface size font
;; note: `global-text-scale-adjust' do that
(use-package emacs-frame-zoom :disabled
:ensure nil
:general
("C-M-=" 'zoom-frame)
("C-M--" 'zoom-frame-out)
:init
;; ref: https://stackoverflow.com/questions/24705984/increase-decrease-font-size-in-an-emacs-frame-not-just-buffer
;; setting typeface size
(defun zoom-frame (&optional amt frame)
"Increaze FRAME font size by amount AMT. Defaults to selected
frame if FRAME is nil, and to 1 if AMT is nil."
(interactive "p")
(let* ((frame (or frame (selected-frame)))
(font (face-attribute 'default :font frame))
(size (font-get font :size))
(amt (or amt 1))
(new-size (+ size amt))
(scale (if (boundp 'org-format-latex-options)
(plist-get org-format-latex-options :scale)
1.0))
(new-scale (* scale 1.15)))
;; change size of images on org buffers
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (string-equal major-mode "org-mode")
(org-zoom-inline-images))))
(set-frame-font (font-spec :size new-size) t t)
;; latex preview in org
(if (boundp 'org-format-latex-options)
(setq org-format-latex-options (plist-put org-format-latex-options :scale new-scale)))))
(defun zoom-frame-out (&optional amt frame)
"Call `zoom-frame' with negative argument."
(interactive "p")
(zoom-frame (- (or amt 1)) frame)
;; change size of images on org buffers
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (string-equal major-mode "org-mode")
(org-zoom-out-inline-images))))
;; latex scale to 1.1
(if (boundp 'org-format-latex-options)
(setq org-format-latex-options (plist-put org-format-latex-options :scale 1.1)))))
;; controls the behavior of windows
(use-package emacs-display-windows :disabled
:ensure nil
:init
;; reuse existing windows including other frames
(customize-set-variable
'display-buffer-base-action ; define a priorized list of actions
'((display-buffer--maybe-same-window
display-buffer-reuse-window ; reuse help buffers for instance
display-buffer--maybe-pop-up-frame-or-window ; pop up transient buffers
display-buffer-in-previous-window
;; display-buffer-same-window ; problems with magit popup
display-buffer-below-selected ; magit pop up at bottom of selected
display-buffer-at-bottom)
(reusable-frames . t)))
;; avoid resizing when a pop up window
(customize-set-variable 'even-window-sizes nil))
(use-package abbrev
:ensure nil
:config
;; abbrev for speed and less strain
(setq-default abbrev-mode t)
(diminish 'abbrev-mode)
(setq save-abbrevs 'silently))
(use-package color-identifiers-mode)
;; save recent visited files
(use-package recentf
:ensure nil
:defer 5
:config
(recentf-mode 1)
(setq recentf-max-saved-items 25
recentf-auto-cleanup 'mode))
;; Enable autorevert on specific modes
(use-package autorevert
:ensure nil
:if (eq system-type 'gnu/linux)
:hook
(text-mode . auto-revert-mode)
(dired-mode . auto-revert-mode)
:config
(setq auto-revert-interval 1
auto-revert-verbose nil
;; maybe slow
auto-revert-check-vc-info nil
;; maybe slow, but useful
auto-revert-remote-files nil))
(use-package helpful
:general
("C-h f" 'helpful-callable)
("C-h d" 'helpful-at-point)
("C-h v" 'helpful-variable)
("C-h k" 'helpful-key)
:init
(defvar read-symbol-positions-list nil) ; fix bug in upstream emacs
:config
;; don't create multiple buffers, just switch the current
(defun pop-or-switch-to-buffer (buffer-name)
(if (eq major-mode 'helpful-mode)
(switch-to-buffer buffer-name)
(pop-to-buffer buffer-name)))
(setq helpful-switch-buffer-function 'pop-or-switch-to-buffer))
;; completion UI (vertical list in minibuffer)
(use-package vertico
:ensure (vertico :type git :host github :repo "minad/vertico"
:files (:defaults "extensions/*"))
:general
('insert vertico-map "C-k" 'vertico-exit-input)
('normal vertico-map
"C-n" 'vertico-next ; same as in insert mode
"C-p" 'vertico-previous) ; same as in insert mode
:init
(vertico-mode)
(setq vertico-resize t))
;; improves behavior when dealing with directories in the minibuffer
(use-package vertico-directory
:ensure nil
:after vertico
:general
(vertico-map "RET" 'vertico-directory-enter
"DEL" 'vertico-directory-delete-char
"M-DEL" 'vertico-directory-delete-word)
;; tidy shadowed file names
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
;; repeat last vertico session
(use-package vertico-repeat
:ensure nil
:after vertico
:general
("M-r" 'vertico-repeat))
;; use vertico to complete in region with orderless in terminal
(use-package vertico-terminal :disabled
:ensure nil
:unless (display-graphic-p)
:init
;; Use `consult-completion-in-regionegion' if Vertico is enabled.
;; Otherwise use the default `completion--in-region' function.
(setq-default completion-in-region-function
(lambda (&rest args)
(apply (if vertico-mode
#'consult-completion-in-region
#'completion--in-region)
args))))
(use-package vertico-terminal-completion-window-placement-hack :disabled
:ensure nil
:unless (display-graphic-p)
:after vertico-multiform
:init
(add-to-list 'vertico-multiform-commands
'(consult-completion-in-region grid (vertico-grid-annotate . 25)))
(setf (alist-get "^\\Completions\\$"
display-buffer-alist
nil nil #'string=)
;; reuse window, otherwise open bellow
'((display-buffer-reuse-window
display-buffer-below-selected))))
;; allows different completion UI configuration
(use-package vertico-multiform
:ensure nil
:after vertico
:general
('insert vertico-map "C-<tab>" 'vertico-multiform-reverse)
;; for terminal
('insert vertico-map "M-SPC" 'vertico-multiform-reverse)
:init
(vertico-multiform-mode)
;; for spell checker
(add-to-list 'vertico-multiform-categories
'(jinx grid (vertico-grid-annotate . 25))))
;; `completion STYLE` with flexible candidate filtering
;; filter with space-separated components and match components in any order
;; filter means how a input string is matched against candidates
(use-package orderless
:demand
:config
;; partial completion for files to allows path expansion
(setq completion-styles '(orderless)
completion-category-defaults nil
completion-ignore-case t ; ignore case (useful in c++ for instance)
read-file-name-completion-ignore-case t
completion-category-overrides '((file (styles . (partial-completion)))
;; navigate files with initials
(minibuffer (initials)))))
;; default completion framework
(use-package simple
:ensure nil
;; :general
;; (minibuffer-mode-map "C-n" 'minibuffer-next-completion)
;; (minibuffer-mode-map "C-p" 'minibuffer-previous-completion)
:config
;; first TAB shows candidates
;; second TAB switches to the candidates buffer
(setq completion-auto-select 'second-tab
;; Just one column is better.
completions-format 'one-column
completions-max-height 20
completions-header-format nil))
;; save the search history
(use-package savehist
:ensure nil
:defer 1
:config
(savehist-mode))
;; minibuffer annotations details
(use-package marginalia
:if (eq system-type 'gnu/linux)
:general
(minibuffer-local-map "M-A" 'marginalia-cycle)
:defer 1
:config
(marginalia-mode))
;; enhances multiple commands based on completion
;; practical navigation and search commands
(use-package consult
:general
;; m/f/b <SPC> for bookmarks/files/buffers narrowing
("C-x b" 'consult-buffer) ; enhanced switch to buffer
("C-M-s" 'consult-line)
("M-s" 'consult-outline) ; navigation by headings
("C-c o" 'consult-imenu) ; navigation by "imenu" items
("M-y" 'consult-yank-pop) ; editing cycle through kill-ring
("C-M-s" 'consult-line) ; search lines with preview
("C-c C-f" 'consult-focus-lines) ; show only matching results
("C-c m" 'consult-mark)
;; two parts: search and filter
;; #<search string>#<filter terms> filtering with orderless! amazing!
;; command line can be specified after "--", example: #<search string> -- -C 10 for context!! WHAT!
("C-c r" 'consult-ripgrep) ; search file contents
("C-c C-r" (general-simulate-key "C-u C-c r"))
("C-c f" 'consult-find-fd) ; search files in directories
;; (minibuffer-local-completion-map "<tab>" 'minibuffer-force-complete)
("M-e" 'consult-isearch-history)
:hook
;; hook for using default completion mode
(completion-list-mode . consult-preview-at-point-mode)
:config
(consult-customize consult-buffer
consult-bookmark
consult-outline
consult-line
:preview-key '(:debounce 1 any))
;; use a key for preview from ripgrep and find
(consult-customize consult-ripgrep consult-find-fd
:preview-key '("M-."))
;; use 'fd' instead of 'find'
(defun consult-find-fd (&optional dir initial)
(interactive "P")
(let ((consult-find-command "fd --color=never --full-path ARG OPTS"))
(consult-find dir initial)))
;; set project root from vc.el
;; available when a project file is visited (project-switch-project)
(setq consult-project-root-function nil)
;; #'vc-root-dir ; using current folder as default
;; added --no-ignore-vcs to avoid skipping files in gitignore
(setq consult-ripgrep-args
"rga --null --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --line-number --no-ignore-vcs --with-filename")
;; previous consult line
(defvar my-consult-line-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-s" #'previous-history-element)
map))
(consult-customize consult-line :keymap my-consult-line-map)
(defvar my-consult-outline-map
(let ((map (make-sparse-keymap)))
(define-key map "\M-s" #'previous-history-element)
map))
(consult-customize consult-outline :keymap my-consult-outline-map)
;; narrow to org buffers
(defvar org-source
(list :name "Org"
:category 'buffer
:narrow ?o
:face 'consult-buffer
:history 'buffer-name-history
:state #'consult--buffer-state
:new
(lambda (name)
(with-current-buffer (get-buffer-create name)
(insert "#+title: " name "\n\n")
(org-mode)
(consult--buffer-action (current-buffer))))
:items
(lambda ()
(mapcar #'buffer-name
(seq-filter
(lambda (x)
(eq (buffer-local-value 'major-mode x) 'org-mode))
(buffer-list))))))
(add-to-list 'consult-buffer-sources 'org-source 'append)
;; narrow to tramp buffers
(defvar tramp-source
(list :name "Remote"
:category 'buffer
:narrow ?r
:face 'consult-buffer
:history 'buffer-name-history
:state #'consult--buffer-state
:new
(lambda (name)
(with-current-buffer (get-buffer-create name)
;;(insert "#+title: " name "\n\n")
(tramp-mode)
(consult--buffer-action (current-buffer))))
:items
(lambda ()
(mapcar #'buffer-name
(seq-filter
(lambda (x)
(file-remote-p (buffer-local-value 'default-directory x)))
(buffer-list))))))
(add-to-list 'consult-buffer-sources 'tramp-source 'append)
;; narrow to local buffers only
(defvar host-source
(list :name "Host"
:category 'buffer
:narrow ?h
:face 'consult-buffer
:history 'buffer-name-history
:state #'consult--buffer-state
:new
(lambda (name)
(with-current-buffer (get-buffer-create name)
;;(insert "#+title: " name "\n\n")
(tramp-mode)
(consult--buffer-action (current-buffer))))
:items
(lambda ()
(mapcar #'buffer-name
(seq-filter
(lambda (x)
(not (file-remote-p (buffer-local-value 'default-directory x))))
(buffer-list))))))
(add-to-list 'consult-buffer-sources 'host-source 'append)
;; narrow to dired buffers
(defvar dired-source
(list :name "Dired"
:category 'buffer
:narrow ?d
:face 'consult-buffer
:history 'buffer-name-history
:state #'consult--buffer-state
:new
(lambda (name)
(with-current-buffer (get-buffer-create name)
;;(insert "#+title: " name "\n\n")
(tramp-mode)
(consult--buffer-action (current-buffer))))
:items
(lambda ()
(mapcar #'buffer-name
(seq-filter
(lambda (x)
(eq (buffer-local-value 'major-mode x) 'dired-mode))
(buffer-list))))))
(add-to-list 'consult-buffer-sources 'dired-source 'append))
;; insert recent openend directories in prompt
(use-package consult-dir
:ensure (consult-dir :type git :host github :repo "karthink/consult-dir")
:general
("C-x C-d" 'consult-dir)
(vertico-map "C-x C-d" 'consult-dir))
;; context menu/action at point or inside the minibuffer (on the top candidate)
;; or in a region
;; `embark-collect` allows acting on a `set of targets` (snapshot or live)
;; `live` works like a completion narrowing that Vertico does
;; `export` the set of targets are shown in an appropriate major-mode
;; embark-mixed-indicator: if no action is selected, buffer will pop up
(use-package embark
:ensure (embark :files (:defaults "embark-org.el"))
;; :demand ; load it independently of bind and hook
:general
('(insert visual normal) "C-z" 'embark-act) ; use "\" for "evil-execute-in-emacs-state"
('(insert motion) minibuffer-local-map "C-z" 'embark-act) ; use "\" for "evil-execute-in-emacs-state"
("C-S-z" 'embark-dwim)
("C-h B" 'embark-bindings)
(embark-function-map "h" 'helpful-symbol)
(embark-variable-map "h" 'helpful-symbol)
('normal grep-mode-map "g r" 'embark-rerun-collect-or-export) ; back to completion after 'embark-export' to grep buffer
:commands embark-prefix-help-command
:config
(add-to-list 'display-buffer-alist
;; hide the mode line of the Embark live/completions buffers
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none))))
(add-to-list 'display-buffer-alist
;; show export in the side
'("\\*Embark Export: .*"
(display-buffer-in-side-window)))
;; change 'describe-symbol' to 'helpful-symbol'
(add-to-list 'embark-default-action-overrides '(describe-symbol . helpful-symbol)))
;; allows consult previews as you move around an auto-updating embark collect
;; buffer
;; `exbark-collects` grep results to a grep buffer
(use-package embark-consult
:demand ;necessary for consult preview
:hook (embark-collect-mode . consult-preview-at-point-mode)
:after (embark consult))
;; targets for org mode
(use-package embark-org
:ensure nil
:after embark
:demand)
;; utility for using icons fonts
(use-package all-the-icons :disabled
:custom
(all-the-icons-scale-factor 1))
(use-package nerd-icons
:ensure (nerd-icons :host github :repo "rainstormstudio/nerd-icons.el"
:files (:defaults "data"))
:defer 1
:demand ;require
:custom
;; need to install the nerd-font
;; For kitty terminal need to add family to kitty config (C-S-<f2>)
(nerd-icons-font-family "Symbols Nerd Font Mono")
:config
;; to use with corfu and kind-icon
(setq kind-icon-use-icons nil)
(setq kind-icon-mapping
`(
(array ,(nerd-icons-codicon "nf-cod-symbol_array") :face font-lock-type-face)
(boolean ,(nerd-icons-codicon "nf-cod-symbol_boolean") :face font-lock-builtin-face)
(class ,(nerd-icons-codicon "nf-cod-symbol_class") :face font-lock-type-face)
(color ,(nerd-icons-codicon "nf-cod-symbol_color") :face success)
(command ,(nerd-icons-codicon "nf-cod-terminal") :face default)
(constant ,(nerd-icons-codicon "nf-cod-symbol_constant") :face font-lock-constant-face)
(constructor ,(nerd-icons-codicon "nf-cod-triangle_right") :face font-lock-function-name-face)
(enummember ,(nerd-icons-codicon "nf-cod-symbol_enum_member") :face font-lock-builtin-face)
(enum-member ,(nerd-icons-codicon "nf-cod-symbol_enum_member") :face font-lock-builtin-face)
(enum ,(nerd-icons-codicon "nf-cod-symbol_enum") :face font-lock-builtin-face)
(event ,(nerd-icons-codicon "nf-cod-symbol_event") :face font-lock-warning-face)
(field ,(nerd-icons-codicon "nf-cod-symbol_field") :face font-lock-variable-name-face)
(file ,(nerd-icons-codicon "nf-cod-symbol_file") :face font-lock-string-face)
(folder ,(nerd-icons-codicon "nf-cod-folder") :face font-lock-doc-face)
(interface ,(nerd-icons-codicon "nf-cod-symbol_interface") :face font-lock-type-face)
(keyword ,(nerd-icons-codicon "nf-cod-symbol_keyword") :face font-lock-keyword-face)
(macro ,(nerd-icons-codicon "nf-cod-symbol_misc") :face font-lock-keyword-face)
(magic ,(nerd-icons-codicon "nf-cod-wand") :face font-lock-builtin-face)
(method ,(nerd-icons-codicon "nf-cod-symbol_method") :face font-lock-function-name-face)
(function ,(nerd-icons-codicon "nf-cod-symbol_method") :face font-lock-function-name-face)
(module ,(nerd-icons-codicon "nf-cod-file_submodule") :face font-lock-preprocessor-face)
(numeric ,(nerd-icons-codicon "nf-cod-symbol_numeric") :face font-lock-builtin-face)
(operator ,(nerd-icons-codicon "nf-cod-symbol_operator") :face font-lock-comment-delimiter-face)
(param ,(nerd-icons-codicon "nf-cod-symbol_parameter") :face default)
(property ,(nerd-icons-codicon "nf-cod-symbol_property") :face font-lock-variable-name-face)
(reference ,(nerd-icons-codicon "nf-cod-references") :face font-lock-variable-name-face)
(snippet ,(nerd-icons-codicon "nf-cod-symbol_snippet") :face font-lock-string-face)
(string ,(nerd-icons-codicon "nf-cod-symbol_string") :face font-lock-string-face)
(struct ,(nerd-icons-codicon "nf-cod-symbol_structure") :face font-lock-variable-name-face)
(text ,(nerd-icons-codicon "nf-cod-text_size") :face font-lock-doc-face)
(typeparameter ,(nerd-icons-codicon "nf-cod-list_unordered") :face font-lock-type-face)
(type-parameter ,(nerd-icons-codicon "nf-cod-list_unordered") :face font-lock-type-face)
(unit ,(nerd-icons-codicon "nf-cod-symbol_ruler") :face font-lock-constant-face)
(value ,(nerd-icons-codicon "nf-cod-symbol_field") :face font-lock-builtin-face)
(variable ,(nerd-icons-codicon "nf-cod-symbol_variable") :face font-lock-variable-name-face)
(t ,(nerd-icons-codicon "nf-cod-code") :face font-lock-warning-face))))
(use-package nerd-icons-dired
:ensure (nerd-icons-dired :type git :host github :repo "rainstormstudio/nerd-icons-dired")
:hook
(dired-mode . nerd-icons-dired-mode))
(use-package nerd-icons-completion
:ensure (nerd-icons-completion :type git :host github :repo "rainstormstudio/nerd-icons-completion")
;; need to load after marginalia
;; https://github.com/rainstormstudio/nerd-icons-completion/issues/4
:after (nerd-icons marginalia)
:init
(nerd-icons-completion-mode))
;; automatic insert matching pairs and navigation
;; highlight matching parens
;; for wrap/unwrap I use evil-surround
;; expand/contract (slurp) is good for elisp
(use-package smartparens
:diminish smartparens-mode
;; :ensure (:includes smartparens-config)
:general
('normal smartparens-mode-map "M-l" 'sp-next-sexp)
('normal smartparens-mode-map "M-h" 'sp-previous-sexp)
('normal smartparens-mode-map "M-k" 'sp-up-sexp)
('normal smartparens-mode-map "M-j" 'sp-down-sexp)
('(normal visual) smartparens-mode-map "] ]" 'sp-forward-sexp) ; go to balancing closing pair
('(normal visual) smartparens-mode-map "[ [" 'sp-beginning-of-sexp) ; go back to matching opening pair
;; binding all modes for Latex
('insert '(prog-mode-map LaTeX-mode-map org-mode-map) "C-<tab>" 'sp-forward-sexp)
:custom-face
(sp-show-pair-match-content-face ((t (:inherit show-paren-match))))
:hook
(prog-mode . smartparens-mode)
(LaTeX-mode . smartparens-mode)
(nxml-mode . smartparens-mode)
;; (org-mode . smartparens-mode) ; messing with org-mode
;; (smartparens-mode . smartparens-strict-mode) ; enforce pairs to be balanced
(smartparens-mode . show-smartparens-mode) ; instead of default show-paren-mode
:config
(setq sp-show-pair-delay 0.125
sp-max-prefix-length 25 ; reduces work
sp-max-pair-length 4 ; reduces work
)
;; show context (echo area) when closing delimiter is off screen
(setq show-paren-context-when-offscreen 'overlay))
(use-package hack-sp-face-in-org
:ensure nil
:after org
:init
(defun change-sp-face-when-in-org ()
"remove background to avoid annoying color when drawing with edraw in
org-mode"
(face-remap-add-relative 'show-paren-match '(:background 'unspecified)))
(add-hook 'org-mode-hook #'change-sp-face-when-in-org))
(use-package smartparens-config
:ensure nil
:demand
:after smartparens
:config
(sp-local-pair 'org-mode "$" "$" :unless '(sp-point-after-word-p)))
(use-package flymake
:hook
(prog-mode . flymake-mode)
:general
(flymake-mode-map "M-n" 'flymake-goto-next-error)
(flymake-mode-map "M-N" 'flymake-goto-prev-error)
:config
;; delay check, check only on save
(setq flymake-no-changes-timeout 1 ;only when saved
flymake-show-diagnostics-at-end-of-line nil ; just use "M-n"
flymake-mode-line-lighter "Fly")
;; avoid warning in the 'flymake' log
;; (remove-hook 'flymake-diagnostic-functions 'flymake-proc-legacy-flymake)
)
;; 'flymake' just for C++ in org edit special
;; https://www.gnu.org/software/emacs/manual/html_node/flymake/Example_002d_002d_002dConfiguring-a-tool-called-directly.html
(use-package flymake-cpp-hack :disabled ;not working with org edit special
:ensure nil
:after flymake
:init
(defun flymake-cc-init ()
(let* (;; Create temp file which is copy of current file
(temp-file (flymake-proc-init-create-temp-buffer-copy
'flymake-proc-create-temp-inplace))
;; Get relative path of temp file from current directory
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
;; Construct compile command which is defined list.
;; First element is program name, "g++" in this case.
;; Second element is list of options.
;; So this means "g++ -Wall -Wextra -fsyntax-only tempfile-path"
(list "g++" (list "-Wall" "-Wextra" "-fsyntax-only" local-file))))
(defun flymake-in-org-edit-special (&optional ARG PRED)
(when (eq major-mode 'c++-mode)
(flymake-mode)
;; Enable above flymake setting for C++ files(suffix is '.cpp')
(add-to-list 'flymake-proc-allowed-file-name-masks
'("\\.cpp$" flymake-cc-init))))
(add-hook 'org-src-mode-hook 'flymake-in-org-edit-special))
(use-package meow
:defer 1
:demand
:config
(defun meow-setup ()
(setq meow-cheatsheet-layout meow-cheatsheet-layout-qwerty)
(meow-motion-overwrite-define-key
'("j" . meow-next)
'("k" . meow-prev)
'("<escape>" . ignore))
(meow-leader-define-key
;; SPC j/k will run the original command in MOTION state.
'("j" . "H-j")
'("k" . "H-k")
;; Use SPC (0-9) for digit arguments.
'("1" . meow-digit-argument)
'("2" . meow-digit-argument)
'("3" . meow-digit-argument)
'("4" . meow-digit-argument)
'("5" . meow-digit-argument)
'("6" . meow-digit-argument)
'("7" . meow-digit-argument)
'("8" . meow-digit-argument)
'("9" . meow-digit-argument)
'("0" . meow-digit-argument)
'("/" . meow-keypad-describe-key)
'("?" . meow-cheatsheet))
(meow-normal-define-key
'("0" . meow-expand-0)
'("9" . meow-expand-9)
'("8" . meow-expand-8)
'("7" . meow-expand-7)
'("6" . meow-expand-6)
'("5" . meow-expand-5)
'("4" . meow-expand-4)
'("3" . meow-expand-3)
'("2" . meow-expand-2)
'("1" . meow-expand-1)
'("-" . negative-argument)
'(";" . meow-reverse)
'("," . meow-inner-of-thing)
'("." . meow-bounds-of-thing)
'("[" . meow-beginning-of-thing)
'("]" . meow-end-of-thing)
'("a" . meow-append)
'("A" . meow-open-below)
'("b" . meow-back-word)
'("B" . meow-back-symbol)
'("c" . meow-change)
'("d" . meow-delete)
'("D" . meow-backward-delete)
'("e" . meow-next-word)
'("E" . meow-next-symbol)
'("f" . meow-find)
'("g" . meow-cancel-selection)
'("G" . meow-grab)
'("h" . meow-left)
'("H" . meow-left-expand)
'("i" . meow-insert)
'("I" . meow-open-above)
'("j" . meow-next)
'("J" . meow-next-expand)
'("k" . meow-prev)
'("K" . meow-prev-expand)
'("l" . meow-right)
'("L" . meow-right-expand)
'("m" . meow-join)
'("n" . meow-search)
'("o" . meow-block)
'("O" . meow-to-block)
'("p" . meow-yank)
'("q" . meow-quit)
'("Q" . meow-goto-line)
'("r" . meow-replace)
'("R" . meow-swap-grab)
'("s" . meow-kill)
'("t" . meow-till)
'("u" . meow-undo)
'("U" . meow-undo-in-selection)
'("v" . meow-visit)
'("w" . meow-mark-word)
'("W" . meow-mark-symbol)
'("x" . meow-line)
'("X" . meow-goto-line)
'("y" . meow-save)
'("Y" . meow-sync-grab)
'("z" . meow-pop-selection)
'("'" . repeat)
'("<escape>" . ignore)))
(meow-setup)
(meow-global-mode)
)
;; For some reason is not working with edits in 'dired'
(use-package evil-multiedit :disabled :disabled
:after evil
:custom-face
(iedit-occurrence ((t (:box (:line-width (-1 . -1)) :inherit nil :style nil))))
:general
("C-;" 'iedit-mode)
('visual "R" 'evil-multiedit-match-all)
("M-d" 'evil-multiedit-match-and-next)
("M-C-d" 'evil-multiedit-match-and-prev)
('(normal visual) evil-multiedit-mode-map "M-t" 'evil-multiedit-toggle-or-restrict-region)
('normal evil-multiedit-mode-map "<escape>" 'evil-multiedit-abort)
('visual "C-S-d" 'evil-multiedit-restore)
('insert evil-multiedit-mode-map "<RET>" nil) ; avoid toggling when completing with corfu
('normal "M-p" nil) ; use to change dictionaries in 'go-translate' package
:config
(setq evil-multiedit-follow-matches t)
(defun make-evil-multiedit-case-sensitive (fn &rest args)
(let ((case-fold-search (not iedit-case-sensitive)))
(apply fn args)))
(advice-add #'evil-multiedit-match-and-next :around #'make-evil-multiedit-case-sensitive)
;; Change the face for terminal
(when (not (display-graphic-p))
(set-face-attribute 'iedit-occurrence nil :inherit 'isearch)))
;; Show-hide selected with 'C-\'' after 'iedit-mode'
;; with prefix "C-u 1", selects just first occurrence, to add more use "M-n" 'iedit-expand-down-to-occurrence'
(use-package iedit
:custom-face
(iedit-occurrence ((t (:box (:line-width (-1 . -1)) :inherit nil))))
:general
("C-;" 'iedit-mode)
('(normal visual) ":" 'iedit-mode) ; for tty, I don't use `evil-ex'
(iedit-mode-keymap "M-'" 'iedit-show/hide-context-lines) ; for tty
("M-d" 'my-iedit-expand-down-to-occurrence)
('normal iedit-mode-occurrence-keymap "<escape>" 'iedit--quit)
(iedit-mode-keymap "C-h k" 'nil) ; use 'helpful'
(iedit-mode-keymap "C-n" 'iedit-next-occurrence)
(iedit-mode-keymap "C-p" 'iedit-prev-occurrence)
(iedit-lib-keymap "TAB" nil)
:init