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