Wai Hon's Blog

Write with Emacs 1: Spell-Checking

2021-10-29 #emacs #writing

I am bad at writing, especially in English, which is not my native language. I misspell words, have limited vocabulary, and misuse grammar without being aware of it.

On the other hand, I write and need to write a lot. Emacs is my main writing tool and I use it to take notes, compose commit messages and blog posts, etc. Over the years, I have learned some tricks to write better with this awesome tool. I am going to share them in the next couple of posts,

Let’s start with the basic – spell-checking.

Check and Correct Spelling with Flyspell

I use Flyspell, an Emacs built-in minor mode, for performing on-the-fly spelling checking and correcting.

When enabled, misspelled words will be highlighted. I can use (flyspell-auto-correct-word) to correct the word at the point. Most of the time, the first candidate is the correct one. It is smart enough to me.

I also use the context menu a lot (by middle-clicking the misspelled word). I can choose the right word from all candidates or save the word, so that it does not complain anymore.

If you don’t like touching the mouse, flyspell-correct is a package to correct misspelled words with other interfaces, like helm and ivy, all inside the keyboard.

Here is a demo for (flyspell-correct-wrapper).

Configuration

Flyspell provides two minor modes:

  1. flyspell-mode for writing
  2. flyspell-prog-mode for programming (only text inside comments and strings is checked)ema

Here is how I enable them respectively and set up the packages mentioned above.

(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)

(use-package flyspell-correct
  :after flyspell
  :bind (:map flyspell-mode-map ("C-;" . flyspell-correct-wrapper)))

;; Replace with flyspell-correct-helm if you are a helm person.
(use-package flyspell-correct-ivy
  :after flyspell-correct)

Caveat

This trick does not work if the misspelled word is valid. For example, when misspelling “summit” as “submit”. So, you should still check the spelling even with tool like this.