21

Because I'm currently doing a lot of non-programming tasks in Emacs, spell-checking became one of my major concerns once again.

I noticed that there is no question related to the options for spell-checking in Emacs yet, so here we go:

What are my options to do spell-checking in Emacs?

Specifically,

  • for general purpose spell-checking, i.e. sensible suggestions for typos, spell correction of words
  • for selective spell-checking, e.g. general purpose spell-check but only in comments
  • for anything which I forgot or am not aware of but you can think of (spell-check related, duh...)

Edit: Forked off the "other" stuff in a separate question, What options are there for writing better texts in emacs

4
  • 1
    I recommend this page: Spelling in Emacs Commented Oct 14, 2014 at 20:12
  • 1
    As it stands this question is too broad. I suggest to restrict it to the second bullet point (selecting spell-checking), and maybe ask about grammar separately. Commented Oct 14, 2014 at 20:30
  • Only your first two items are about spell checking. Grammar and language are not spell checking, and your last three items would make an entirely different question altogether.
    – Malabarba
    Commented Oct 14, 2014 at 20:55
  • 1
    Although I don't really agree that the original question was too broad or composed of two vastly different questions, I have forked the second part. This question is now only about spell-checking, the other one about grammar checking and writing better texts.
    – elemakil
    Commented Oct 14, 2014 at 21:23

3 Answers 3

10
  • For general purpose spell-checking, there are quite a few popular alternatives
    1. ispell and friends: Built into emacs & typically called with ispell-buffer. Checks spelling only on demand.
    2. flyspell-mode: Also built-in and provides on-the-fly spell checking and highlights mistakes.
    3. speck-mode: Available from MELPA, it checks the spelling of the word once you pause after typing. Also has a few distinguishing features from flyspell mode like able to use multiple dictionaries in the same buffer. (Disclaimer : I only used this mode briefly a long time back)

Note that all the above require dedicated spell-checking programs such as aspell or hunspell and appropriate dictionaries. The modes only provide a convenient emacs interface to the command line programs.

  • For selective spell checking, you can customize flyspell-mode with the variable flyspell-generic-check-word-predicate by wiring a function that selects which words must be checked. Your listed example is easy though -- Just use flyspell-prog-mode which only checks comments in code buffers.
3
  • 1
    First, let me thank you for your answer. Following the comments by Gilles and Malabarba I have forked the question into two parts. Therefore, I'd suggest that you post the second part of your answer (the one about weasel-word) as an answer to the new question. You can find the link in my original question.
    – elemakil
    Commented Oct 14, 2014 at 21:24
  • Please add wcheck to your list. It's very good, though flyspell has become so good lately, that I don't use wcheck anymore.
    – rasmus
    Commented Oct 25, 2014 at 23:59
  • For OSX, the highly customized version of Emacs called Aquamacs has built-in support for the native OSX spellchecker (including, the accompanying OSX user dictionary of words that have been added by the user). That is a specialty item that no other Emacs version can offer.
    – lawlist
    Commented Jan 29, 2015 at 23:39
6

@Vamsi's answer already covers general-purpose and selective spell-checking. But what about personalized auto-correction? @Malabarba has a nice post about this topic on his blog. The basic idea is to store pairs of misspelled words and appropriate corrections as Abbrevs. Here is (a slightly modified version of) the code that lets you do this easily:

(defun ispell-word-then-abbrev (p)
  "Call `ispell-word'. Then create an abbrev for the correction made.
With prefix P, create local abbrev. Otherwise it will be global."
  (interactive "P")
  (let ((before (downcase (or (thing-at-point 'word) "")))
        after)
    (call-interactively 'ispell-word)
    (setq after (downcase (or (thing-at-point 'word) "")))
    (unless (string= after before)
      (define-abbrev
        (if p local-abbrev-table global-abbrev-table) before after))
      (message "\"%s\" now expands to \"%s\" %sally."
               before after (if p "loc" "glob"))))

(define-key ctl-x-map (kbd "C-i") 'ispell-word-then-abbrev)
(setq save-abbrevs t)
(setq-default abbrev-mode t)

With this in place, you can simply

  1. hit C-x C-i after a misspelled word
  2. select a correction, and
  3. never worry about it again

because from now on Emacs will automatically replace the misspelled version of the word with the correction. It's hard to put into words just how useful this is!


If you want to supercharge Emacs' new-found auto-correction capabilities, you can add the abbrevs defined here to your abbrev_defs file.

1

Old question, but since it's the top result in search engines:

jinx uses (lib-)enchant which can use multiple spellchecking backends such as hunspell, aspell, nuspell...

jinx checks all visible words, as opposed to just the one beneath the cursor, it can use multiple dictionaries simultaneously and using native enchant bindings leads to high performance with low memory usage.

Also in the code I have tested only spelling mistakes in comments and string variables get shown and in org mode source code blocks are not spell checked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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