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)?
-
i would suggest all those answering this question to also inform how to add e.g. French to the set of ispell dictionaries, if it didn't get there during installation. I consider all the answers givenhere incomplete. – Albert van der Horst Aug 07 '20 at 12:09
7 Answers
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.
-
1This sets the dictionary for the current session only. How can I set it as default for emacs ? – dknight Dec 22 '13 at 08:08
-
1With the completion of `ispell-change-dictionary` you can check what strings are permissible for the variable `ispell-dictionary`. Choose the wanted one and customize `ispell-dictionary` (i.e., `M-x customize-option` `ispell-dictionary` and then input your wanted dictionary into the appropriate field). – Tobias Dec 23 '13 at 12:56
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:
;; 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.

- 2,858
- 22
- 21
At the end of a LaTeX file you can use:
%%% Local Variables:
%%% ispell-local-dictionary: "british"
%%% End:
that will set the dictionary to be used just for that file.

- 688
- 6
- 13
Use M-x ispell-change-dictionary
and hit TAB
to see what dictionary are available for you.
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).
For instance, start ispell in AUCTeX automatically using British English (by default English dictionary is American English)
(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

- 394
- 2
- 9
If you want to change the language on a per-directory basis, you can add this to a .dir-locals.el
file:
(ispell-local-dictionary . "american")
If you have no .dir-locals.el
file already, it will look like this:
((nil .
((ispell-local-dictionary . "american")))
)
See the emacs wiki page about directory variables for more information.

- 6,380
- 1
- 31
- 34
For convenience (f7) I added the following to my .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:
sudo apt install aspell-de aspell-en

- 543
- 3
- 10
Here is some code to remap the C-\ key to automatically toggle between multiple languages and to change the input method to the corresponding language. (derived from this post: https://stackoverflow.com/a/45891514/17936582 )
;; Toggle both distionary and input method with C-\
(let ((languages '("en" "it" "de")))
(setq ispell-languages-ring (make-ring (length languages)))
(dolist (elem languages) (ring-insert ispell-languages-ring elem)))
(defun ispell-cycle-languages ()
(interactive)
(let ((language (ring-ref ispell-languages-ring -1)))
(ring-insert ispell-languages-ring language)
(ispell-change-dictionary language)
(cond
((string-match "it" language) (activate-input-method "italian-postfix"))
((string-match "de" language) (activate-input-method "german-postfix"))
((string-match "en" language) (deactivate-input-method)))))
(define-key (current-global-map) [remap toggle-input-method] 'ispell-cycle-languages)

- 11
- 1