Question

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)?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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

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.

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top