题
我想在Emacs中使用ispell-buffer命令。它默认使用英语。有没有一种简单的方法可以切换到另一个字典(例如,另一种语言)?
解决方案
以下命令建议使用的已安装词典列表:
M-x ispell-change-dictionary
通常, M-x isp-c-d
也会扩展到上面。
其他提示
从文件ispell.el中,您可以为 ispell
命令指定一些选项。这是通过在文件末尾添加一个部分来实现的:
;; Local Variables:
;; ispell-check-comments: exclusive
;; ispell-local-dictionary: "american"
;; End:
请注意,双分号标记当前模式中注释的开头。它应该被改变以反映您的文件(编程语言)引入注释的方式,例如Java的 //
。
在LaTeX文件的末尾,您可以使用:
%%% Local Variables:
%%% ispell-local-dictionary: "british"
%%% End:
将设置字典仅用于该文件。
使用 M-x ispell-change-dictionary
并点击 TAB
查看可用的字典。
然后在 .emacs
中编写默认字典设置,并为特定模式自动添加一个启动ispell的挂钩(如果需要)。
例如,使用英式英语自动启动AUCTeX中的ispell(默认情况下英语词典是美式英语)
(add-hook 'LaTeX-mode-hook 'flyspell-mode) ;start flyspell-mode
(setq ispell-dictionary "british") ;set the default dictionary
(add-hook 'LaTeX-mode-hook 'ispell) ;start ispell
如果要基于每个目录更改语言,可以将其添加到 .dir-locals.el
文件中:
(ispell-local-dictionary . "american")
如果您还没有 .dir-locals.el
文件,它将如下所示:
((nil .
((ispell-local-dictionary . "american")))
)
有关详细信息,请参阅有关目录变量的emacs wiki页面。
为方便起见(f7),我将以下内容添加到我的.emacs中:
(global-set-key [f7] 'spell-checker)
(require 'ispell)
(require 'flyspell)
(defun spell-checker ()
"spell checker (on/off) with selectable dictionary"
(interactive)
(if flyspell-mode
(flyspell-mode-off)
(progn
(flyspell-mode)
(ispell-change-dictionary
(completing-read
"Use new dictionary (RET for *default*): "
(and (fboundp 'ispell-valid-dictionary-list)
(mapcar 'list (ispell-valid-dictionary-list)))
nil t))
)))
BTW:别忘了安装所需的词典。例如。 on debian / ubuntu,德语和英语词典:
sudo apt install aspell-de aspell-en
不隶属于 StackOverflow