-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolarion-emacs.org
1999 lines (1666 loc) · 69.5 KB
/
solarion-emacs.org
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
#+TITLE: README
#+AUTHOR: wang1zhen
#+EMAIL: [email protected]
#+STARTUP: content
* Solarion Emacs
[[https://996.icu][https://img.shields.io/badge/link-996.icu-red.svg]]
Here is my personal configuration file for Emacs. The whole README file is a symlink to =solarion-emacs.org=, and with =org babel=, this file could be tangled into separate emacs-lisp files under =$HOME/.emacs.d/lisp/=.
* Table of Contents :TOC:
- [[#solarion-emacs][Solarion Emacs]]
- [[#installation][Installation]]
- [[#early-initel][early-init.el]]
- [[#initel][init.el]]
- [[#init-straightel][init-straight.el]]
- [[#init-funcel][init-func.el]]
- [[#init-basicel][init-basic.el]]
- [[#init-generalel][init-general.el]]
- [[#init-uiel][init-ui.el]]
- [[#init-scrollel][init-scroll.el]]
- [[#init-fontsel][init-fonts.el]]
- [[#init-editel][init-edit.el]]
- [[#init-hydrael][init-hydra.el]]
- [[#init-mapel][init-map.el]]
- [[#init-verticoel][init-vertico.el]]
- [[#init-corfuel][init-corfu.el]]
- [[#init-tempelel][init-tempel.el]]
- [[#init-magitel][init-magit.el]]
- [[#init-ibufferel][init-ibuffer.el]]
- [[#init-midnightel][init-midnight.el]]
- [[#init-trampel][init-tramp.el]]
- [[#init-orgel][init-org.el]]
- [[#init-latexel][init-latex.el]]
- [[#init-diredel][init-dired.el]]
- [[#init-projectileel][init-projectile.el]]
- [[#init-dashboardel][init-dashboard.el]]
- [[#init-vtermel][init-vterm.el]]
- [[#init-perspel][init-persp.el]]
- [[#init-imel][init-im.el]]
- [[#init-wslel][init-wsl.el]]
* Installation
*Clone the repository*
#+begin_src shell :tangle no
git clone [email protected]:wang1zhen/solarion-emacs ~/.emacs.d
#+end_src
*Tangle the org file*
#+begin_src shell :tangle no
emacs --batch --eval "(progn (require 'org) (let ((org-confirm-babel-evaluate nil)) (org-babel-tangle-file \"~/.emacs.d/solarion-emacs.org\")))"
#+end_src
*Launch Emacs and have fun!*
* early-init.el
#+begin_src emacs-lisp :tangle ./early-init.el
;;; early-init.el --- early-init.el is run before package and UI initialization happens -*- lexical-binding: t -*-
;;; Code:
;; Defer garbage collection further back in the startup process
(setq gc-cons-threshold most-positive-fixnum
gc-cons-percentage 0.5)
;; Package initialize occurs automatically, before `user-init-file' is
;; loaded, but after `early-init-file'. We handle package
;; initialization, so we must prevent Emacs from doing it early!
(setq package-enable-at-startup nil)
;; Inhibit resizing frame
(setq frame-inhibit-implied-resize t)
;; Faster to disable these here (before they've been initialized)
(push '(menu-bar-lines . 0) default-frame-alist)
(push '(tool-bar-lines . 0) default-frame-alist)
(push '(vertical-scroll-bars) default-frame-alist)
#+end_src
* init.el
#+begin_src emacs-lisp :tangle ./init.el
;;; init.el --- Load the full configuration -*- lexical-binding: t -*-
;;; Code:
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))
;; Custom file
(setq custom-file (make-temp-file "emacs-custom-"))
;; Adjust garbage collection thresholds during startup, and thereafter
(let ((normal-gc-cons-threshold (* 20 1024 1024))
(init-gc-cons-threshold (* 128 1024 1024)))
(setq gc-cons-threshold init-gc-cons-threshold)
(add-hook 'emacs-startup-hook
(lambda () (setq gc-cons-threshold normal-gc-cons-threshold))))
;; Always load newest byte code
(setq load-prefer-newer t)
;; Packages
(require 'init-straight)
;; Useful functions defined
(require 'init-func)
;; Preferences
(require 'init-basic)
(require 'init-general)
(require 'init-ui)
(require 'init-scroll)
(require 'init-fonts)
(require 'init-edit)
;; Keybindings
(require 'init-hydra)
(require 'init-map)
(require 'init-vertico)
(require 'init-corfu)
(require 'init-tempel)
(require 'init-magit)
(require 'init-ibuffer)
(require 'init-midnight)
(require 'init-tramp)
(require 'init-org)
(require 'init-latex)
(require 'init-dired)
(require 'init-projectile)
(require 'init-dashboard)
(require 'init-vterm)
(require 'init-persp)
(require 'init-im)
;; WSL specific setting
(when (and (eq system-type 'gnu/linux) (getenv "WSLENV"))
(require 'init-wsl))
#+end_src
* init-straight.el
#+begin_src emacs-lisp :tangle ./lisp/init-straight.el :mkdirp yes
;;; init-straight.el --- Initialize package configurations -*- lexical-binding: t -*-
;;; Code:
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(setq straight-use-package-by-default t)
(setq straight-vc-git-default-protocol 'https)
(setq straight-vc-git-default-clone-depth 3)
(load bootstrap-file nil 'nomessage))
;; Install use-package with straight
(straight-use-package 'use-package)
;; Should set before loading `use-package'
(setq use-package-expand-minimally t)
(setq use-package-enable-imenu-support t)
(require 'use-package)
;; Native compile
;; Log warnings but not pop up the *Warnings* buffer
(setq native-comp-async-report-warnings-errors 'silent)
;; Required by `use-package'
(use-package diminish)
(use-package bind-key)
(provide 'init-straight)
#+end_src
* init-func.el
#+begin_src emacs-lisp :tangle ./lisp/init-func.el :mkdirp yes
;;; init-func.el --- Useful functions are defined here -*- lexical-binding: t -*-
;;; Code:
(defun indent-buffer ()
(interactive)
(save-excursion
(indent-region (point-min) (point-max) nil)))
;; Font
(defun font-installed-p (font-name)
"Check if font with FONT-NAME is available."
(find-font (font-spec :name font-name)))
;; Auto tangle babel file
(defun org-babel-auto-tangle ()
(when (and (eq major-mode 'org-mode)
(string-equal (buffer-name) "solarion-emacs.org"))
(org-babel-tangle)))
;; Define split-window-below-and-focus and split-window-right-and-focus
(defun split-window-below-and-focus ()
"Split the window vertically and focus the new window."
(interactive)
(split-window-below)
(windmove-down))
(defun split-window-right-and-focus ()
"Split the window horizontally and focus the new window."
(interactive)
(split-window-right)
(windmove-right))
(defun solarion/org-mode-setup ()
(auto-fill-mode 0)
(visual-line-mode 1)
(adaptive-wrap-prefix-mode 1)
;; (electric-pair-local-mode -1)
)
;; Ask for the filename before pasting an image
;; filename should end with ".png/.jpg/.svg"
(defun solarion/org-download-paste-clipboard-wsl ()
"to simplify the logic, use c:/Users/Public as temporary directory, and move it into current directory"
(interactive)
(let* ((powershell (executable-find "powershell.exe"))
(file-base-name (format-time-string "image-%Y%m%d_%H%M%S.png"))
(file-name (read-string (format "Filename [%s]: " file-base-name) nil nil file-base-name))
(file-path-wsl (concat "./image/" file-name)))
(shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/Public/" file-name "\\\")\""))
(make-directory "./image" t)
(rename-file (concat "/mnt/c/Users/Public/" file-name) file-path-wsl)
(insert (concat "#+ATTR_LATEX: :width \\linewidth\n"))
(org-indent-line)
(insert (concat "[[file:" file-path-wsl "]]"))
(org-display-inline-images)))
;; dashboard
(defun solarion-edit-config (&rest _)
(interactive)
(find-file (concat user-emacs-directory "solarion-emacs.org")))
;; buffer
(defun solarion-new-buffer nil
(interactive)
(let ((buffer (generate-new-buffer "*new*")))
(set-window-buffer nil buffer)
(with-current-buffer buffer
(funcall (default-value 'major-mode)))))
;; Delete file and buffer
(defun delete-file-and-buffer ()
"Kill the current buffer and deletes the file it is visiting."
(interactive)
(let ((filename (buffer-file-name)))
(if filename
(if (y-or-n-p (concat "Do you really want to delete file " filename " ?"))
(progn
(delete-file filename)
(message "Deleted file %s." filename)
(kill-buffer)))
(message "Not a file visiting buffer!"))))
(defun flash-mode-line ()
(invert-face 'mode-line)
(run-with-timer 0.1 nil #'invert-face 'mode-line))
(defun copy-line (arg)
"Copy lines (as many as prefix argument) in the kill ring.
Ease of use features:
- Move to start of next line.
- Appends the copy on sequential calls.
- Use newline as last char even on the last line of the buffer.
- If region is active, copy its lines."
(interactive "p")
(let ((beg (line-beginning-position))
(end (line-end-position arg)))
(when mark-active
(if (> (point) (mark))
(setq beg (save-excursion (goto-char (mark)) (line-beginning-position)))
(setq end (save-excursion (goto-char (mark)) (line-end-position)))))
(if (eq last-command 'copy-line)
(kill-append (buffer-substring beg end) (< end beg))
(kill-ring-save beg end)))
(kill-append "\n" nil)
(beginning-of-line (or (and arg (1+ arg)) 2))
(if (and arg (not (= 1 arg))) (message "%d lines copied" arg)))
(defun solarion/git-add-commit-push ()
"Simple commit current git project and push to its upstream."
(interactive)
(when (and buffer-file-name
(buffer-modified-p))
(save-buffer)) ;; save it first if modified.
(magit-diff-unstaged)
(when (yes-or-no-p "Do you really want to commit everything?")
(magit-stage-modified t) ;; stage modified and untracked
(magit-diff-staged)
(let ((msg (read-string "Commit Message: ")))
(when (= 0 (length msg))
(setq msg (format-time-string "commit by magit in emacs@%Y-%m-%d %H:%M:%S"
(current-time))))
(magit-call-git "commit" "-m" msg)
(magit-push-current-to-upstream nil)
(message "now do async push to %s" (magit-get "remote" "origin" "url"))))
(magit-mode-bury-buffer))
(defun solarion/indent-buffer-and-format ()
"Indent buffer and format code"
(interactive)
(indent-buffer)
(when (format-all--language-id-buffer)
(format-all-buffer t)))
(provide 'init-func)
#+end_src
* init-basic.el
#+begin_src emacs-lisp :tangle ./lisp/init-basic.el :mkdirp yes
;;; init-basic.el --- Default configurations -*- lexical-binding: t -*-
;;; Code:
(setq user-full-name "wang1zhen"
user-mail-address "[email protected]")
;; Increase how much is read from processes in a single chunk (default is 4kb)
(setq read-process-output-max #x10000) ; 64kb
;; Garbage Collector Magic Hack
(use-package gcmh
:diminish
:init
(setq gcmh-idle-delay 5
gcmh-high-cons-threshold #x1000000) ; 16MB
:hook (after-init . gcmh-mode))
;; Encoding
;; UTF-8 as the default coding system
(when (fboundp 'set-charset-priority)
(set-charset-priority 'unicode))
;; Explicitly set the prefered coding systems to avoid annoying prompt
;; from emacs (especially on Microsoft Windows)
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(set-language-environment 'utf-8)
(set-default-coding-systems 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-8)
(set-file-name-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(modify-coding-system-alist 'process "*" 'utf-8)
;; Ensure environment variables inside Emacs look the same as in the user's shell
(use-package exec-path-from-shell
:init
(setq exec-path-from-shell-variables '("PATH" "MANPATH")
exec-path-from-shell-arguments '("-l"))
:config
(exec-path-from-shell-initialize))
;; Start server
(use-package server
:straight nil
:hook (after-init . server-mode))
;; Go to the last place when previously visited the file
(use-package saveplace
:straight nil
:hook (after-init . save-place-mode))
(use-package recentf
:straight nil
:hook (after-init . recentf-mode)
:init
(setq recentf-max-saved-items 500
recentf-max-menu-items 15
recentf-exclude
'("\\.?cache" ".cask" "url" "COMMIT_EDITMSG\\'" "bookmarks"
"\\.\\(?:gz\\|gif\\|svg\\|png\\|jpe?g\\|bmp\\|xpm\\)$"
"\\.?ido\\.last$" "\\.revive$" "/G?TAGS$" "/.elfeed/"
"^/tmp/" "^/var/folders/.+$" "^/ssh:" "/persp-confs/"
(lambda (file) (file-in-directory-p file package-user-dir))))
:config
(push (expand-file-name recentf-save-file) recentf-exclude)
(add-to-list 'recentf-filename-handlers #'abbreviate-file-name))
(use-package savehist
:straight nil
:hook (after-init . savehist-mode)
:init
(setq enable-recursive-minibuffers t ; Allow commands in minibuffers
history-length 1000
savehist-additional-variables '(mark-ring
global-mark-ring
search-ring
regexp-search-ring
extended-command-history)
savehist-autosave-interval 300))
(use-package simple
:straight nil
:hook ((after-init . size-indication-mode)
(text-mode . visual-line-mode)
(helpful-mode . visual-line-mode)
((prog-mode org-mode markdown-mode conf-mode latex-mode) . (lambda () (setq show-trailing-whitespace t))))
:init
(setq column-number-mode t
line-number-mode t
;; kill-whole-line t ; Kill line including '\n'
line-move-visual t
;; track-eol t ; Keep cursor at end of lines. Require line-move-visual is nil.
set-mark-command-repeat-pop t) ; Repeating C-SPC after popping mark pops it again
)
(use-package so-long
:straight nil
:hook (after-init . global-so-long-mode)
:config (setq so-long-threshold 400))
(use-package adaptive-wrap
:commands adaptive-wrap-prefix-mode)
(use-package keyfreq
:init
(setq keyfreq-file "~/.emacs.d/.keyfreq")
(setq keyfreq-file-lock "~/.emacs.d/.keyfreq.lock")
(keyfreq-mode 1)
(keyfreq-autosave-mode 1)
:config
(setq keyfreq-excluded-commands
'(self-insert-command
org-self-insert-command
forward-char
backward-char
previous-line
next-line))
(setq keyfreq-excluded-regexp
'("\\`vertico-.*\\'"
"\\`iscroll-.*\\'"
"\\`vterm-.*\\'")))
;; Misc
(fset 'yes-or-no-p 'y-or-n-p)
(setq-default major-mode 'emacs-lisp-mode
tab-width 8
indent-tabs-mode nil) ; Permanently indent with spaces, never with TABs
;; flash the modeline for visual bell
(setq visible-bell nil
ring-bell-function 'flash-mode-line)
(setq inhibit-compacting-font-caches t ; Don’t compact font caches during GC.
delete-by-moving-to-trash t ; Deleting files go to OS's trash folder
make-backup-files nil ; Forbide to make backup files
create-lockfiles nil ; Forbide to make lockfiles
auto-save-default nil ; Disable auto save
uniquify-buffer-name-style 'post-forward-angle-brackets ; Show path if names are same
adaptive-fill-regexp "[ t]+|[ t]*([0-9]+.|*+)[ t]*"
adaptive-fill-first-line-regexp "^* *$"
sentence-end-double-space nil)
;; Use the system clipboard
(setq select-enable-clipboard t)
;; Always focus the help window
(setq help-window-select t)
;; Enable mouse in terminal mode
(xterm-mouse-mode)
;; Auto tangle this file after save (without prompt)
(add-hook 'after-save-hook #'org-babel-auto-tangle)
;; Disable scratch buffer text
(setq initial-scratch-message nil)
(provide 'init-basic)
#+end_src
* init-general.el
Only prepare the packages here, specific keybindings goes to =init-map.el=.
#+begin_src emacs-lisp :tangle ./lisp/init-general.el :mkdirp yes
;;; init-general.el --- Initialize general -*- lexical-binding: t -*-
;;; Code:
(use-package key-chord
:diminish
:init
(key-chord-mode))
(use-package general)
(provide 'init-general)
#+end_src
* init-ui.el
#+begin_src emacs-lisp :tangle ./lisp/init-ui.el :mkdirp yes
;;; init-ui.el --- Better lookings and appearances. -*- lexical-binding: t -*-
;;; Code:
(defconst solarion-font-size
260
"Font size for default font and modeline")
;; Title
(setq frame-title-format '((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))
" "
user-login-name
"@"
system-name)
icon-title-format frame-title-format)
;; Optimization
(setq idle-update-delay 1.0)
(setq-default cursor-in-non-selected-windows nil)
(setq highlight-nonselected-windows nil)
(tooltip-mode -1) ;; Disable tooltips
(set-fringe-mode 10) ;; 左右边框 仅对GUI生效
(global-hl-line-mode t)
;; always split vertically
(setq split-height-threshold nil
split-width-threshold 80)
;; Mode-line
(use-package doom-modeline
:diminish doom-modeline-mode
:init
(setq doom-modeline-modal-icon nil)
;; Must use mono font here
(set-face-attribute 'mode-line nil :font "CaskaydiaCove Nerd Font Mono" :height solarion-font-size)
(set-face-attribute 'mode-line-inactive nil :font "CaskaydiaCove Nerd Font Mono" :height solarion-font-size)
(unless (version< emacs-version "29")
(set-face-attribute 'mode-line-active nil :font "CaskaydiaCove Nerd Font Mono" :height solarion-font-size)) ;; For Emacs 29+
(doom-modeline-mode t))
(use-package nerd-icons
:init
(setq nerd-icons-font-family "CaskaydiaCove Nerd Font Mono"))
(use-package display-line-numbers
:straight nil
:init
(setq display-line-numbers-width-start t)
(setq display-line-numbers-current-absolute t)
:config
(dolist (mode '(c-mode-common-hook
c-mode-hook
emacs-lisp-mode-hook
lisp-interaction-mode-hook
lisp-mode-hook
sh-mode-hook
python-mode-hook
html-mode-hook
rust-mode-hook
conf-mode-hook))
(add-hook mode (lambda () (setq display-line-numbers t)))))
;; Suppress GUI features
(setq use-file-dialog nil
use-dialog-box nil
inhibit-startup-screen t
inhibit-startup-echo-area-message t)
;; Display dividers between windows
(setq window-divider-default-places t
window-divider-default-bottom-width 1
window-divider-default-right-width 1)
(add-hook 'window-setup-hook #'window-divider-mode)
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(use-package rainbow-delimiters
:hook
(prog-mode . rainbow-delimiters-mode)
(LaTeX-mode . rainbow-delimiters-mode))
(use-package which-key
:diminish which-key-mode
:hook (after-init . which-key-mode)
:init
(setq which-key-idle-delay 0.2)
(setq which-key-sort-order 'which-key-key-order-alpha)
(setq which-key-prefix-prefix "")
:config
(set-face-attribute 'which-key-group-description-face nil :weight 'bold))
(use-package which-key-posframe
:init
(which-key-posframe-mode)
:config
(setq which-key-posframe-parameters
'((left-fringe . 8)
(right-fringe . 8))))
(use-package command-log-mode
:commands command-log-mode)
(use-package helpful
:bind
([remap describe-function] . helpful-callable)
([remap describe-variable] . helpful-variable)
([remap describe-key] . helpful-key))
(use-package winum
:hook (after-init . winum-mode))
(use-package posframe)
(use-package shackle
:hook (after-init . shackle-mode)
:init
(setq shackle-select-reused-windows nil) ; default nil
(setq shackle-default-alignment 'right) ; default below
(setq shackle-select-reused-windows t)
(setq shackle-rules
'(("*vterm*" :size 0.3 :align below :popup t)
;; (compilation-mode :ignore t)
;; ("\\*Async Shell.*\\*" :regexp t :ignore t)
;; ("\\*corfu.*\\*" :regexp t :ignore t)
;; ("*eshell*" :select t :size 0.4 :align t :popup t)
(helpful-mode :size 0.4 :align t :popup t)
(help-mode :size 0.4 :align t :popup t)
;; ("*Messages*" :select t :size 0.4 :align t :popup t)
(magit-status-mode :inhibit-window-quit t :other t)
(magit-log-mode :inhibit-window-quit t :other t)
("\\*Org Src.*\\*" :regexp t :inhibit-window-quit t :other t))))
(use-package ef-themes
:straight '(ef-themes :type git :host github :repo "protesilaos/ef-themes")
:init
(setq ef-themes-headings nil)
(setq ef-themes-mixed-fonts nil)
(setq ef-themes-variable-pitch-ui nil)
(ef-themes-select 'ef-cyprus))
(provide 'init-ui)
#+end_src
* init-scroll.el
Use iscroll for image scrolling and pixel-scroll-precision-mode for smooth scrolling (available since emacs 29)
#+begin_src emacs-lisp :tangle ./lisp/init-scroll.el :mkdirp yes
;;; init-scroll.el --- Better scrolling effects. -*- lexical-binding: t -*-
;;; Code:
(setq scroll-preserve-screen-position 'always)
(setq next-screen-context-lines 5)
(use-package iscroll
:init
:hook (org-mode . iscroll-mode))
(when (fboundp 'pixel-scroll-precision-mode)
(pixel-scroll-precision-mode))
(provide 'init-scroll)
#+end_src
* init-fonts.el
The font settings are mainly for GUI Emacs, this would not affect TUI Emacs.
font check
Chinese:
言
Symbols:
♪
Kana:
夜に駆ける
#+begin_src emacs-lisp :tangle ./lisp/init-fonts.el :mkdirp yes
;;; init-fonts.el --- Fonts configurations (for GUI) -*- lexical-bindings: t -*-
;;; Code:
(defun solarion-config-fonts ()
(when (display-graphic-p)
;; Set default font
(set-face-attribute 'default
nil
:font "CaskaydiaCove Nerd Font Mono"
:height solarion-font-size)
;; Fixed-pitch (monospaced) fonts 等宽字体
(set-face-attribute 'fixed-pitch
nil
:font "CaskaydiaCove Nerd Font Mono"
:height solarion-font-size)
;; CJK fonts
(set-fontset-font t 'han (font-spec :family "Noto Serif CJK SC" :weight 'semi-bold :slant 'normal))
(set-fontset-font t 'cjk-misc (font-spec :family "Noto Serif CJK SC" :weight 'semi-bold :slant 'normal))
(set-fontset-font t 'kana (font-spec :family "Noto Serif CJK JP" :weight 'semi-bold :slant 'normal))
;; Emoji
(set-fontset-font t 'symbol (font-spec :family "Noto Color Emoji") nil 'prepend)))
(solarion-config-fonts)
(add-hook 'window-setup-hook #'solarion-config-fonts)
(add-hook 'server-after-make-frame-hook #'solarion-config-fonts)
;; https://github.com/mickeynp/ligature.el
(use-package ligature
:straight '(ligature :type git :host github :repo "mickeynp/ligature.el")
:config
;; Enable the "www" ligature in every possible major mode
(ligature-set-ligatures 't '("www"))
;; Enable traditional ligature support in eww-mode, if the
;; `variable-pitch' face supports it
(ligature-set-ligatures 'eww-mode '("ff" "fi" "ffi"))
;; Enable all Cascadia Code ligatures in programming modes
(ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
"!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
"<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
"..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
"~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
"[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
"<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
"##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
"?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
"\\\\" "://"))
;; Enables ligature checks globally in all buffers. You can also do it
;; per mode with `ligature-mode'.
(global-ligature-mode t))
(provide 'init-fonts)
#+end_src
* init-edit.el
#+begin_src emacs-lisp :tangle ./lisp/init-edit.el :mkdirp yes
;;; init-edit.el --- Initialize editing configurations -*- lexical-binding: t -*-
;;; Code:
;; Automatically reload files was modified by external program
(use-package autorevert
:straight nil
:diminish
:init
(setq global-auto-revert-non-file-buffers t
auto-revert-interval 1)
(global-auto-revert-mode))
(use-package auto-save
:straight '(auto-save :type git :host github :repo "manateelazycat/auto-save")
:config
(auto-save-enable)
(setq auto-save-silent t) ; quietly save
(setq auto-save-delete-trailing-whitespace t) ; automatically delete spaces at the end of the line when saving
)
(use-package format-all
:commands (format-all-buffer format-all--language-id-buffer))
;; Jump to things in Emacs tree-style
(use-package avy
:hook (after-init . avy-setup-default)
:config (setq avy-all-windows t
avy-background t
avy-style 'at-full
avy-timeout-seconds 0.5))
(use-package beginend
:diminish beginend-global-mode
:hook (after-init . beginend-global-mode))
;; A comprehensive visual interface to diff & patch
(use-package ediff
:straight nil
:hook (;; show org ediffs unfolded
(ediff-prepare-buffer . outline-show-all)
;; restore window layout when done
;; (ediff-quit . winner-undo)
)
:config
(setq ediff-window-setup-function 'ediff-setup-windows-plain
ediff-split-window-function 'split-window-vertically
ediff-merge-split-window-function 'split-window-vertically))
;; Increase selected region by semantic units
(use-package expand-region
:commands er/expand-region)
;; Hungry deletion
(use-package hungry-delete
:diminish
:hook (after-init . global-hungry-delete-mode)
:init (setq hungry-delete-except-modes '(help-mode minibuffer-mode minibuffer-inactive-mode calc-mode)
hungry-delete-chars-to-skip " \f"))
;; Move to the beginning/end of line or code
(use-package mwim
:config
(general-def "C-a" #'mwim-beginning-of-code-or-line)
(general-def "C-e" #'mwim-end-of-code-or-line))
(general-def "C-/" #'undo-only)
(general-def "C-r" #'undo-redo)
;; vundo
(use-package vundo
:config
(general-def "C-x u" #'vundo)
(general-def "C-x r" #'vundo)
(general-def vundo-mode-map "C-n" #'vundo-next)
(general-def vundo-mode-map "C-p" #'vundo-previous)
(general-def vundo-mode-map "C-f" #'vundo-forward)
(general-def vundo-mode-map "C-b" #'vundo-backward)
(setq vundo-glyph-alist vundo-unicode-symbols))
;; Handling capitalized subwords in a nomenclature
(use-package subword
:straight nil
:diminish
:hook ((prog-mode . subword-mode)
(minibuffer-setup . subword-mode)))
(use-package sudo-edit
:commands (sudo-edit-find-file sudo-edit-current-file))
;; On-the-fly spell checker
(use-package flyspell
:straight nil
:diminish
:if (executable-find "aspell")
:hook
(((text-mode outline-mode) . flyspell-mode)
(prog-mode . flyspell-prog-mode)
(LaTeX-mode . flyspell-mode)
(flyspell-mode . (lambda ()
(dolist (key '("C-;" "C-," "C-."))
(unbind-key key flyspell-mode-map)))))
:init
(setq flyspell-issue-message-flag nil
ispell-program-name "aspell"
ispell-extra-args '("--sug-mode=ultra" "--lang=en_US" "--run-together")))
;; Framework for mode-specific buffer indexes
(use-package imenu
:straight nil
:init
(setq imenu-auto-rescan t))
;; 中英文间自动加入空格
(use-package pangu-spacing
:diminish global-pangu-spacing-mode
:init
(global-pangu-spacing-mode 1)
(setq pangu-spacing-real-insert-separtor t))
;; occur
(add-hook 'occur-hook (lambda () (switch-to-buffer-other-window "*Occur*")))
;; smartparens
(use-package smartparens
:diminish
:config
(require 'smartparens-config)
(add-hook 'org-mode-hook #'smartparens-mode)
(add-hook 'LaTeX-mode-hook #'smartparens-mode)
(add-hook 'emacs-lisp-mode-hook #'smartparens-mode)
;; custom pairs
(with-eval-after-load 'org
(sp-local-pair 'org-mode "\\[" "\\]")
(sp-local-pair 'org-mode "=" nil :actions :rem)
(sp-local-pair 'org-mode "/" nil :actions :rem)))
(use-package lorem-ipsum)
;; (treesit-auto-install-all)
(use-package treesit-auto
:config
(global-treesit-auto-mode)
(setq treesit-font-lock-level 4))
(provide 'init-edit)
#+end_src
* init-hydra.el
#+begin_src emacs-lisp :tangle ./lisp/init-hydra.el :mkdirp yes
;;; init-hydra.el --- Hydra configurations -*- lexical-binding: t -*-
;;; Code:
(use-package hydra
:config
(defhydra hydra-window-resize (:timeout 4)
"Resize window"
("j" enlarge-window "Increase height")
("k" shrink-window "Decrease height")
("h" shrink-window-horizontally "Decrease width")
("l" enlarge-window-horizontally "Increase width")
("SPC" balance-windows "Balance windows")
("q" nil "quit" :exit t)))
(provide 'init-hydra)
#+end_src
* init-map.el
Define the majority of keybindings here.
#+begin_src emacs-lisp :tangle ./lisp/init-map.el :mkdirp yes
;;; init-map.el --- Keybindings -*- lexical-binding: t -*-
;;; Code:
;; misc
(general-def [f10] #'solarion/indent-buffer-and-format) ;; f12 reserved for yakuake
(general-def [f5] #'revert-buffer)
(general-def ";" (general-key-dispatch 'self-insert-command
:timeout 0.25
"'" #'comment-line))
(general-def "j" (general-key-dispatch 'self-insert-command
:timeout 0.25
"k" (general-key "C-g")))
(general-def "k" (general-key-dispatch 'self-insert-command
:timeout 0.25
"j" #'avy-goto-char-timer))
(general-def :keymaps 'override "C-c k" #'copy-line)
(general-unbind "M-`") ;; reserved for tmux
(general-create-definer global-leader-def
:keymaps 'override
:prefix "C-c")
(general-create-definer local-leader-def
:keymaps 'override
:prefix "C-c m")
;; Global leader
(global-leader-def
;; maps
"h" #'(help-command :which-key "Help")
"p" #'(projectile-command-map :which-key "Projectile")
;; keys
"C-." #'consult-imenu ;; "C-c ." for org-time-stamp
"=" #'er/expand-region
"C-s" #'consult-ripgrep
"C-SPC" #'consult-mark
;; window
"w" '(:ignore t :which-key "Window")
"ws" #'split-window-below-and-focus
"wv" #'split-window-right-and-focus
"wd" #'(delete-window :which-key "Delete window")
"wq" #'(kill-buffer-and-window :which-key "Kill buffer and window")
"wr" #'(hydra-window-resize/body :which-key "Window Resize")
"w=" #'(balance-windows :which-key "Balance Windows")
"1" #'(winum-select-window-1 :which-key "Switch to window 1")
"2" #'(winum-select-window-2 :which-key "Switch to window 2")
"3" #'(winum-select-window-3 :which-key "Switch to window 3")
"4" #'(winum-select-window-4 :which-key "Switch to window 4")
"5" #'(winum-select-window-5 :which-key "Switch to window 5")
;; buffer & bookmark
"b" '(:ignore t :which-key "Buffer/Bookmark")
"bp" #'(previous-buffer :which-key "Previous Buffer")
"bn" #'(next-buffer :which-key "Next Buffer")
"bb" #'(consult-buffer :which-key "Switch Buffer")
"bc" #'(clone-indirect-buffer :which-key "Clone Buffer")
"bd" #'(kill-current-buffer :which-key "Kill Buffer")