【发布时间】:2021-01-10 14:45:52
【问题描述】:
Windows 7、Emacs 25.1
我需要“即时”对我的自定义文本进行拼写检查(例如,强调不正确的单词)。但我用两种语言编写文本:英语和俄语。而且我想在两种语言的拼写检查之间轻松切换。
最好的 emacs 包是什么?谢谢。
【问题讨论】:
标签: emacs
Windows 7、Emacs 25.1
我需要“即时”对我的自定义文本进行拼写检查(例如,强调不正确的单词)。但我用两种语言编写文本:英语和俄语。而且我想在两种语言的拼写检查之间轻松切换。
最好的 emacs 包是什么?谢谢。
【问题讨论】:
标签: emacs
你想要这个:guess_language.el
(use-package guess-language ; Automatically detect language for Flyspell
:ensure t
:defer t
:init (add-hook 'text-mode-hook #'guess-language-mode)
:config
(setq guess-language-langcodes '((en . ("en_GB" "English"))
(it . ("it_IT" "Italian")))
guess-language-languages '(en it)
guess-language-min-paragraph-length 45)
:diminish guess-language-mode)
或者,如果您只想循环浏览它们:
(defvar mu-languages-ring nil "Languages ring for Ispell")
(let ((languages '("en_GB" "it_IT")))
(validate-setq mu-languages-ring (make-ring (length languages)))
(dolist (elem languages) (ring-insert mu-languages-ring elem)))
(defun mu-cycle-ispell-languages ()
(interactive)
(let ((language (ring-ref mu-languages-ring -1)))
(ring-insert mu-languages-ring language)
(ispell-change-dictionary language)))
这些应该与FlySpell一起使用
【讨论】:
guess-language 配置示例已被证明非常有用,谢谢 :-) Fedora 的 aspell-it 软件包用户(可能还有其他人)的说明:起初我遇到了一个错误,为了让它工作我必须在guess-language-langcodes 中使用"it" 而不是"it_IT"。
我遇到了类似的问题,我找到的解决方案是同时管理两种或多种语言,而不使用guess_language 包。此解决方案基于 Hunspell 拼写检查器。
系统: Windows 7 SP1,GNU Emacs 26.1
首先,在安装 Hunspell 后执行 Ispell/Hunspell 配置。在 .emacs 文件中插入下一个代码,该文件通常位于 C:/Users/Account 中。
;; START BLOCK1 <-- Ispell/Hunspell setting
;; e.g., "C:/Hunspell/bin/hunspell.exe"
(setq-default ispell-program-name "hunspell.exe FULL PATH")
(setq-default ispell-extra-args '("--sug-mode=ultra"))
;; Set "DICTDIR" variable, e.g., "C:/Hunspell/share/hunspell"
(setenv "DICTDIR" "hunspell DICTIONARY PATH")
;; Uncomment next line to set English or another dictionary
;; (setq ispell-dictionary "en_US")
;; Automatically enable flyspell-mode in text-mode
(setq text-mode-hook '(lambda() (flyspell-mode t) ))
(require 'ispell)
;; END BLOCK1 <-- Ispell/Hunspell setting
此代码基于另一个讨论的拼写配置部分,请参阅M Parashar - Load Theme。块代码 1 适用于默认字典,可以使用 ispell-dictionary 变量取消注释行来更改它。这段代码非常适合我。
第二个代码块使我们能够使用多个字典,它基于AM Lafon - Multi Spell Checking。对我来说,此代码块仅适用于代码块 1 的下一个。
;;START BLOCK2<-- Multiple dictionaries. Only works with BLOCK1
(with-eval-after-load "ispell"
;; Configure `LANG`, otherwise ispell.el cannot find a 'default
;; dictionary' even though multiple dictionaries will be configured
;; in next line.
(setenv "LANG" "es_ES")
;; English/spanish configuration.
(setq ispell-dictionary "en_US,es_ES")
;; ispell-set-spellchecker-params has to be called
;; before ispell-hunspell-add-multi-dic will work
(ispell-set-spellchecker-params)
(ispell-hunspell-add-multi-dic "en_US,es_ES")
;; For saving words to the personal dictionary, don't infer it from
;; the locale, otherwise it would save to ~/.hunspell_de_DE.
(setq ispell-personal-dictionary "~/.hunspell_personal"))
;; The personal dictionary file has to exist, otherwise hunspell will
;; silently not use it.
(unless (file-exists-p ispell-personal-dictionary)
(write-region "" nil ispell-personal-dictionary nil 0))
;;END BLOCK2<-- Multiple dictionaries. Only works with BLOCK1
这两个代码块可以同时对英语/西班牙语进行拼写检查。可以将更多语言添加到检查系统中,使用适当的字典名称扩展“en_US,es_ES”字符串。我使用了位于 Share/Hunspell 目录中的那些。语言之间没有键绑定,文件开头也没有每个文件的字典分配,如下所示:
# -\*- ispell-dictionary: "castellano8" -\*-.
在拼写错误的单词上单击鼠标中键时会显示一个上下文菜单,其中一个选项是保存单词条目。这些单词将使用变量 ispell-personal-dictionary 保存在名为 .hunspell_personal 的新文件中,该文件位于通常的路径上。
两个代码块的包含给出了预期的结果。仅包含第二个代码块就会引发错误“错误类型参数字符串p nil”。
【讨论】:
(setq ispell-program-name "hunspell") 调用,Emacs 默认为aspell。并且还需要ispell-change-dictionary 电话。但是无论如何+1。我posted a snippet 显示了 Emacs 28.0.50 所需的确切代码。