2019-02-22 00:20:29 -05:00
|
|
|
;;; tools/flyspell/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
(defvar-local +flyspell-immediately t
|
|
|
|
"If non-nil, spellcheck the current buffer upon starting `flyspell-mode'.
|
|
|
|
|
|
|
|
Since spellchecking can be slow in some buffers, this can be disabled with:
|
|
|
|
|
|
|
|
(setq-hook! 'TeX-mode-hook +flyspell-immediately nil)")
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Packages
|
|
|
|
|
|
|
|
(after! ispell
|
|
|
|
(setq-default ispell-dictionary "english")
|
|
|
|
|
2019-03-18 15:52:32 +01:00
|
|
|
(let ((no-flags (and (not (featurep! +aspell)) (not (featurep! +hunspell)))))
|
|
|
|
;; Enable either aspell or hunspell.
|
|
|
|
;; If no module flags are given, enable either aspell or hunspell if their
|
|
|
|
;; ... binary is found.
|
|
|
|
;; If one of the flags `+aspell' or `+hunspell' is given, try to only
|
|
|
|
;; ... enable that spell checker and not the other.
|
|
|
|
(cond
|
|
|
|
((and (or no-flags (featurep! +aspell))
|
|
|
|
(executable-find "aspell"))
|
|
|
|
(setq ispell-program-name "aspell"
|
|
|
|
ispell-extra-args '("--sug-mode=ultra" "--run-together"))
|
|
|
|
|
|
|
|
(setq-hook! 'text-mode-hook
|
|
|
|
ispell-extra-args (remove "--run-together" ispell-extra-args))
|
|
|
|
|
|
|
|
(defun +flyspell*setup-ispell-extra-args (orig-fun &rest args)
|
|
|
|
(let ((ispell-extra-args (remove "--run-together" ispell-extra-args)))
|
|
|
|
(ispell-kill-ispell t)
|
|
|
|
(apply orig-fun args)
|
|
|
|
(ispell-kill-ispell t)))
|
|
|
|
(advice-add #'ispell-word :around #'+flyspell*setup-ispell-extra-args)
|
|
|
|
(advice-add #'flyspell-auto-correct-word :around #'+flyspell*setup-ispell-extra-args))
|
|
|
|
|
|
|
|
((and (or no-flags (featurep! +hunspell))
|
|
|
|
(executable-find "hunspell"))
|
|
|
|
(setq ispell-program-name "hunspell"
|
|
|
|
;; Don't use `ispell-cmd-args', it isn't respected with hunspell.
|
|
|
|
;; Hack ispell-local-dictionary-alist instead.
|
|
|
|
ispell-dictionary-alist
|
|
|
|
`((,ispell-local-dictionary
|
|
|
|
"[[:alpha:]]"
|
|
|
|
"[^[:alpha:]]"
|
|
|
|
"[']"
|
|
|
|
nil
|
|
|
|
("-d" ,ispell-local-dictionary)
|
|
|
|
nil
|
|
|
|
utf-8))))
|
|
|
|
|
|
|
|
t (user-error "Spell checker not found. Either install `aspell' of `hunspell'")))
|
2019-02-22 00:20:29 -05:00
|
|
|
|
2019-03-02 01:56:32 -05:00
|
|
|
(add-to-list 'ispell-extra-args "--dont-tex-check-comments"))
|
2019-02-22 00:20:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
;; `flyspell' (built-in)
|
2019-02-26 16:46:26 -05:00
|
|
|
(progn
|
|
|
|
(setq flyspell-issue-welcome-flag nil)
|
|
|
|
|
|
|
|
(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))
|
2019-02-22 00:20:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
(def-package! flyspell-correct
|
|
|
|
:commands (flyspell-correct-word-generic
|
|
|
|
flyspell-correct-previous-word-generic)
|
|
|
|
:config
|
|
|
|
(cond ((featurep! :completion helm)
|
|
|
|
(require 'flyspell-correct-helm))
|
|
|
|
((featurep! :completion ivy)
|
|
|
|
(require 'flyspell-correct-ivy))
|
|
|
|
((require 'flyspell-correct-popup)
|
|
|
|
(setq flyspell-popup-correct-delay 0.8)
|
|
|
|
(define-key popup-menu-keymap [escape] #'keyboard-quit))))
|