When I use flyspell-mode, it reports spelling errors whenever I type a URL. Is there a way I can tell Flyspell to stop checking URLs?

  • 1
    For ispell (not flyspell) this semi-related link, regarding ispell-skip-region-alist, looks helpful: superuser.com/a/345461/206164 Perhaps flyspell has something similar that can be implemented -- e.g., using flyspell-mode-predicate.
    – lawlist
    Dec 15 '14 at 19:08

After a bit of digging, I found a hint in [this Superuser.com answer: you need to set flyspell-mode-predicate to a function that will decide whether words should be checked or not. Here's a way to get Flyspell to ignore anything starting with "http" or "https":

(defun flyspell-ignore-http-and-https ()
  "Function used for `flyspell-generic-check-word-predicate' to ignore stuff starting with \"http\" or \"https\"."
    (forward-whitespace -1)
    (when (looking-at " ")
    (not (looking-at "https?\\b"))))) 

(put 'text-mode 'flyspell-mode-predicate 'flyspell-ignore-http-and-https)

There are some shortcomings, of course:

  • I'm assuming that anything beginning with "http" or "https" should be skipped; that includes "http://cnn.com" and "https://google.com" (good), but also "httpomatic" and "httpstatisticiansarehip" (presumably bad)
  • I'm not bothering with mailto:, ftp:, file:, etc etc. (But that way may lie madness...)

But as a quick-and-dirty method, it should work.

  • It did not work for the header section. Example usage in org mode: * [text text](https://emacs.stackexchange.com/com/sqJUcbjp) ; sqJUcbjp is highlighted
    – alper
    Sep 9 '21 at 12:48

I've something along these lines (in my case for markdown mode) to be slightly more resistant to some common but pathological cases from Saint Aardvark the Carpeted's answer:

(require 'thingatpt)
(defun markdown-flyspell-predicate ()
  (not (thing-at-point 'url)))
(put 'markdown-mode 'flyspell-mode-predicate 'markdown-flyspell-predicate)

In particular, if you start by looking at the whitespace before a word, the URL won't necessarily start with https. Consider these cases:

[text text](https://emacs.stackexchange.com)
  • It did not work for the header part, ex for * [text text](https://emacs.stackexchange.com/com/sqJUcbjp)
    – alper
    Sep 9 '21 at 12:47

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.