时间轴

2025-12-29

init


wsl下载ubuntu

1
2
3
4
# 查看可以下载的镜像
wsl --list --online
# 下载ubuntu20.04
wsl --install Ubuntu-20.04

迁移到D盘

在D盘创建一个目录用来存放新的WSL,比如D:\WSL\Ubuntu-20.04

1
2
3
4
5
6
7
# 1. 导出它的备份(比如命名为Ubuntu.tar)
wsl --export Ubuntu-20.04 D:\WSL\Ubuntu-20.04.tar
# 2. 注销原来的
wsl --unregister Ubuntu-20.04
# 3. 将备份文件恢复到D:\WSL\Ubuntu-20.04中去
wsl --import Ubuntu-20.04 D:\WSL\Ubuntu-20.04 D:\WSL\Ubuntu-20.04.tar
# 这时候可以把Ubuntu-20.04.tar删除了

如果这时候启动WSL,发现好像已经恢复正常了,但是用户变成了root。用以下命令恢复:

1
Ubuntu2004 config --default-user username

安装最新版emacs

1
2
3
4
5
6
7
8
9
10
# Optional: 卸载snapd
sudo apt-get purge snapd

# 下载emacs源码
wget https://mirrors.ustc.edu.cn/gnu/emacs/emacs-30.2.tar.xz
cd emacs
sudo apt install zlib1g-dev libgccjit-9-dev pkg-config libgnutls28-dev
./configure --without-x --without-ns --without-pgtk --with-native-compilation --with-threads --prefix=/usr/local
make -j$(nproc)
sudo make install
  • --without-x emacs-nox,不使用 X11(Xorg),只能用 emacs -nw(终端)
  • --without-ns 禁用 macOS 的 Cocoa / NS 窗口系统,只是防止 configure 自动探测到 macOS GUI
  • --without-pgtk 禁用 Pure GTK(Wayland 下的新 GUI 后端)
  • --with-native-compilation 启用 native-comp(.eln)将Elisp 编译成机器码
  • --with-threads启用 多线程支持
  • --prefix=/usr/local安装到 /usr/local

treesitter问题
参考下面这个修改,主要是ABI版本不匹配的问题,降低版本即可。

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
(use-package tree-sitter
:ensure t
;; :when (and (fboundp 'treesit-available-p)
;; (treesit-available-p))
:config
(setq treesit-font-lock-level 4)
;;:init
(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" "v0.20.4"))
(rust . ("https://github.com/tree-sitter/tree-sitter-rust" "v0.20.3"))
(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"))
))

;;没有内置<languate>-mode的需要添加
(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))
)

;; 安装 tree-sitter 语法解析器(仅 Emacs 29+)
;; (run-with-idle-timer 3 nil ; 启动后3秒空闲时执行
;; (lambda ()
;; (dolist (lang '(bash c cpp python rust toml cmake dockerfile make yaml json))
;; (unless (treesit-language-available-p lang)
;; (treesit-install-language-grammar lang)))))

;; 优先使用 Tree-sitter mode
(setq major-mode-remap-alist
'((bash-mode . bash-ts-mode)
(sh-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)
(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)
))

另外通过apt下载的clangd版本比较老,可能不支持某些配置项,参考下面修改

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
(use-package eglot
:ensure t
:defer 1
:config
(setq eglot-server-programs
'(((c++-mode c-mode c++-ts-mode c-ts-mode) . ("clangd"
;;"-j=4"
;; "--enable-config"
"--background-index"
;; "--background-index-priority=low"
"--clang-tidy"
"--completion-style=detailed"
"--header-insertion=never"
"--all-scopes-completion"
"--pretty"
"--fallback-style=none"
;;"--query-driver=aarch64-linux-gnu-*"
;;"--query-driver=gcc,g++"
))
((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"))

))

;; 关闭lsp自动格式化
(setq eglot-ignored-server-capabilities '(:documentOnTypeFormattingProvider))
)

参考