-
Notifications
You must be signed in to change notification settings - Fork 4
/
.emacs
3370 lines (2920 loc) · 105 KB
/
.emacs
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
;;; .emacs --- Emacs init file -*- lexical-binding: t; -*-
;;; Commentary:
;;; Emacs init file
;;;
;;; Code:
;;; Speed up init.
;;; Temporarily reduce garbage collection during startup. Inspect `gcs-done'.
;; https://gitlab.com/ambrevar/dotfiles/blob/master/.emacs.d/init.el
(setq gc-cons-threshold (* 64 1024 1024)
gc-cons-percentage 0.6)
(defun ambrevar/reset-gc-cons-threshold ()
(setq gc-cons-threshold
(car (get 'gc-cons-threshold 'standard-value))
gc-cons-percentage 0.1))
(add-hook 'after-init-hook #'ambrevar/reset-gc-cons-threshold)
;;; Temporarily disable the file name handler.
(setq default-file-name-handler-alist file-name-handler-alist
setqfile-name-handler-alist nil)
(defun ambrevar/reset-file-name-handler-alist ()
(setq file-name-handler-alist
(append default-file-name-handler-alist
file-name-handler-alist))
(cl-delete-duplicates file-name-handler-alist :test 'equal))
(add-hook 'after-init-hook #'ambrevar/reset-file-name-handler-alist)
(setq load-prefer-newer t)
(defun kd/emacs-subdirectory (d)
"Make dir path inside Emacs user dir for D."
(expand-file-name d user-emacs-directory))
(defvar kd/cache-dir "~/.cache/emacs")
(unless (file-directory-p kd/cache-dir)
(mkdir kd/cache-dir))
(defun kd/emacs-cache-dir (f &optional dirp)
(let ((dir (expand-file-name f kd/cache-dir)))
(unless (and dirp (file-exists-p dir))
(mkdir dir))
dir))
(defvar kd/ghq-dir "~/.ghq")
(defun kd/ghq-repo-path (domain repo)
"Return a path of repo managed by ghq.
DOMAIN is like: `github.com'
REPO's pattern: `<user>/<repo>'."
(expand-file-name (concat domain "/" repo) kd/ghq-dir))
(defun kd/ghq-github-repo-path (repo)
"Return a path of github repo mamaged by ghq.
REPO's pattern: `<user>/<repo>'"
(expand-file-name (kd/ghq-repo-path "github.com" repo)))
(defconst kd/default-local-proxy "127.0.0.1:7890")
(defun kd/turn-on-http-proxy (force &optional proxy)
"Turn on http PROXY. FORCE to turn on even no proxy process detected."
(interactive "P")
;; Tor / Proxy: set up before package initialization.
(when (or (member "ClashX Pro"
(mapcar (lambda (p) (alist-get 'comm (process-attributes p)))
(list-system-processes)))
(eq force '(4)))
(require 'url)
(unless url-proxy-services
(unless proxy
(setq proxy kd/default-local-proxy))
(setq url-proxy-services
`(("no_proxy" . "^\\(localhost\\|10.*\\)")
("http" . ,proxy)
("https" . ,proxy)))
(message "Proxy turned on: %s" proxy))))
(add-to-list 'load-path (kd/emacs-subdirectory "elisp"))
(setq source-directory (kd/ghq-github-repo-path "emacs-mirror/emacs"))
;;; Package
;;; https://emacs.stackexchange.com/questions/51721/failed-to-download-gnu-archive
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(with-eval-after-load 'package
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")
("org" . "https://orgmode.org/elpa/"))))
(require 'package)
;; (call-interactively 'kd/turn-on-http-proxy)
(package-initialize)
(defun kd/install-pkgs (pkgs)
(let ((refreshed nil))
(dolist (pkg pkgs)
(unless (package-installed-p pkg)
(unless refreshed
(package-refresh-contents)
(setq refreshed t))
(package-install pkg)))))
;;;; auto-compile
(kd/install-pkgs '(auto-compile))
(require 'auto-compile)
(auto-compile-on-save-mode 1)
(auto-compile-on-load-mode 1)
;;;; use-package
(kd/install-pkgs '(bind-key
diminish
use-package))
(with-eval-after-load 'use-package
(progn
(customize-set-variable 'use-package-enable-imenu-support t)
(setq use-package-compute-statistics t)
(setq use-package-verbose t)))
(eval-when-compile
(require 'use-package))
(use-package bind-key)
(use-package diminish)
(use-package quelpa
:ensure t
:defer t
:config
(setq quelpa-melpa-recipe-stores '("~/.ghq/github.com/melpa/melpa/recipes"))
(setq quelpa-update-melpa-p nil)
(setq quelpa-melpa-dir "~/.ghq/github.com/melpa/melpa"))
(use-package quelpa-use-package
:ensure t)
(use-package use-package-chords
:ensure t
:config (key-chord-mode 1))
(use-package use-package-ensure-system-package
:ensure t)
(use-package auto-package-update
:ensure t
:commands (auto-package-update-now kd/update-git-packages)
:config (setq auto-package-update-delete-old-versions nil))
(use-package paradox
:ensure t
:config
(setq paradox-column-width-package 27)
(setq paradox-column-width-version 13)
(setq paradox-execute-asynchronously t)
(setq paradox-hide-wiki-packages t)
(paradox-enable)
(remove-hook 'paradox-after-execute-functions #'paradox--report-buffer-print))
;; (use-package rx
;; :load-path "~/.emacs.d/quelpa/build/rx"
;; :quelpa (rx :fetcher url :url "https://raw.githubusercontent.com/emacs-mirror/emacs/dbffbe08815644fd30404891ef81496277ed27da/lisp/emacs-lisp/rx.el"))
;;; Defaults
(use-package kd-defaults
:no-require t
:config
(use-package better-defaults
:ensure t)
(setenv "LC_ALL" "en_US.UTF-8")
(setenv "LC_CTYPE" "en_US.UTF-8")
(setenv "LANG" "en_US.UTF-8")
(setq current-language-environment "en_US.UTF-8")
(setq confirm-kill-emacs 'y-or-n-p)
(setq scroll-conservatively 10000)
(setq scroll-preserve-screen-position t)
(setq vc-follow-symlinks t)
(setq custom-file "/dev/null")
(setq history-length 200)
;;;; Tabs
(setq-default tab-width 4)
(setq indent-tabs-mode nil)
(setq buffer-file-coding-system 'utf-8)
(setq prefer-coding-system 'utf-8)
(fset 'yes-or-no-p 'y-or-n-p)
(unless noninteractive
(advice-add #'display-startup-echo-area-message :override #'ignore)
(setq inhibit-startup-message t
initial-major-mode 'fundamental-mode
initial-scratch-message nil
ring-bell-function 'ignore))
(use-package warnings
:config (setq warning-minimum-level :error)))
;;; Keybinding
(use-package kd-keybinding
:no-require t
:demand t
:preface
(defun kd/make-prefix-command (key command)
"Bind KEY for a prefix COMMAND."
(define-prefix-command command)
(global-set-key key command))
(defvar kd/org-map nil)
(kd/make-prefix-command (kbd "s-r") 'kd/org-map)
(defvar kd/compile-map nil)
(kd/make-prefix-command (kbd "s-c") 'kd/compile-map)
(defvar kd/errors-map nil)
(kd/make-prefix-command (kbd "s-e") 'kd/errors-map)
(defvar kd/eshell-map nil)
(kd/make-prefix-command (kbd "s-s") 'kd/eshell-map)
(defvar kd/tags-map nil)
(kd/make-prefix-command (kbd "s-T") 'kd/tags-map)
(defvar kd/testing-map nil)
(kd/make-prefix-command (kbd "s-l") 'kd/testing-map)
(defun kd/switch-to-previous-buffer ()
"Switch to previously open buffer.
Repeated invocations toggle between the two most recently open buffers."
(interactive)
(switch-to-buffer (other-buffer (current-buffer) 1)))
(defun kd/kill-buffer-no-select ()
(interactive)
(kill-buffer nil))
:defines (kd/org-map
kd/compile-map
kd/errors-map
kd/eshell-map)
:commands kd/switch-to-previous-buffer
:functions kd/make-prefix-command
:chords ("JJ" . kd/switch-to-previous-buffer)
:config (global-set-key (kbd "C-x K") #'kd/kill-buffer-no-select))
;;; Startup
;;;; envvar
(use-package exec-path-from-shell
:ensure t
:config
(setq exec-path-from-shell-check-startup-files nil)
(setq exec-path-from-shell-shell-name (executable-find "zsh"))
(setq exec-path-from-shell-variables '("PATH" "MANPATH" "GOPATH" "JAVA_HOME"))
(exec-path-from-shell-initialize))
;;;; daemon
(use-package server
:defer 1
:config
(defun kd/server-start ()
(unless (server-running-p)
(server-start)))
(add-hook 'after-init-hook #'kd/server-start))
(use-package desktop
:commands (desktop-save desktop-save-in-desktop-dir desktop-read)
:init
(let ((desktop-dir (list (kd/emacs-cache-dir "desktop" t))))
(setq desktop-dirname desktop-dir)
(setq desktop-path desktop-dir)))
;;; User Interface (UI)
(use-package kd-UI
:no-require t
:config
(menu-bar-mode 1)
(column-number-mode 1)
(defun kd/suppress-messages (old-fun &rest args)
(cl-flet ((silence (&rest args1) (ignore)))
(advice-add 'message :around #'silence)
(unwind-protect
(apply old-fun args)
(advice-remove 'message #'silence))))
(use-package face-remap
:commands (buffer-face-mode
text-scale-mode
face-remap-add-relative))
(use-package simple
:diminish visual-line-mode
:commands (global-visual-line-mode turn-on-visual-line-mode)
:init (add-hook 'after-init-hook #'global-visual-line-mode)
:config
(setq set-mark-command-repeat-pop t)
(setq next-error-recenter '(4))
(advice-add 'toggle-truncate-lines :around #'kd/suppress-messages))
(use-package shackle
:ensure t
:init (add-hook 'after-init-hook #'shackle-mode)
:config
(setq shackle-lighter "")
(setq shackle-select-reused-windows nil)
(setq shackle-default-alignment 'below)
(setq shackle-default-size 0.45)
;; https://github.com/kaushalmodi/.emacs.d/blob/master/setup-files/setup-shackle.el
(setq shackle-rules
;; CONDITION(:regexp) :select :inhibit-window-quit :size+:align|:other :same|:popup
'(("*osx-dictionary*" :select t :align below :popup t)
("*info*" :select t :align right :popup t)
("*Help*" :select t :align right :popup t)
("\\`\\*[hH]elm.*?\\*\\'" :regexp t :size 0.35 :align 'below)
(helpful-mode :select t :align right :popup t)
(magit-status-mode :select t :size 0.5 :align right :popup t)
(magit-log-mode :select t :size 0.4 :align right :popup t)
("*Flycheck errors*" :select t :size 0.2 :align below :popup t))))
(use-package all-the-icons
:config
(setq all-the-icons-color-icons nil))
(use-package doom-modeline
:ensure t
:preface
(defun kd/setup-custom-doom-modeline ()
(doom-modeline-set-modeline 'kd/doom-modeline-format 'default))
:hook ((after-init . doom-modeline-mode)
(doom-modeline-mode . kd/setup-custom-doom-modeline))
:config
(doom-modeline-def-modeline 'kd/doom-modeline-format
'(bar persp-name workspace-name checker window-number modals matches buffer-info remote-host buffer-position vcs selection-info)
'(misc-info debug lsp minor-modes indent-info buffer-encoding major-mode process))
(setq doom-modeline-height 25)
(setq doom-modeline-buffer-file-name-style 'buffer-name)
(setq doom-modeline-icon nil)
(setq doom-modeline-minor-modes nil)
(setq doom-modeline-persp-name t)
(set-face-attribute 'doom-modeline-persp-name nil
:inherit '(mode-line-emphasis italic))
(set-face-attribute 'doom-modeline-persp-buffer-not-in-persp nil
:inherit '(mode-line-emphasis bold italic))))
(use-package writeroom-mode
:ensure t
:commands writeroom-mode
:config
(setq writeroom-mode-line-toggle-position 'mode-line-format)
(setq writeroom-mode-line t)
(setq writeroom-restore-window-config t)
(setq writeroom-fullscreen-effect 'maximized)
(setq writeroom-global-effects '(writeroom-set-fullscreen
writeroom-set-bottom-divider-width)))
;;;; Graphic
(defconst IS-GUI (display-graphic-p))
(use-package kd-GUI
:no-require t
:if IS-GUI
:config
(horizontal-scroll-bar-mode -1)
(scroll-bar-mode -1)
;;;;; Mouse
(setq mouse-wheel-scroll-amount '(3 ((shift) . 1)))
(setq mouse-wheel-progressive-speed nil)
(setq mouse-wheel-follow-mouse 't)
;;;;; Font
(set-frame-font (font-spec :family "Input Mono Narrow"
:size 17
:weight 'regular)
nil
t)
;;;;; Frame
(setq default-frame-alist '((fullscreen . fit-frame-to-buffer-sizes)
(font . "Input Mono Narrow-17:regular")
(vertical-scroll-bars . nil)
(horizontal-scroll-bars . nil)))
(setq frame-title-format '(buffer-file-name "%f" ("%b")))
(setq initial-frame-alist '((fullscreen . maximized)))
;;;;; Theme
(use-package default-black-theme
:disabled t
:config
(load-theme 'default-black t))
(use-package nord-theme
:disabled t
:ensure t
:config
(setq nord-region-highlight "frost")
(load-theme 'nord t))
(use-package cyberpunk-theme
:disabled t
:ensure t
:config
(load-theme 'cyberpunk t)
(custom-theme-set-faces
'cyberpunk
'(highlight-symbol-face
((t (:foreground "#d3d3d3" :background "dark magenta"))) t)
'(go-guru-hl-identifier-face
((t (:foreground "#d3d3d3" :background "dark magenta"))) t)))
(use-package zenburn-theme
:disabled t
:ensure t
:config
(load-theme 'zenburn t))
(use-package hc-zenburn-theme
;; :disabled t
:ensure t
:config
(load-theme 'hc-zenburn t))
(use-package color-theme-sanityinc-tomorrow
:disabled t
:ensure t
:config
(load-theme 'sanityinc-tomorrow-night t))
(use-package prez-theme
:disabled t
:config
(load-theme 'prez t))
(use-package doom-themes
:disabled t
:ensure t
:config
(setq doom-themes-padded-modeline t)
(setq doom-opera-brighter-comments nil)
(setq doom-opera-brighter-modeline nil)
(setq doom-opera-comment-bg nil)
(setq doom-opera-padded-modeline 1)
(load-theme 'doom-opera t)
(doom-themes-org-config)
;; (custom-theme-set-faces
;; 'doom-opera
;; `(region
;; ((t (:background ,(doom-lighten (doom-color 'base4) 0.1))) t))
;; `(ivy-current-match
;; ((t (:background ,(doom-lighten (doom-color 'base4) 0.1) :underline t)) t)))
)
(use-package tron-legacy-theme
:disabled t
:quelpa (tron-legacy-theme :fetcher github :repo "ianpan870102/tron-legacy-emacs-theme")
:config
;; (add-to-list 'custom-theme-load-path
;; "/Users/kane/.emacs.d/elpa/tron-legacy-theme-20200521.1649"
;; )
(load-theme 'tron-legacy t))
(tool-bar-mode -1)
(tooltip-mode -1))
;;;; macOS
(defconst IS-MAC (memq window-system '(mac ns)))
(use-package kd-macOS
:if IS-MAC
:no-require t
:demand t
:preface
(defun kd/start-screen-saver ()
(interactive)
(osx-lib-run-osascript "do shell script \"
if [ -e /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app ]; then
open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app
else
open -a ScreenSaverEngine
fi
\""))
:config
(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'super)
(use-package osx-lib
:commands osx-lib-run-osascript
:ensure t)
(use-package osx-dictionary
:ensure t
:functions kd/osx-dictionary-mode-hook-func
:bind ("C-c f" . osx-dictionary-search-pointer)
:init
(when IS-GUI
(defun kd/osx-dictionary-mode-hook-func ()
(setq buffer-face-mode-face '(:family "Verdana" :height 190))
(buffer-face-mode 1))
(add-hook 'osx-dictionary-mode-hook #'kd/osx-dictionary-mode-hook-func))))
;;;; macOS GUI
(use-package kd-macOS-GUI
:if (and IS-MAC IS-GUI)
:demand t
:no-require t
:config
;;;;; Frame
(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
(add-to-list 'default-frame-alist '(ns-appearance . dark))
(when (fboundp 'mac-set-frame-tab-group-property)
(mac-set-frame-tab-group-property nil :tab-bar-visible-p nil))
(setq mac-frame-tabbing nil)
;;;;; Unicode font
;; Useful for https://github.com/dunn/company-emoji
;; https://www.reddit.com/r/emacs/comments/8ph0hq/i_have_converted_from_the_mac_port_to_the_ns_port/
;; not tested with emacs26 (requires a patched Emacs version for multi-color font support)
(if (version< "27.0" emacs-version)
(set-fontset-font
"fontset-default" 'unicode "Apple Color Emoji" nil 'prepend)
(set-fontset-font
t 'symbol (font-spec :family "Apple Color Emoji") nil 'prepend))
(setq mac-mouse-wheel-smooth-scroll nil))
;;; ---
(use-package savehist
:hook (after-init . savehist-mode)
:config
(setq history-delete-duplicates t)
(setq history-length t)
(setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
(setq savehist-file (expand-file-name "history" kd/cache-dir))
(setq savehist-save-minibuffer-history t)
(savehist-mode 1))
(use-package recentf
:hook (after-init . recentf-mode)
:config
(setq recentf-exclude (list "COMMIT_EDITMSG"
"~$"
"/scp:"
"/ssh:"
"/sudo:"
"/tmp/"))
(setq recentf-max-menu-items 15)
(setq recentf-max-saved-items 200)
(setq recentf-save-file (expand-file-name "recentf" kd/cache-dir)))
(use-package whitespace
:diminish whitespace-mode
:commands whitespace-mode
:config
(setq whitespace-line-column nil)
(setq whitespace-display-mappings '((space-mark 32 [183] [46])
(newline-mark 10 [9166 10])
(tab-mark 9 [9654 9] [92 9]))))
(use-package fill
:diminish auto-fill-mode
:commands auto-fill-mode)
(use-package visual-fill-column
:ensure t
:commands visual-fill-column-mode)
(use-package which-func
:commands which-function-mode
:config (add-to-list 'which-func-non-auto-modes 'nxml-mode))
(use-package which-key
:ensure t
:diminish which-key-mode
:init (add-hook 'after-init-hook #'which-key-mode))
(use-package wgrep
:ensure t
:commands wgrep-change-to-wgrep-mode
:config (setq wgrep-auto-save-buffer t))
(use-package autoinsert
:demand t
:commands auto-insert-mode
:functions define-auto-insert
:init (add-hook 'after-init-hook #'auto-insert-mode)
:config (setq auto-insert-query nil))
(use-package highlight-symbol
:ensure t
:commands highlight-symbol-mode
:diminish highlight-symbol-mode
:config (set-face-attribute 'highlight-symbol-face nil :background "gray40"))
(use-package aggressive-indent
:ensure t
:diminish aggressive-indent-mode
:commands aggressive-indent-mode
:config
(add-to-list
'aggressive-indent-dont-indent-if
'(and (derived-mode-p 'c-mode)
(null (string-match "\\([;{}]\\|\\b\\(if\\|for\\|while\\)\\b\\)"
(thing-at-point 'line))))))
(use-package avy
:ensure t
:commands (avy-goto-char-timer avy-goto-line)
:chords
("jl" . avy-goto-line)
("jc" . avy-goto-char-timer))
(use-package ace-window
:ensure t
:chords ("jw" . ace-window))
(use-package ace-isearch
:disabled t
:ensure t
:bind (:map isearch-mode-map
("C-'" . ace-isearch-jump-during-isearch))
:hook (after-init . global-ace-isearch-mode)
:config
(setq ace-isearch-function-from-isearch #'swiper-from-isearch)
(setq ace-isearch-jump-delay 0.5))
(use-package amx
:ensure t
:hook (after-init . amx-mode)
:config
(setq amx-save-file (expand-file-name "amx-items" kd/cache-dir)))
(use-package scratch
:ensure t
:preface
(defun kd/scratch-create-buffer-hook-func ()
(emacs-lock-mode 'kill))
:commands scratch
:hook (scratch-create-buffer . kd/scratch-create-buffer-hook-func))
(use-package so-long
:commands global-so-long-mode
:hook (after-init . global-so-long-mode))
(use-package multiple-cursors
:ensure t
:config
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines))
;;; Window
(use-package window
:bind (("C-x =" . balance-windows)))
(use-package windmove
:bind (("C-s-h" . windmove-left)
("C-s-j" . windmove-down)
("C-s-k" . windmove-up)
("C-s-l" . windmove-right)
("<C-s-268632072>" . windmove-left)
("<C-s-268632074>" . windmove-down)
("<C-s-268632075>" . windmove-up)
("<C-s-268632076>" . windmove-right)))
(use-package winner
:commands winner-mode
:init (add-hook 'after-init-hook #'winner-mode)
:config (setq winner-dont-bind-my-keys t))
(use-package zygospore
:ensure t
:bind ("C-x 1" . zygospore-toggle-delete-other-windows))
(use-package eyebrowse
:ensure t
:demand t
:bind (("C-c C--" . eyebrowse-next-window-config)
("C-c C-=" . eyebrowse-prev-window-config)
("s-w" . eyebrowse-close-window-config)
("s-'" . eyebrowse-last-window-config)
("s-1" . eyebrowse-switch-to-window-config-1)
("s-2" . eyebrowse-switch-to-window-config-2)
("s-3" . eyebrowse-switch-to-window-config-3)
("s-4" . eyebrowse-switch-to-window-config-4)
("s-5" . eyebrowse-switch-to-window-config-5))
:config
(setq eyebrowse-mode-line-separator " ")
(setq eyebrowse-mode-line-style 'always)
(setq eyebrowse-new-workspace t)
(setq eyebrowse-wrap-around t)
(eyebrowse-mode 1))
(use-package persp-mode
:disabled t
:ensure t
:demand t
:bind (:map persp-mode-map
("s-w" . persp-switch)
("s-x" . persp-switch-to-buffer))
:config
(setq wg-morph-on nil)
(setq persp-autokill-buffer-on-remove 'kill-weak)
(setq persp-kill-foreign-buffer-behaviour nil)
(setq persp-nil-hidden t)
(setq persp-auto-save-opt 1)
(setq persp-remove-buffers-from-nil-persp-behaviour nil)
(setq persp-add-buffer-on-after-change-major-mode 'free)
(persp-mode 1))
;; Perspective-local eyebrwose window config
;; https://github.com/syl20bnr/spacemacs/pull/4068/files
(use-package persp-mode-local-eyebrowse
:disabled t
:no-require t
:after (persp-mode eyebrowse)
:config
(defun kd/load-eyebrowse-for-perspective (&optional frame-or-window)
"Load an eyebrowse workspace according to a perspective's parameters.
FRAME's perspective is the perspective that is considered, defaulting to
the current frame's perspective.
If the perspective doesn't have a workspace, create one."
(let* ((frame (if (eq frame-or-window 'frame)
(selected-frame)
nil))
(window (if (eq frame-or-window 'window)
(selected-window)
nil))
(persp (get-current-persp frame window))
(window-configs (persp-parameter 'eyebrowse-window-configs persp))
(current-slot (persp-parameter 'eyebrowse-current-slot persp))
(last-slot (persp-parameter 'eyebrowse-last-slot persp)))
(if window-configs
(progn
(eyebrowse--set 'window-configs window-configs frame)
(eyebrowse--set 'current-slot current-slot frame)
(eyebrowse--set 'last-slot last-slot frame)
(eyebrowse--load-window-config current-slot))
(eyebrowse--set 'window-configs nil frame)
(eyebrowse-init frame)
(kd/save-eyebrowse-for-perspective frame))))
(defun kd/update-eyebrowse-for-perspective (_new-persp-name &optional frame)
"Update and save current frame's eyebrowse workspace to its perspective.
Parameter _NEW-PERSP-NAME is ignored, and exists only for compatibility with
`persp-before-switch-functions'."
(eyebrowse--update-window-config-element
(eyebrowse--current-window-config (eyebrowse--get 'current-slot)
(eyebrowse--get 'current-tag)))
(kd/save-eyebrowse-for-perspective))
(defun kd/save-eyebrowse-for-perspective (&optional frame)
"Save FRAME's eyebrowse workspace to FRAME's perspective.
FRAME defaults to the current frame."
(let ((persp (get-frame-persp frame)))
(set-persp-parameter
'eyebrowse-window-configs (eyebrowse--get 'window-configs frame) persp)
(set-persp-parameter
'eyebrowse-current-slot (eyebrowse--get 'current-slot frame) persp)
(set-persp-parameter
'eyebrowse-last-slot (eyebrowse--get 'last-slot frame) persp)))
(add-hook 'persp-before-switch-functions #'kd/update-eyebrowse-for-perspective)
(add-hook 'eyebrowse-post-window-switch-hook #'kd/save-eyebrowse-for-perspective)
(add-hook 'persp-activated-functions #'kd/load-eyebrowse-for-perspective))
;;; Dired
(use-package dired
:commands (dired dired-hide-details-mode)
:diminish dired-mode
:init
(add-hook 'dired-mode-hook #'dired-hide-details-mode)
(add-hook 'dired-mode-hook #'diff-hl-dired-mode-unless-remote)
:config
(setq dired-dwim-target t)
(setq dired-listing-switches "-lahF")
(setq dired-isearch-filenames t)
(setq dired-ls-F-marks-symlinks t))
(use-package dired-single
:ensure t
:bind (:map dired-mode-map
("<RET>" . dired-single-buffer)
("<mouse-1>" . dired-single-buffer-mouse)
("^" . dired-single-up-directory)))
(use-package dired-x
:commands dired-omit-mode
:defines dired-omit-files
:init (add-hook 'dired-mode-hook #'dired-omit-mode))
(use-package dired-du
:commands dired-du-mode
:ensure t)
;; (use-package dired+
;; :quelpa (dired+ :fetcher url :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/dired+.el")
;; :after dired)
(use-package peep-dired
:ensure t
:commands peep-dired
:bind ((:map dired-mode-map
("P" . peep-dired))))
;;; Tramp
(use-package tramp
:defer t
:config
(setq remote-file-name-inhibit-cache nil)
(setq tramp-verbose 1)
(setq tramp-default-method "ssh"))
;; ---
(use-package projectile
:ensure t
:demand t
:diminish projectile-mode
:commands projectile-mode
:bind ("s-x" . projectile-switch-to-buffer)
;; :bind ((:map kd/projectile-map
;; ("a" . projectile-add-known-project)
;; ("b" . projectile-ibuffer)
;; ("i" . projectile-invalidate-cache)))
:config
;; (defadvice projectile-project-root (around exlude-tramp activate)
;; "This should disable projectile when visiting a remote file"
;; (unless (--any? (and it (file-remote-p it))
;; (list
;; (buffer-file-name)
;; list-buffers-directory
;; default-directory
;; dired-directory))
;; ad-do-it))
(setq projectile-cache-file (expand-file-name "projectile.cache" kd/cache-dir))
(setq projectile-track-known-projects-automatically nil)
(setq projectile-generic-command "fd --type f --print0")
(setq projectile-enable-caching t)
(setq projectile-completion-system 'ivy)
(setq projectile-tags-backend 'xref)
(setq projectile-mode-line
'(:eval
(if (file-remote-p default-directory)
"P"
(format "P[%s]" (projectile-project-name)))))
(setq projectile-mode-line "P")
(setq projectile-tags-file-name "/FILE_NOT_EXISTS")
(setq projectile-sort-order 'recently-active)
(projectile-mode 1))
(use-package persp-mode-projectile-bridge
:disabled t
:ensure t
:after (persp-mode projectile)
:preface
(defun kd/persp-mode-projectile-bridge-mode-hook-func ()
(if persp-mode-projectile-bridge-mode
(persp-mode-projectile-bridge-find-perspectives-for-all-buffers)
(persp-mode-projectile-bridge-kill-perspectives)))
:hook ((persp-mode-projectile-bridge-mode . kd/persp-mode-projectile-bridge-mode-hook-func)
(after-init . persp-mode-projectile-bridge-mode)))
(use-package rg
:ensure t
:commands rg-define-search
:bind ("C-c A" . rg-dwim)
:hook (rg-mode . wgrep-rg-setup))
(use-package deadgrep
:ensure t
:bind ("C-c a" . deadgrep))
;;; Git
(use-package magit
:ensure t
:bind (("s-g" . nil)
("s-g s" . magit-status)
("s-g l" . magit-log-current)
("s-g b" . magit-blame))
:preface
(defun kd/magit-revision-mode-hook-func ()
(text-scale-mode 1)
(text-scale-set -0.3))
:hook ((magit-process-mode . goto-address-mode)
(magit-post-refresh . diff-hl-magit-post-refresh)
(magit-revision-mode . kd/magit-revision-mode-hook-func))
:config
(setq magit-git-executable (executable-find "git")))
(use-package git-commit
:ensure t
:commands (git-commit-setup git-commit-mode global-git-commit-mode)
:init (add-hook 'git-commit-setup-hook #'flyspell-mode))
(use-package diff-hl
:ensure t
:commands
(turn-on-diff-hl-mode
diff-hl-magit-post-refresh
diff-hl-dired-mode
diff-hl-dired-mode-unless-remote))
(use-package expand-region
:ensure t
:bind ("C-=" . er/expand-region))
(use-package smartscan
:ensure t
:commands global-smartscan-mode
:init (add-hook 'after-init-hook #'global-smartscan-mode)
:config (setq smartscan-symbol-selector "symbol"))
(use-package duplicate-thing
:ensure t
:bind (:map ctl-x-map
("u" . duplicate-thing)))
(use-package hydra
:ensure t
:bind (("s-z" . hydra-goto/body)
("s-t" . hydra-toggle/body)
("s-o" . hydra-open/body)
("C-c w" . hydra-winner/body)
("C-M-o" . hydra-window-size/body))
:config
(use-package pretty-hydra
:ensure t)
(pretty-hydra-define hydra-goto
(:hint nil :color blue :quit-key "q" :title "Goto")
("Coding"
(("p" counsel-projectile-switch-project "Project")
("s" kd/jump-to-src "Repo")
("f" kd/jump-to-reference "Ref")
("e" (find-file "~/.dotfiles/.emacs") ".emacs"))
"Org"
(("c" kd/default-captured-org-note "cap.org: Default note")
("r" kd/counsel-org-find-file "Org files")
("t" (find-file "~/Dropbox/nvALT/snippets.org") "Snippets")
("w" (find-file (expand-file-name "work.org" org-directory)) "Work")
("l" helm-org-rifle-org-directory "Rifle"))
"File"
(("g" (find-file "~/Dropbox/ledger/ledger.beancount") "Ledger"))
"Deft"
(("zz" zetteldeft-new-file "New zettle")
("zf" zetteldeft-follow-link "Follow zettle link")
("zi" zetteldeft-find-file-full-title-insert "Insert zettle link")
("d" deft "Deft"))
"Buffer"
(("x" (switch-to-buffer "*scratch*") "*scratch*"))))
(pretty-hydra-define hydra-toggle
(:hint nil :color blue :quit-key "q" :title "Toggle")
("UI"
(("l" display-line-numbers-mode "Show line number" :toggle t)
("w" whitespace-mode "Show white space" :toggle t)
("z" writeroom-mode "Writeroom" :toggle t)
("v" visual-fill-column-mode "Visual fill column mode" :toggle t)
("h" hl-line-mode "Show highlight line" :toggle t)
("m" markdown-toggle-markup-hiding "Hiding markdown markup")
("t" toggle-truncate-lines "Truncate long lines"))
"Editing"
(("f" auto-fill-mode "Auto fill mode"))
"Desktop"
(("s" desktop-save-in-desktop-dir "Save desktop")
("r" desktop-read "Read desktop"))
"Debugging"
(("D" dap-hydra)
("de" toggle-debug-on-error "Debug on error")
("dq" toggle-debug-on-quit "Debug on quit"))))
(pretty-hydra-define hydra-open
(:hint nil :color blue :quit-key "q" :title "Open")
("Editing"
(("u" undo-tree-visualize "Show undo tree")
("U" undo-propose "Propose undo"))
"Open"
(("b" browse-url-at-point "Browse URL at point")
("r" browse-at-remote "Browse at repository")
("'" imenu-list-smart-toggle "Imenu list")
("e" prelude-open-with "Open externally")
("x" scratch "Scratch for current major mode"))
"Package"
(("p" list-packages "List packages"))))
(defhydra hydra-winner ()
"winner mode"
("h" winner-undo "undo")
("l" winner-redo "redo"))
(defhydra hydra-zoom ()
"zoom"
("g" text-scale-increase "in")
("l" text-scale-decrease "out"))