使用ispell时如何更改Emacs中的语言?

时间:2008-10-20 13:55:07

标签: emacs ispell

我想在Emacs中使用ispell-buffer命令。它默认使用英语。有没有一种简单的方法可以切换到另一个字典(例如,另一种语言)?

6 个答案:

答案 0 :(得分:42)

以下命令建议使用的已安装词典列表:

M-x ispell-change-dictionary

通常,M-x isp-c-d也会扩展到上面。

答案 1 :(得分:24)

从ispell.el文件中,您可以为ispell命令指定一些选项。这是通过在文件末尾添加一个部分来实现的:

;; Local Variables:
;; ispell-check-comments: exclusive
;; ispell-local-dictionary: "american"
;; End:

请注意,双分号标记当前模式中注释的开头。它应该被更改以反映您的文件(编程语言)引入注释的方式,例如Java的//

答案 2 :(得分:15)

在LaTeX文件的末尾,您可以使用:

%%% Local Variables:
%%% ispell-local-dictionary: "british"
%%% End:

将设置字典仅用于该文件。

答案 3 :(得分:10)

使用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

答案 4 :(得分:2)

如果要基于每个目录更改语言,可以将其添加到(ispell-local-dictionary . "american") 文件中:

.dir-locals.el

如果您还没有((nil . ((ispell-local-dictionary . "american"))) ) 个文件,它将如下所示:

[jay@rhbd gopath]$ go get github.com/golang/example/hello
package github.com/golang/example/hello
        imports fmt: unrecognized import path "fmt"
package github.com/golang/example/hello
        imports runtime: unrecognized import path "runtime"

有关详细信息,请参阅emacs wiki page about directory variables

答案 5 :(得分:1)

为方便起见(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))
      )))

顺便说一句:不要忘记安装所需的词典。例如。在debian / ubuntu上,用于德语和英语词典:

sudo apt install aspell-de aspell-en