Emacs flyspell

2026-03-19 12:54:555min

flyspell 是 Emacs 內建的一個拼寫撿查工具,它可以在 Emacs q寫做的時候,即時的撿查拼寫問題。

安裝 aspell

flyspell 使用 Emacs 的 ispell,ispell 是一個前端,後端可以接 aspell 或是 hunspell 。 這次安裝選擇使用 aspell

aspell 可以在任何 Linux 發行版的套件管理工具取得。我這次使用 nix 安裝。

nix profile add nixpkgs#aspell
nix profile add nixpkgs#aspellDicts.en # 一併安裝 en 字典檔  

設定 Emacs

~/init.el

(setq ispell-program-name "aspell")
(setq ispell-dictionary "en_US")
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)

ispell-program-name 設定 ispell 的後端。 ispell-dictionary 設定預設的字檔。

疑難排解 - 找不到 dictionary

似乎是 aspell 在 nix 上安裝方式與預設不同產生的問題,Emacs 會顯示找不到字典檔。

Error enabling Flyspell mode: (Error: The file
\"/nix/store/facmzwl5kr45f2i6gi6adx4i3vpw6nsz-aspell-0.60.8.1/lib/aspell/en~US~\"
can not be opened for reading.) Starting new Ispell process aspell with
en~US~ dictionary... \\ Starting new Ispell process aspell with en~US~
dictionary...done 

目前的 workaround solution,可以使用 ~/.aspell.conf ,告訴 aspell 字典檔的位置。

vi \~/.aspell.conf
dict-dir *home/howard*.nix-profile/lib/aspell 

留言