使 hunspell 使用 emacs 和德语

stu*_*ent 9 emacs spell-checking hunspell

我想hunspell在 ubuntu 13.04-box 上使用 emacs24 和德语词典。

要做到这一点我安装hunspellhunspell-de并添加以下到我的.emacs文件:

(setq ispell-program-name "hunspell")
(setq ispell-dictionary "deutsch8")
Run Code Online (Sandbox Code Playgroud)

当我在 emacs 中打开一个文件并启动时,flyspell-buffer我得到了Starting new Ispell process [[hunspell::deutsch8]]但它阻塞了 emacs 缓冲区(鼠标变成了一个旋转磁盘,指示等待)并且无休止地工作而不显示任何结果。所以我的配置肯定有问题。

没有第二行它可以工作,但仅适用于英文文本。

那么什么是设置的最佳方式hunspellemacs24在Ubuntu 13.04德语字典?是否有任何可能的陷阱?

小智 7

要检查字典是否在路径中列出,请运行hunspell -D。它应该沿着这些线输出一些东西:

...
/usr/share/hunspell/en_US
/usr/share/hunspell/de_BE
/usr/share/hunspell/de_LU
/usr/share/hunspell/de_DE
...
Run Code Online (Sandbox Code Playgroud)

接下来,将您的首选词典添加到ispell-local-dictionary-alist您的.emacs文件中

(add-to-list 'ispell-local-dictionary-alist '("deutsch-hunspell"
                                              "[[:alpha:]]"
                                              "[^[:alpha:]]"
                                              "[']"
                                              t
                                              ("-d" "de_DE"); Dictionary file name
                                              nil
                                              iso-8859-1))

(add-to-list 'ispell-local-dictionary-alist '("english-hunspell"
                                              "[[:alpha:]]"
                                              "[^[:alpha:]]"
                                              "[']"
                                              t
                                              ("-d" "en_US")
                                              nil
                                              iso-8859-1))

(setq ispell-program-name "hunspell"          ; Use hunspell to correct mistakes
      ispell-dictionary   "deutsch-hunspell") ; Default dictionary to use
Run Code Online (Sandbox Code Playgroud)

除此之外,您可以定义一个函数来在德语和英语词典之间切换并将其绑定到C-c d例如

(defun switch-dictionary-de-en ()
  "Switch german and english dictionaries."
  (interactive)
  (let* ((dict ispell-current-dictionary)
         (new (if (string= dict "deutsch-hunspell") "english-hunspell"
                   "deutsch-hunspell")))
    (ispell-change-dictionary new)
    (message "Switched dictionary from %s to %s" dict new)))

(global-set-key (kbd "C-c d") 'switch-dictionary-de-en)
Run Code Online (Sandbox Code Playgroud)

  • 谢谢。我认为您应该在 `(add-to-list 'ispell-local...)` 行之前添加一个 `(require 'ispell)`。 (5认同)
  • 我认为如果我为那些可能会陷入这种境地的 Windows 用户添加一点评论,也不会受到伤害。在 Windows 中,Emacs 将 `LANG` 环境变量设置为区域设置。将 `(setenv "LANG" "en_US")` 之类的内容添加到您的 init 文件中是个好主意。这将是您的初始字典,除非您更改它。默认的“LANG”值可能设置为一些可能很奇怪的东西(比如“ENG”),从而产生 ispell/hunspell 错误。 (2认同)