“Flyspell enables on-the-fly spell checking in Emacs by the means of a minor mode. It is called Flyspell. This facility is hardly intrusive. It requires no help. Flyspell highlights incorrect words as soon as they are completed or as soon as the TextCursor hits a new word.”
Flyspell can be found at http://www-sop.inria.fr/mimosa/Manuel.Serrano/flyspell/flyspell.html
It is also part of Emacs. See also FlyspellWithoutColors.
Here is an example to enable it for text-mode, and disable it for log-edit-mode and change-log-mode. These two are derived from text-mode, and thus enabling flyspell-mode for text-mode also enables it for these two. An alternative solution would be the writing of a flyspell-mode-predicate such that symbols are ignored by flyspell.
(dolist (hook '(text-mode-hook)) (add-hook hook (lambda () (flyspell-mode 1)))) (dolist (hook '(change-log-mode-hook log-edit-mode-hook)) (add-hook hook (lambda () (flyspell-mode -1))))
The idiom used above makes it very easy to enable and disable flyspell for the various major-modes out there: Just add the relevant hook to the list where the other hooks already are.
Programmers can use flyspell-prog-mode to enable spell checking only within comments of source code.
Flyspell comes with a mode to check comments and strings in programming modes. Just type M-x flyspell-prog-mode or add it to your mode hooks
(add-hook 'c++-mode-hook (lambda () (flyspell-prog-mode) ; ... ))
- ruediger -
I highly suggest setting
‘flyspell-issue-message-flag’ to nil, as printing messages for every word (when checking the entire buffer) causes an enormous slowdown. – nschum
I recently started using flyspell and am enjoying its features. Is there a way to disable flyspell for certain regexps? For instance, I would like to disable flyspell when typing a url. Otherwise, when entering a url such as http://www.emacswiki.org/cgi-bin/emacs/FlySpell, www, emacswiki, cgi and FlySpell are highlighted as errors. Any advice would be greatly appreciated. – MattLundin
There is only one way, using flyspell-generic-check-word-predicate which should be a function. In such a function you can use thing at point.
However it is a bit difficult to manage this as this variable may be only one function. I have submitted a patch to Emacs devel to take care of this.
Thanks for pointing me to the flyspell-generic-check-word-predicate variable. – MattLundin
I am interested in a working solution to ignore spellchecking URLs and email addresses. The answer at http://superuser.com/a/345461/40407 seems to be relevant to making a solution with flyspell-generic-check-word-predicate, though not specificly for URLs and email addresses. MattLundin, did you come up with something?
As I often need to switch between English and German I use this function:
(defun fd-switch-dictionary() (interactive) (let* ((dic ispell-current-dictionary) (change (if (string= dic "deutsch8") "english" "deutsch8"))) (ispell-change-dictionary change) (message "Dictionary switched from %s to %s" dic change) )) (global-set-key (kbd "<f8>") 'fd-switch-dictionary)
I too cycle through different languages, but not all that is available in the system. I use the following code inside my .emacs.
(let ((langs '("american" "francais" "brasileiro"))) (setq lang-ring (make-ring (length langs))) (dolist (elem langs) (ring-insert lang-ring elem)))
(defun cycle-ispell-languages () (interactive) (let ((lang (ring-ref lang-ring -1))) (ring-insert lang-ring lang) (ispell-change-dictionary lang)))
(global-set-key [f6] 'cycle-ispell-languages)
How can I ignore or add a word without using the popup menu?
This is not working for me. With flyspell-auto-correct-word I can go through all suggestions for correction, but I do not get an option to insert the word into my dictionary.
I used “M x ispell-region”, and the words that ispell considered having incorrect spellings were highlighted. The point moved to the first “mis-spelled” word. By typing “i”, I inserted the word into my personal dictionary. Later I found that the personal dictionary was stored in the file $HOME/.aspell.en.pws in pure text format. Although the word was added when I used “ispell” instead of “flyspell”, but once added, flyspell also recognized the word as having a correct spelling. :-) This information came from the web page: http://www.delorie.com/gnu/docs/emacs/emacs_109.html . Thanks!
– Namo Amitabha
You can also type “a” to make the word session-local and “A” to make it buffer-local (i.e. to add it to your LocalWords list.)
Place the below code in your .emacs
F8 will call ispell (or aspell, etc) for the word the cursor is on (or near). You can also use the built-in key binding M-$.
Ctrl-Shift-F8 enables/disables FlySpell for your current buffer (highlights misspelled words as you type)
Crtl-Meta-F8 runs FlySpell on your current buffer (highlights all misspelled words in the buffer)
Ctrl-F8 calls ispell for the FlySpell highlighted word prior to the cursor’s position
Meta-F8 calls ispell for the FlySpell highlighted word after the cursor’s position
;; easy spell check (global-set-key (kbd "<f8>") 'ispell-word) (global-set-key (kbd "C-S-<f8>") 'flyspell-mode) (global-set-key (kbd "C-M-<f8>") 'flyspell-buffer) (global-set-key (kbd "C-<f8>") 'flyspell-check-previous-highlighted-word) (defun flyspell-check-next-highlighted-word () "Custom function to spell check next highlighted word" (interactive) (flyspell-goto-next-error) (ispell-word) ) (global-set-key (kbd "M-<f8>") 'flyspell-check-next-highlighted-word)
How can I position the flyspell suggestions in a window that is below the current window? Currently, on Aquamacs, running leuven color theme, when the suggestions come up, the tabs do not disappear (they did when i wasn’t using the color theme). The theme is really nice (in conjunction with org-mode) so I do not wish to get rid of that. How can i force the suggestion window to appear just above the modeline?
If you use flyspell with aspell instead of ispell you have to add :
(setq ispell-list-command "--list")
Because the “-l” option mean “--lang” in aspell and the “-l” option mean “--list” in ispell. flyspell-buffer, and flyspell-region are affected by this problem.
If I add a word during a flyspell session, it’s still marked up as misspelled. And flyspell-correct-previous-word tells me that it’s spelling is correct. How do I run flyspell-buffer on the buffer every time the dictionary is modified?
When the subword mode is on, especially with cc-mode, the words are distinguished more skilfully, e.g., “GoodBadType?” → “Good”, “Bad”, and “Type”. How do I set the flyspell to work in this context?