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

时间:2021-09-03 07:23:54

I would like to use the ispell-buffer command in Emacs. It uses the English language by default. Is there an easy way to switch to another dictionary (for example, another language)?

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

6 个解决方案

#1


39  

The following command proposes a list of installed dictionaries to use:

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

M-x ispell-change-dictionary

Usually, M-x isp-c-d expands to the above also.

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

#2


21  

From the file ispell.el you may specify some options for the ispell commands. This happens by adding a section to the end of your file like this:

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

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

Note the double semicolon marks the start of comments in the current mode. It should probably be changed to reflect the way your file (programming language) introduces comments, like // for Java.

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

#3


14  

At the end of a LaTeX file you can use:

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

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

that will set the dictionary to be used just for that file.

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

#4


10  

Use M-x ispell-change-dictionary and hit TAB to see what dictionary are available for you.

使用M-x ispell-change-dictionary并点击TAB查看可用的字典。

Then write the setting of default dictionary in your .emacs, and add a hook to start ispell automatically for you specific mode (if you want).

然后在.emacs中编写默认字典的设置,并为您的特定模式添加一个自动启动ispell的挂钩(如果需要)。

For instance, start ispell in AUCTeX automatically using British English (by default English dictionary is American English)

例如,使用英式英语自动启动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

#5


2  

If you want to change the language on a per-directory basis, you can add this to a .dir-locals.el file:

如果要基于每个目录更改语言,可以将其添加到.dir-locals.el文件中:

(ispell-local-dictionary . "american")

If you have no .dir-locals.el file already, it will look like this:

如果您还没有.dir-locals.el文件,它将如下所示:

((nil .
   ((ispell-local-dictionary . "american")))
)

See the emacs wiki page about directory variables for more information.

有关详细信息,请参阅emacs wiki页面有关目录变量的信息。

#6


1  

For convenience (f7) I added the following to my .emacs:

为方便起见(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: don't forget to install needed dictionaries. E.g. on debian/ubuntu, for the german and english dictionary:

顺便说一句:别忘了安装所需的词典。例如。 on debian / ubuntu,对于德语和英语词典:

sudo apt install aspell-de aspell-en

#1


39  

The following command proposes a list of installed dictionaries to use:

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

M-x ispell-change-dictionary

Usually, M-x isp-c-d expands to the above also.

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

#2


21  

From the file ispell.el you may specify some options for the ispell commands. This happens by adding a section to the end of your file like this:

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

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

Note the double semicolon marks the start of comments in the current mode. It should probably be changed to reflect the way your file (programming language) introduces comments, like // for Java.

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

#3


14  

At the end of a LaTeX file you can use:

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

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

that will set the dictionary to be used just for that file.

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

#4


10  

Use M-x ispell-change-dictionary and hit TAB to see what dictionary are available for you.

使用M-x ispell-change-dictionary并点击TAB查看可用的字典。

Then write the setting of default dictionary in your .emacs, and add a hook to start ispell automatically for you specific mode (if you want).

然后在.emacs中编写默认字典的设置,并为您的特定模式添加一个自动启动ispell的挂钩(如果需要)。

For instance, start ispell in AUCTeX automatically using British English (by default English dictionary is American English)

例如,使用英式英语自动启动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

#5


2  

If you want to change the language on a per-directory basis, you can add this to a .dir-locals.el file:

如果要基于每个目录更改语言,可以将其添加到.dir-locals.el文件中:

(ispell-local-dictionary . "american")

If you have no .dir-locals.el file already, it will look like this:

如果您还没有.dir-locals.el文件,它将如下所示:

((nil .
   ((ispell-local-dictionary . "american")))
)

See the emacs wiki page about directory variables for more information.

有关详细信息,请参阅emacs wiki页面有关目录变量的信息。

#6


1  

For convenience (f7) I added the following to my .emacs:

为方便起见(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: don't forget to install needed dictionaries. E.g. on debian/ubuntu, for the german and english dictionary:

顺便说一句:别忘了安装所需的词典。例如。 on debian / ubuntu,对于德语和英语词典:

sudo apt install aspell-de aspell-en