Refactor +markdown-flyspell-word-p predicate

A little faster and less duplicated logic.
This commit is contained in:
Henrik Lissner 2020-11-27 16:58:45 -05:00
parent 0f3226558f
commit 7f99eb7a48
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -2,23 +2,31 @@
;;;###autoload ;;;###autoload
(defun +markdown-flyspell-word-p () (defun +markdown-flyspell-word-p ()
"Return t if point is on a word that should be spell checked. "Return t if `flyspell' should check work before point.
Return nil if on a link url, markup, html, or references." Used for `flyspell-generic-check-word-predicate'. Augments
(let ((faces (doom-enlist (get-text-property (point) 'face)))) `markdown-flyspell-check-word-p' to:
(or (and (memq 'font-lock-comment-face faces)
(memq 'markdown-code-face faces)) a) Do spell check in code comments and
(not (cl-loop with unsafe-faces = '(markdown-reference-face b) Inhibit spell check in html markup"
markdown-url-face (and (markdown-flyspell-check-word-p)
markdown-markup-face (save-excursion
markdown-comment-face (goto-char (1- (point)))
markdown-html-attr-name-face (if (or
;; Spell check in code comments
(not (and (markdown-code-block-at-point-p)
(markdown--face-p (point) '(font-lock-comment-face))))
;; Don't spell check in html markup
(markdown--face-p (point) '(markdown-html-attr-name-face
markdown-html-attr-value-face markdown-html-attr-value-face
markdown-html-tag-name-face markdown-html-tag-name-face)))
markdown-code-face) (prog1 nil
for face in faces ;; If flyspell overlay is put, then remove it
if (memq face unsafe-faces) (when-let (bounds (bounds-of-thing-at-point 'word))
return t))))) (cl-loop for ov in (overlays-in (car bounds) (cdr bounds))
when (overlay-get ov 'flyspell-overlay)
do (delete-overlay ov))))
t))))
;; ;;