Timeline add desktop-save-mode, add ibuffer, add magit
This article introduces the Emacs configuration scheme in the Windows Terminal and WSL2 (Arch Linux and Ubuntu) environment, discussing in detail the terminal appearance settings, system dependency preparation, and the Emacs installation process. At the same time, it summarizes custom key bindings for common shortcuts such as code formatting, window adjustment, and LSP code navigation. Environment Using Windows Terminal + WSL2
WSL2 Arch Linux
Configuration Windows Terminal Open settings in Windows Terminal, select to open the JSON file, and add a color scheme in schemes
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 "schemes" : [ { "background" : "#0D1117" , "black" : "#484F58" , "blue" : "#58A6FF" , "brightBlack" : "#6E7681" , "brightBlue" : "#79C0FF" , "brightCyan" : "#56D4DD" , "brightGreen" : "#56D364" , "brightPurple" : "#D2A8FF" , "brightRed" : "#FFA198" , "brightWhite" : "#FFFFFF" , "brightYellow" : "#E3B341" , "cursorColor" : "#2F81F7" , "cyan" : "#39C5CF" , "foreground" : "#E6EDF3" , "green" : "#3FB950" , "name" : "GitHub-Dark-Default" , "purple" : "#BC8CFF" , "red" : "#FF7B72" , "selectionBackground" : "#E6EDF3" , "white" : "#B1BAC4" , "yellow" : "#D29922" } ] ,
In the archlinux configuration, select the Appearance tab Select GitHub-Dark-Default as the color scheme Select FiraCode Nerd Font as the font Background opacity 86%, select to enable acrylic material In the archlinux configuration, select the Advanced tab Uncheck sound for bell notification style, select flash window and flash taskbar Install win32yank.exe and add it to the environment variables so that it can be accessed directly from the command line. If acrylic fails, simply turn off Windows power-saving mode.
Arch Linux Arch Linux needs to download some packages.
Download yay reference.
Note that after downloading, it is best to change the sources for pacman and yay, otherwise the speed will be extremely slow.
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 sudo nano /etc/locale.gensudo locale-gensudo pacman -Sy emacs-noxsudo pacman -Sy clang nvm ripgrep bear pandocsource /usr/share/nvm/init-nvm.shnvm list-remote nvm install v20.19.4 nvm use v20.19.4 npm i -g pyright bash-language-server devicetree-language-server prettier curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup component add rust-analyzer sudo pacman -S exaecho 'alias ll="ls -alF"' >> ~/.bashrcecho 'alias ls="exa --icons"' >> ~/.bashrcsource ~/.bashrcmkdir -p ~/.emacs.d/data/backupmkdir -p ~/.emacs.d/data/autosavegit config --global core.editor "emacs"
Ubuntu20.04 Reference:
Emacs Install. Arch Linux can be installed directly via pacman; if using Ubuntu, consider compiling it yourself. Reference:
Configuration .emacs(Click to expand) 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 (menu-bar-mode -1 ) (global-display-line-numbers-mode t ) (column-number-mode 1 ) (add-hook 'prog-mode-hook 'hs-minor-mode) (global-auto-revert-mode 1 ) (global-visual-line-mode 1 ) (electric-pair-mode 1 ) (electric-indent-mode 1 ) (xterm-mouse-mode 1 ) (set-language-environment "utf-8" ) (set-buffer-file-coding-system 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (set-default-coding-systems 'utf-8) (set-clipboard-coding-system 'utf-8) (modify-coding-system-alist 'process "*" 'utf-8) (prefer-coding-system 'utf-8) (setq-default pathname-coding-system 'utf-8) (setq default-process-coding-system '(utf-8 . utf-8) locale-coding-system 'utf-8 file-name-coding-system 'utf-8 default-buffer-file-coding-system 'utf-8 slime-net-coding-system 'utf-8-unix ) (setq find-file-encoding 'auto) (setq-default coding-system-for-read 'utf-8) (setq-default coding-system-for-write 'utf-8) (setq-default window-combination-resize t x-stretch-cursor t indent-tabs-mode nil tab-width 8 ) (setq ring-bell-function 'ignore initial-scratch-message nil inhibit-startup-message t auto-save-file-name-transforms '((".*" "~/.emacs.d/data/autosave/" t )) backup-directory-alist '(("." . "~/.emacs.d/data/backup/" )) create-lockfiles nil scroll-conservatively 10000 scroll-step 1 undo-limit 80000 display-time-default-load-average nil use-short-answers t comp-deferred-compilation t native-comp-async-report-warnings-errors nil ) (defun my/kill-unwanted-buffers () "在 Emacs 启动时关闭一些不想要的 buffer." (dolist (buf-name '("*scratch*" ;;"*Async-native-compile-log*" ;; can't be killed ;;"*Messages*" )) (when (get-buffer buf-name) (kill-buffer buf-name)))) (add-hook 'emacs-startup-hook #'my/kill-unwanted-buffers) (add-hook 'emacs-startup-hook (lambda () (message "Emacs ready in %s with %d garbage collections." (format "%.2f seconds" (float-time (time-subtract after-init-time before-init-time))) gcs-done))) (when (display-graphic-p ) (set-face-attribute 'default nil :font "FiraCode Nerd Font" :height 120 )) (cond ((executable-find "win32yank.exe" ) (defun my/clipboard-to-windows (text &optional push) (let ((process-connection-type nil )) (with-temp-buffer (insert text) (call-process-region (point-min ) (point-max ) "win32yank.exe" nil nil nil "-i" )))) (defun my/clipboard-from-windows () (string-trim-right (with-output-to-string (call-process "win32yank.exe" nil standard-output nil "-o" )))) (setq interprogram-cut-function 'my/clipboard-to-windows) (setq interprogram-paste-function 'my/clipboard-from-windows)) ((and (getenv "WAYLAND_DISPLAY" ) (executable-find "wl-copy" ) (executable-find "wl-paste" )) (defun my/clipboard-to-wayland (text &optional push) (let ((process-connection-type nil )) (with-temp-buffer (insert text) (call-process-region (point-min ) (point-max ) "wl-copy" nil nil nil )))) (defun my/clipboard-from-wayland () (string-trim-right (with-output-to-string (call-process "wl-paste" nil standard-output nil )))) (setq interprogram-cut-function 'my/clipboard-to-wayland) (setq interprogram-paste-function 'my/clipboard-from-wayland)) ((and (getenv "DISPLAY" ) (executable-find "xclip" )) (defun my/clipboard-to-x11 (text &optional push) (let ((process-connection-type nil )) (with-temp-buffer (insert text) (call-process-region (point-min ) (point-max ) "xclip" nil nil nil "-selection" "clipboard" )))) (defun my/clipboard-from-x11 () (string-trim-right (with-output-to-string (call-process "xclip" nil standard-output nil "-selection" "clipboard" "-o" )))) (setq interprogram-cut-function 'my/clipboard-to-x11) (setq interprogram-paste-function 'my/clipboard-from-x11))) (setq package-archives '(("gnu" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/" ) ("nongnu" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/nongnu/" ) ("melpa" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/" ))) (use-package package :config (unless (bound-and-true-p package--initialized) (package-initialize ))) (setq use-package-verbose t use-package-always-ensure t use-package-minimum-reported-time 0.01 ) (use-package benchmark-init :ensure t :config (add-hook 'after-init-hook 'benchmark-init/deactivate)) (setq gc-cons-threshold (* 128 1024 1024 )) (add-hook 'after-init-hook (lambda () (setq gc-cons-threshold (* 5 1024 1024 )))) (use-package recentf :ensure t :defer 2 ) (use-package nerd-icons :defer t :custom (nerd-icons-font-family "FiraCode Nerd Font" ) ) (use-package doom-themes :ensure t :init :config (setq doom-themes-enable-bold t doom-themes-enable-italic nil ) (load-theme 'doom-tomorrow-night t ) (global-hl-line-mode 1 ) (doom-themes-visual-bell-config ) ) (use-package diredfl :ensure t :defer t :hook ((dired-mode . diredfl-mode) (dirvish-directory-view-mode . diredfl-mode)) :config (set-face-attribute 'diredfl-dir-name nil :bold t )) (setq dired-free-space nil ) (setq dired-listing-switches "-l --almost-all --human-readable --group-directories-first --no-group" ) (add-hook 'dired-mode-hook #'dired-hide-details-mode) (use-package dirvish :ensure t :config (setq dirvish-default-layout '(main preview 0.75 )) (setq dirvish-mode-line-bar-image-width 0 ) (setq dirvish-mode-line-format '(:left (sort symlink) :right (omit yank index))) (setq dirvish-attributes '(vc-state subtree-state nerd-icons git-msg) dirvish-side-attributes '(vc-state nerd-icons)) (defun my-dirvish-preview-enable-line-numbers () (unless (derived-mode-p 'dirvish-special-preview-mode) (display-line-numbers-mode 1 ))) (add-hook 'dirvish-preview-setup-hook #'my-dirvish-preview-enable-line-numbers) :hook (after-init . dirvish-override-dired-mode) :bind ("C-x C-j" . dirvish)) (use-package marginalia :defer t :vc (:url "https://github.com/minad/marginalia" :rev :newest ) :bind (:map minibuffer-local-map ("M-A" . marginalia-cycle)) :init (marginalia-mode )) (use-package nerd-icons-completion :after marginalia :config (nerd-icons-completion-mode ) (add-hook 'marginalia-mode-hook #'nerd-icons-completion-marginalia-setup)) (use-package nerd-icons-ibuffer :ensure t :config (setq nerd-icons-ibuffer-human-readable-size t ) :hook (ibuffer-mode . nerd-icons-ibuffer-mode)) (use-package ibuffer :ensure nil :config (setq ibuffer-expert t ) (setq ibuffer-display-summary nil ) (setq ibuffer-use-other-window nil ) (setq ibuffer-show-empty-filter-groups nil ) (setq ibuffer-default-sorting-mode 'filename/process) (setq ibuffer-title-face 'font-lock-doc-face) (setq ibuffer-use-header-line t ) (setq ibuffer-default-shrink-to-minimum-size nil ) (setq ibuffer-formats '((mark modified read-only locked " " (name 40 40 :left :elide) " " (size 9 -1 :right) " " (mode 16 16 :left :elide) " " filename-and-process) (mark " " (name 16 -1 ) " " filename))) (setq ibuffer-saved-filter-groups '(("Main" ("Directories" (mode . dired-mode)) ("C/C++" (or (mode . c++-mode) (mode . c++-ts-mode) (mode . c-mode) (mode . c-ts-mode) (mode . c-or-c++-ts-mode))) ("Devicetree" (or (mode . dts-mode) )) ("Python" (or (mode . python-ts-mode) (mode . c-mode) (mode . python-mode))) ("Build" (or (mode . make-mode) (mode . makefile-gmake-mode) (name . "^Makefile$" ) (mode . change-log-mode))) ("Scripts" (or (mode . shell-script-mode) (mode . shell-mode) (mode . sh-mode) (mode . lua-mode) (mode . bat-mode))) ("Config" (or (mode . conf-mode) (mode . conf-toml-mode) (mode . toml-ts-mode) (mode . conf-windows-mode) (name . "^\\.clangd$" ) (name . "^\\.gitignore$" ) (name . "^Doxyfile$" ) (name . "^config\\.toml$" ) (mode . yaml-mode))) ("Web" (or (mode . mhtml-mode) (mode . html-mode) (mode . web-mode) (mode . nxml-mode))) ("CSS" (or (mode . css-mode) (mode . sass-mode))) ("JS" (or (mode . js-mode) (mode . rjsx-mode))) ("Markup" (or (mode . markdown-mode) (mode . adoc-mode))) ("Org" (mode . org-mode)) ("LaTeX" (name . "\.tex$" )) ("Magit" (or (mode . magit-blame-mode) (mode . magit-cherry-mode) (mode . magit-diff-mode) (mode . magit-log-mode) (mode . magit-process-mode) (mode . magit-status-mode))) ("Apps" (or (mode . elfeed-search-mode) (mode . elfeed-show-mode))) ("Claude Code" (and (mode . vterm-mode) (name . "^\\*claude\\*$" ))) ("Fundamental" (or (mode . fundamental-mode) (mode . text-mode))) ("Emacs" (or (mode . emacs-lisp-mode) (name . "^\\*Help\\*$" ) (name . "^\\*Custom.*" ) (name . "^\\*Org Agenda\\*$" ) (name . "^\\*info\\*$" ) (name . "^\\*scratch\\*$" ) (name . "^\\*Backtrace\\*$" ) (name . "^\\*Messages\\*$" )))))) :hook (ibuffer-mode . (lambda () (ibuffer-switch-to-saved-filter-groups "Main" ))) ) (use-package doom-modeline :ensure t :custom (doom-modeline-buffer-file-name-style 'truncate-except-project) (doom-modeline-env-version t ) (doom-modeline-major-mode-icon t ) :init (doom-modeline-mode 1 )) (use-package undo-tree :ensure t :init (global-undo-tree-mode ) :config (setq undo-tree-history-directory-alist `(("." . "~/.emacs.d/.cache" ))) ) (use-package amx :ensure t :defer t :init (amx-mode )) (use-package exec-path-from-shell :ensure t :init :config (when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize ))) (use-package magit :ensure t :defer t :bind (("C-x g" . magit-status)) ) (use-package markdown-mode :ensure t :defer t :mode ("\\.md\\'" . markdown-mode) :init (setq markdown-command "pandoc" ) (add-to-list 'auto-mode-alist '("README\\'" . markdown-mode)) (add-to-list 'auto-mode-alist '("readme\\'" . markdown-mode)) (add-to-list 'auto-mode-alist '("[Rr]eadme\\(?:\\.md\\)?\\'" . markdown-mode))) (use-package dts-mode :ensure t :defer t ) (use-package tree-sitter :ensure t :config (setq treesit-font-lock-level 4 ) (setq treesit-language-source-alist '((bash . ("https://github.com/tree-sitter/tree-sitter-bash" "v0.20.0" )) (c . ("https://github.com/tree-sitter/tree-sitter-c" "v0.21.3" )) (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp" )) (python . ("https://github.com/tree-sitter/tree-sitter-python" )) (rust . ("https://github.com/tree-sitter/tree-sitter-rust" )) (toml . ("https://github.com/tree-sitter/tree-sitter-toml" )) (elisp . ("https://github.com/Wilfred/tree-sitter-elisp" )) (cmake . ("https://github.com/uyha/tree-sitter-cmake" )) (dockerfile . ("https://github.com/camdencheek/tree-sitter-dockerfile" )) (make . ("https://github.com/alemuller/tree-sitter-make" )) (yaml . ("https://github.com/ikatyang/tree-sitter-yaml" )) (json . ("https://github.com/tree-sitter/tree-sitter-json" )) (java . ("https://github.com/tree-sitter/tree-sitter-java" )) (html . ("https://github.com/tree-sitter/tree-sitter-html" )) (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" )) (css . ("https://github.com/tree-sitter/tree-sitter-css" )) (go . ("https://github.com/tree-sitter/tree-sitter-go" )) )) (add-to-list 'auto-mode-alist '("\\.c\\.[^/]*\\'" . c-ts-mode)) (add-to-list 'auto-mode-alist '("\\.include\\.[^/]*\\'" . c-ts-mode)) (add-to-list 'auto-mode-alist '("\\.y[a]?ml\\'" . yaml-ts-mode)) (add-to-list 'auto-mode-alist '("\\(?:Dockerfile\\(?:\\..*\\)?\\|\\.[Dd]ockerfile\\)\\'" . dockerfile-ts-mode)) (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode)) (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)) (add-to-list 'auto-mode-alist '("\\.js\\'" . js-ts-mode)) ) (run-with-idle-timer 3 nil (lambda () (dolist (lang '(bash c cpp python rust toml elisp cmake dockerfile make yaml json java html javascript css go)) (unless (treesit-language-available-p lang) (treesit-install-language-grammar lang))))) (setq major-mode-remap-alist '((bash-mode . bash-ts-mode) (c-mode . c-ts-mode) (c++-mode . c++-ts-mode) (python-mode . python-ts-mode) ;;(rust-mode . rust-ts-mode) (conf-toml-mode . toml-ts-mode) (elisp-mode . elisp-ts-mode) (cmake-mode . cmake-ts-mode) ;;(dockerfile-mode . dockerfile-ts-mode) (json-mode . json-ts-mode) (java-mode . java-ts-mode) ;;(yaml-mode . yaml-ts-mode) (makefile-mode . makefile-ts-mode) (mhtml-mode . html-ts-mode) (html-mode . html-ts-mode) ;;(js-mode . js-ts-mode) (css-mode . css-ts-mode) ;;(go-mode . go-ts-mode) )) (defun my-c-cpp-indent-setup () "Customize C/C++ mode." (setq c-ts-mode-indent-offset 8 ) (setq c-ts-mode-indent-style 'linux)) (dolist (hook '(c-mode-hook c++-mode-hook c-ts-mode-hook c++-ts-mode-hook)) (add-hook hook #'my-c-cpp-indent-setup)) (use-package eglot :ensure t :defer 1 :config (setq eglot-server-programs '(((c-mode-hook c++-mode-hook c++-ts-mode c-ts-mode) . ("clangd" ;; "-j=4" "--enable-config" "--background-index" ;; "--background-index-priority=low" "--clang-tidy" "--completion-style=detailed" "--ranking-model=decision_forest" "--header-insertion=never" ;; "--all-scopes-completion" "--pretty" ;; "--fallback-style=none" ;;"--query-driver=aarch64-linux-gnu-*" ;;"--query-driver=gcc,g++" "--query-driver=/usr/bin/g++,/usr/bin/gcc" )) ((dts-mode) . ("devicetree-language-server" "--stdio" )) ((rust-mode rust-ts-mode) . ("rust-analyzer" :initializationOptions (:cargo (:buildScripts (:enable t )) :procMacro (:enable t )))) ((python-mode python-ts-mode) . ("pyright-langserver" "--stdio" )) ;; ((bash-mode bash-ts-mode sh-mode sh-ts-mode) . ("bash-language-server" "start" )) ;; ((toml-mode toml-ts-mode) . ("taplo" "lsp" "stdio" )) ;; ((yaml-mode yaml-ts-mode) . ("yaml-language-server" "--stdio" )) ;; ((markdown-mode markdown-ts-mode) . ("marksman" )) )) (setq eglot-ignored-server-capabilities '(:documentOnTypeFormattingProvider )) ) (dolist (hook '(c-mode-hook c-ts-mode-hook c++-mode-hook c++-ts-mode-hook dts-mode-hook rust-mode-hook rust-ts-mode-hook python-mode-hook python-ts-mode-hook ;;bash-mode-hook bash-ts-mode-hook ;;sh-mode-hook sh-ts-mode-hook ;; markdown-mode-hook markdown-ts-mode-hook ;; toml-mode-hook toml-ts-mode-hook ;; yaml-mode-hook yaml-ts-mode-hook )) (add-hook hook 'eglot-ensure)) (global-set-key (kbd "M-," ) 'xref-find-definitions) (global-set-key (kbd "M-." ) 'xref-pop-marker-stack) (global-set-key (kbd "M-?" ) 'xref-find-references) (defun my-cpp-line-comments () "Use // comments instead of /* */ in C/C++." (setq-local comment-start "// " comment-end "" comment-start-skip "//+\\s-*" )) (dolist (hook '(c-mode-hook c++-mode-hook c-ts-mode-hook c++-ts-mode-hook rust-mode-hook rust-ts-mode-hook python-mode-hook python-ts-mode-hook java-mode-hook java-ts-mode-hook)) (add-hook hook #'my-cpp-line-comments)) (use-package yasnippet :ensure t :hook (after-init . yas-global-mode) :config ) (use-package company :defer 1 :ensure t :hook (after-init . global-company-mode) :config (setq company-idle-delay 0 ) (setq company-backends '((company-capf :with company-yasnippet) company-keywords company-files)) (setq company-minimum-prefix-length 1 ) (setq company-tooltip-limit 30 ) (setq eldoc-idle-delay 0.3 ) (add-hook 'gud-mode-hook (lambda () (company-mode -1 ))) (add-hook 'eshell-mode-hook (lambda () (company-mode -1 ))) ) (use-package format-all :ensure t :defer t :commands format-all-mode :config (setq-default format-all-formatters '(("C" (clang-format)) ("C++" (clang-format)) ;; ("Java" (clang-format)) ("Rust" (rustfmt)) ("JavaScript" (prettier)) ("Markdown" (prettier)) ("YAML" (prettier)) ;;("TOML" (taplo-fmt)) ;;("Devicetree" (dtsfmt)) ))) (global-set-key (kbd "C-x f" ) 'format-all-buffer) (use-package inheritenv :vc (:url "https://github.com/purcell/inheritenv" :rev :newest )) (use-package monet :vc (:url "https://github.com/stevemolitor/monet" :rev :newest )) (use-package vterm :ensure t ) (use-package claude-code :ensure t :vc (:url "https://github.com/stevemolitor/claude-code.el" :rev :newest ) :config (add-hook 'claude-code-process-environment-functions #'monet-start-server-function) (monet-mode 1 ) (setq claude-code-terminal-backend 'vterm) (claude-code-mode ) :bind-keymap ("C-c c" . claude-code-command-map) :bind (:repeat-map my-claude-code-map ("M" . claude-code-cycle-mode))) (use-package which-key :ensure t :defer t :config (which-key-mode )) (use-package ace-window :ensure t :defer t :bind (("M-o" . ace-window))) (use-package buffer-move :ensure t :defer t :bind (("C-c <up>" . buf-move-up) ("C-c <down>" . buf-move-down) ("C-c <left>" . buf-move-left) ("C-c <right>" . buf-move-right))) (use-package crux :ensure t :defer t :bind (("C-a" . 'crux-move-beginning-of-line) ("C-c k" . 'crux-smart-kill-line))) (use-package goto-line-preview :ensure t :defer t :bind (("M-g g" . goto-line-preview))) (use-package move-dup :ensure t :defer t :bind (("C-M-p" . move-dup-move-lines-up) ("C-M-n" . move-dup-move-lines-down) )) (setq project-find-functions nil ) (use-package projectile :ensure t :config (projectile-mode +1 ) (setq projectile-enable-caching t ) (setq projectile-project-search-path '("~/repository" )) (setq projectile-completion-system 'auto) (use-package rg :defer t :ensure t )) (use-package multiple-cursors :ensure t :config (global-set-key (kbd "C-c m" ) 'mc/mark-all-dwim)) (global-set-key (kbd "M-n" ) #'flymake-goto-next-error) (global-set-key (kbd "M-p" ) #'flymake-goto-prev-error) (global-set-key (kbd "M-<up>" ) 'enlarge-window) (global-set-key (kbd "M-<down>" ) 'shrink-window) (global-set-key (kbd "M-<left>" ) 'shrink-window-horizontally) (global-set-key (kbd "M-<right>" ) 'enlarge-window-horizontally) (global-set-key (kbd "C-/" ) 'undo-only) (global-set-key (kbd "C-c C-s" ) 'projectile-ripgrep) (defun k-insert-timestamp () (interactive ) (insert (format-time-string "%Y-%m-%d %H:%M" ))) (defun k-insert-date () (interactive ) (insert (format-time-string "%Y-%m-%d" ))) (global-set-key (kbd "C-c t" ) 'k-insert-timestamp) (global-set-key (kbd "C-c d" ) 'k-insert-date) (global-unset-key (kbd "C-x C-b" )) (global-set-key (kbd "C-x C-b" ) 'ibuffer) (global-set-key (kbd "TAB" ) 'tab-to-tab-stop) (global-set-key (kbd "C-x k" ) (lambda () (interactive ) (kill-this-buffer ))) (add-hook 'prog-mode-hook (lambda () (local-set-key (kbd "C-c p" ) #'flymake-show-buffer-diagnostics) (local-set-key (kbd "C-c f" ) #'eglot-code-actions))) (custom-set-variables '(package-selected-packages nil) '(package-vc-selected-packages '((claude-code :url "https://github.com/stevemolitor/claude-code.el" )))) (custom-set-faces )
Shortcut Key Configuration Overview “C” in Emacs representsCtrl
“M” in Emacs representsAlt
Shortcut Key Function Description Source Configuration C-/ Undo (undo-only) Manual Binding M-<up> Increase current window height Manual Binding M-<down> Decrease current window height Manual Binding M-<left> Decrease current window width Manual binding M-<right> Increase current window width Manual binding C-<left> Switch to previous tab (Centaur Tabs) centaur-tabsC-<right> Switch to next tab centaur-tabsM-g g Preview jump to specified line (goto-line-preview) goto-line-previewM-C-p Move current line up move-dupM-C-n Move current line down move-dupM-p Next error flymakeM-n Previous error flymakeC-c p Show all errors flymakeC-c f Fix code using LSP (eglot-code-actions) eglotC-x C-j Open file browser (dirvish) dirvishC-x C-f Find file and open Built-in C-x C-b Open buffer browser IbufferC-x g magit status magitC-x f Format current buffer (clang-format / rustfmt) format-allM-, Jump to definition (xref-find-definitions, requires LSP support) Manual binding M-. Jump back to previous position (xref-pop-marker-stack) Manual binding M-? Find references (xref-find-references, requires LSP support) Manual binding M-o Switch focus between multiple windows ace-windowC-c <up> Move current buffer up to another window buffer-moveC-c <down> Move current buffer down to another window buffer-moveC-c <left> Move current buffer left to another window buffer-moveC-c <right> Move current buffer right to another window buffer-moveC-a Smart move cursor to beginning of line (press again to go to code start) cruxC-c k Smart delete a line (does not break indentation) cruxC-x SPC Rectangle selection mode, can select certain columns Built-in M-< Move to beginning of buffer Built-in M-> Move to end of buffer Built-in C-c t Insert timestamp Manual binding C-c d Insert date Manual binding C-x u Open undo-tree undo-tree
M-X projectile-ripgrep Global search with ripgrepC-c C-s Global search in projectM-x recenter Center current line in windowM-x eglot-rename Rename symbol while programmingM-x man , then enter the function to search for, e.g.shmget(2)where 2 means search for syscall, then in*Man*buffer, use: M-n → next man pageM-p → previous man pageThe following key operations are available:
Key Function EnterorfSwitch to the buffer at the cursor line oSwitch to that buffer and keep*Buffer List* dMark this buffer as “to be deleted” (not immediately deleted) xActually delete all marked bufferssSave this buffer (if modified) uUnmark (if previously pressedd) qClose*Buffer List*Window gRefresh list (reload latest status)
After marking deletion with d, press x to actually delete
magit Magit’s design philosophy is:One key = one action 。
Key Function sStage File/region under cursor (equivalent togit add)uUnstage (Unstage)cCommit (Commit) → then presscConfirmPPush Push to remoteFFetch Pull updates from remotepPull (Pull and merge)bBranch operations (create/switch/merge) lViewlog (Commit history) LView log with graph (similar togit log --graph) dDiff View changes=Press on commit=View diff of that commit qQuit Close current Magit buffer
⚠️ Note: These commands are only valid in the Magit status buffer (*magit: xxx*) !
After pressing a key, press Ctrl-g to cancel
Programming settings For projects with a Makefile, use bear to generate compile_commands.json for clangd indexing
1 2 3 4 5 6 touch .projectilemake clean bear -- make
For Linux kernel related settings, refer to
Directly used the Linux Kernel configuration, but used spaces instead of tabs, and increased ColumnLimit to 100
.clang-format 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 --- AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: false AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: None AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: false BinPackArguments: true BinPackParameters: true BraceWrapping: AfterClass: false AfterControlStatement: false AfterEnum: false AfterFunction: true AfterNamespace: true AfterObjCDeclaration: false AfterStruct: false AfterUnion: false AfterExternBlock: false BeforeCatch: false BeforeElse: false IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true BreakBeforeBinaryOperators: None BreakBeforeBraces: Custom BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: false BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeComma BreakAfterJavaFieldAnnotations: false BreakStringLiterals: false ColumnLimit: 100 CommentPragmas: "^ IWYU pragma:" CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 8 ContinuationIndentWidth: 8 Cpp11BracedListStyle: false DerivePointerAlignment: false DisableFormat: false ExperimentalAutoDetectBinPacking: false FixNamespaceComments: false IncludeBlocks: Preserve IncludeCategories: - Regex: ".*" Priority: 1 IncludeIsMainRegex: "(Test)?$" IndentCaseLabels: false IndentGotoLabels: false IndentPPDirectives: None IndentWidth: 8 IndentWrappedFunctionNames: false JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: "" MacroBlockEnd: "" MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBinPackProtocolList: Auto ObjCBlockIndentWidth: 8 ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true PenaltyBreakAssignment: 10 PenaltyBreakBeforeFirstCallParameter: 30 PenaltyBreakComment: 10 PenaltyBreakFirstLessLess: 0 PenaltyBreakString: 10 PenaltyExcessCharacter: 100 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Right ReflowComments: false SortIncludes: false SortUsingDeclarations: false SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatementsExceptForEachMacros SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: false SpacesInContainerLiterals: false SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp03 TabWidth: 8 UseTab: false
Run Emacs as a daemon systemd Requires systemd
1 2 systemctl --user enable --now emacs emacsclient file.txt
Shell 1 2 emacs --daemon emacsclient file.txt
After finishing editing, pressCtrl +x , then# to exit, Emacs will mark the buffer as finished, and then emacsclient will exit. If no other buffers are in use, the LSP (e.g., clangd) started for that buffer will also exit.
But if you pressCtrl +x to exit, thenc , Emacs will consider that this buffer cannot be closed yet