The Computer Oracle

How to exclude {{{ ... }}} in flyspell-mode and flyspell-buffer?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Quirky Dreamscape Looping

--

Chapters
00:00 How To Exclude {{{ ... }}} In Flyspell-Mode And Flyspell-Buffer?
00:43 Accepted Answer Score 17
01:34 Thank you

--

Full question
https://superuser.com/questions/345084/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#emacs #aspell

#avk47



ACCEPTED ANSWER

Score 17


The variable ispell-skip-region-alist does what you want when spell checking the buffer, but not for flyspell. Just add an entry like

(add-to-list 'ispell-skip-region-alist
             '("^{{{" . "^}}}"))

Unfortunately, it's not as easy to get flyspell to ignore certain regions. You have to use flyspell-generic-check-word-predicate which is a function. Several modes already define this so you would have to add the following as advice to those functions. I'll assume for simplicity though that you are using a mode (I used text-mode below) which doesn't have it defined. Then you can add the following to your .emacs:

(defun flyspell-ignore-verbatim ()
  "Function used for `flyspell-generic-check-word-predicate' to ignore {{{ }}} blocks."
  (save-excursion
    (widen)
    (let ((p (point))
          (count 0))
      (not (or (and (re-search-backward "^{{{" nil t)
                    (> p (point))
                    ;; If there is no closing }}} then assume we're still in it
                    (or (not (re-search-forward "^}}}" nil t))
                        (< p (point))))
               (eq 1 (progn (while (re-search-backward "`" (line-beginning-position) t)
                              (setq count (1+ count)))
                            (- count (* 2 (/ count 2))))))))))
(put 'text-mode 'flyspell-mode-predicate 'flyspell-ignore-verbatim)