WSL2中安装使用GUI的Emacs全过程(2023.11)

Table of Contents

  1. WSL2配置debian
    1. 需要启用的Windows功能
    2. 配置Debian
      1. 换源
      2. 安装emacs-pgtk及相关软件
      3. 安装emacs-rime
  2. 为什么选择WSLg里的Emacs GUI而非Windows原生Emacs

WSL2配置debian

需要启用的Windows功能

  • Hyper-V
  • Windows虚拟机监控程序平台
  • 适用于Linux的Windows子系统
  • 虚拟机平台

在Windows的用户目录 %USERPROFILE% 下面创建一个配置文件 .wslconfig,写入以下内容:

[experimental]
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true

配置Debian

用户名:USERNAME

密码:USERPASSWD

换源

sudo nano /etc/apt/sources.list

deb http://mirrors.tuna.tsinghua.edu.cn/debian/ sid main contrib non-free non-free-firmware

sudo apt update && sudo apt install apt-transport-https ca-certificates

#https源
sudo nano /etc/apt/sources.list

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ sid main contrib non-free non-free-firmware

sudo apt install locale

sudo dpkg-reconfigure locales

安装emacs-pgtk及相关软件

sudo apt install emacs-pgtk  wl-clipboard 

#以下可选
sudo apt install ssh git fonts-cascadia-code wget ripgrep libvterm-dev

ssh-keygen -t ed25519 -C "YOUREMAIL"

clip.exe < ~/.ssh/id_ed25519.pub

nano ~/.ssh/config

Host github.com
  HostName ssh.github.com
  User git
  Port 443

git clone [email protected]:YOUR_EMACSD_GIT_REPO

#以下可选,下载HarmonyOS Sans SC 中文字体
wget -e "https_proxy=http://127.0.0.1:7890" https://github.com/uniartisan/fonts-harmonyos-sans-cn/raw/main/harmonyos_sans.deb

sudo apt install ./harmonyos_sans.deb

git config --global user.name "TomoeMami"
git config --global user.email "[email protected]"

安装emacs-rime

sudo apt install librime-dev

(use-package rime
  :custom
  (default-input-method "rime")
  (rime-show-candidate 'posframe)
  :bind
  ("C-\\" . toggle-input-method)
  )

为什么选择WSLg里的Emacs GUI

  • Emacs在Linux下更顺滑
  • 输入法与Windows的Emacs配合不是很好,涉及到Shift+Alt的按键输入法会识别成长按Shift导致切换中英文状态
    • 配置好Linux下的Emacs之后就不用在Windows里取消输入法的Shift切换中英文了
  • Linux原生的命令行工具更顺手
  • WSL 2.0 可用性大幅提升,可以镜像主机网络,直接通过127.0.0.1访问主机运行的程序

相关链接

5 个赞