Improve flyspell support
+ Make flyspell more selective about what to scan in markdown buffers. + Don't mark duplicates when proseline or langtool are present. + Add set-flyspell-predicate! for seeing mode-specific word predicates.
This commit is contained in:
parent
d83ba452ef
commit
db2949ff32
4 changed files with 57 additions and 6 deletions
|
@ -20,3 +20,23 @@
|
|||
(if (thing-at-point-looking-at +markdown--regex-del)
|
||||
(markdown-unwrap-thing-at-point nil 2 4)
|
||||
(markdown-wrap-or-insert delim delim 'word nil nil)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +markdown-flyspell-word-p ()
|
||||
"Return t if point is on a word that should be spell checked.
|
||||
|
||||
Return nil if on a link url, markup, html, or references."
|
||||
(let ((faces (doom-enlist (get-text-property (point) 'face))))
|
||||
(or (and (memq 'font-lock-comment-face faces)
|
||||
(memq 'markdown-code-face faces))
|
||||
(not (cl-loop with unsafe-faces = '(markdown-reference-face
|
||||
markdown-url-face
|
||||
markdown-markup-face
|
||||
markdown-comment-face
|
||||
markdown-html-attr-name-face
|
||||
markdown-html-attr-value-face
|
||||
markdown-html-tag-name-face
|
||||
markdown-code-face)
|
||||
for face in faces
|
||||
if (memq face unsafe-faces)
|
||||
return t)))))
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
markdown-gfm-uppercase-checkbox t) ; for compat with org-mode
|
||||
|
||||
:config
|
||||
(set-flyspell-predicate! '(markdown-mode gfm-mode) #'+markdown-flyspell-word-p)
|
||||
|
||||
(defun +markdown|set-fill-column-and-line-spacing ()
|
||||
(setq-local line-spacing 2)
|
||||
(setq-local fill-column 80))
|
||||
|
|
16
modules/tools/flyspell/autoload.el
Normal file
16
modules/tools/flyspell/autoload.el
Normal file
|
@ -0,0 +1,16 @@
|
|||
;;; tools/flyspell/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +flyspell--predicate-alist nil
|
||||
"TODO")
|
||||
|
||||
;;;###autodef
|
||||
(defun set-flyspell-predicate! (modes predicate)
|
||||
"TODO"
|
||||
(dolist (mode (doom-enlist modes) +flyspell--predicate-alist)
|
||||
(add-to-list '+flyspell--predicate-alist (cons mode predicate))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +flyspell|init-predicate ()
|
||||
"TODO"
|
||||
(when-let* ((pred (assq major-mode +flyspell--predicate-alist)))
|
||||
(setq-local flyspell-generic-check-word-predicate (cdr pred))))
|
|
@ -47,13 +47,26 @@ Since spellchecking can be slow in some buffers, this can be disabled with:
|
|||
|
||||
|
||||
;; `flyspell' (built-in)
|
||||
(setq flyspell-issue-welcome-flag nil)
|
||||
(progn
|
||||
(setq flyspell-issue-welcome-flag nil)
|
||||
|
||||
(defun +flyspell|immediately ()
|
||||
"Spellcheck the buffer when `flyspell-mode' is enabled."
|
||||
(when (and flyspell-mode +flyspell-immediately)
|
||||
(flyspell-buffer)))
|
||||
(add-hook 'flyspell-mode-hook #'+flyspell|immediately)
|
||||
(defun +flyspell|inhibit-duplicate-detection-maybe ()
|
||||
"Don't mark duplicates when style/grammar linters are present.
|
||||
e.g. proselint and langtool."
|
||||
(when (or (executable-find "proselint")
|
||||
(featurep 'langtool))
|
||||
(setq-local flyspell-mark-duplications-flag nil)))
|
||||
(add-hook 'flyspell-mode-hook #'+flyspell|inhibit-duplicate-detection-maybe)
|
||||
|
||||
(defun +flyspell|immediately ()
|
||||
"Spellcheck the buffer when `flyspell-mode' is enabled."
|
||||
(when (and flyspell-mode +flyspell-immediately)
|
||||
(flyspell-buffer)))
|
||||
(add-hook 'flyspell-mode-hook #'+flyspell|immediately)
|
||||
|
||||
;; Ensure mode-local predicates declared with `set-flyspell-predicate!' are
|
||||
;; used in their respective major modes.
|
||||
(add-hook 'flyspell-mode-hook #'+flyspell|init-predicate))
|
||||
|
||||
|
||||
(def-package! flyspell-correct
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue