7

I'm using the following code to launch flyspell when I edit LaTeX files with Emacs+AUCTeX.

(if (file-exists-p "/usr/bin/hunspell")
    (progn
      (setq ispell-program-name "hunspell")
      (eval-after-load "ispell"
        '(progn (defun ispell-get-coding-system () 'utf-8)))))


(global-set-key [f2] 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)

You can notice flyspell is automatically started when in the LaTeX mode (AUCTeX mode) and could be disable/enable with the shortcut F2.

The configuration uses hunspell (which is much better than ispell or aspell in my opinion) with the system default language (in my case: French).

I would like to be able to change the language with a shortcut. I'm writing in French and English (sometimes inside the same document) and I would be able to switch language in an quick way during editing. For example, it would be wonderful if I could choose English dictionary with F4 and go back to the default French dictionary with F3 (when F2 is still used to toogle on/off flyspell).

P-S : For now, I'm doing the switch with M-x ispell-change-dictionary but it isn't very efficient.

  • Would you publish, maybe as an edit, your whole setup regarding flyspell, including the dictionary and so on? I'd really be interested, but using only your code throws errors. I found this site: emacswiki.org/emacs/InteractiveSpell#toc5 -- I will test what's been published there. – Keks Dose Mar 21 '14 at 23:33
  • @KeksDose This is all my flyspell related code. It loads the system default dictionnary but the accepted answer show how to choose another one. Perhaps, hunspell-xx (where xx is the language shortcut : en for English) is not installed on your system? – ppr Mar 23 '14 at 16:46
  • @KeksDose you could override the system default dictionnary with (setq ispell-dictionary "francais"). – ppr Mar 23 '14 at 16:50
  • 1
    Thank you. I got a working system with hunspell by using "rw-hunspell.el". The dictionary is far better than a/ispell, at least regarding German language. – Keks Dose Mar 23 '14 at 16:55
9

Add the following code to your .emacs:

(global-set-key
 [f3]
 (lambda ()
   (interactive)
   (ispell-change-dictionary "francais")))
(global-set-key
 [f4]
 (lambda ()
   (interactive)
   (ispell-change-dictionary "english")))

Are you already aware of this?

  • Thanks, I was aware of AUCTeX capabilities regarding languages. However, I prefer to use csquote and \enquote{} command. – ppr Mar 21 '14 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.