17

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
  • 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, 2014 at 19:08

2 Answers 2

14

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\"."
  (save-excursion
    (forward-whitespace -1)
    (when (looking-at " ")
        (forward-char)
    (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.

1
  • Can we apply this in the latex-mode? and also for the url inside href{}?
    – alper
    Jan 11, 2023 at 13:51
1

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:

(https://emacs.stackexchange.com)
[text text](https://emacs.stackexchange.com)
\url{https://emacs.stackexchange.com}
0

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.