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)")
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-05-06 19:39:35 -04:00
|
|
|
;;; Packages
|
2019-02-22 00:20:29 -05:00
|
|
|
|
|
|
|
(after! ispell
|
2019-04-02 14:03:27 -04:00
|
|
|
(add-to-list 'ispell-extra-args "--dont-tex-check-comments")
|
2019-02-22 00:20:29 -05:00
|
|
|
|
2019-04-02 14:03:27 -04:00
|
|
|
;; 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, only enable that
|
|
|
|
;; spell checker.
|
|
|
|
(pcase (cond ((featurep! +aspell) 'aspell)
|
|
|
|
((featurep! +hunspell) 'hunspell)
|
|
|
|
((executable-find "aspell") 'aspell)
|
|
|
|
((executable-find "hunspell") 'hunspell))
|
|
|
|
(`aspell
|
|
|
|
(setq ispell-program-name "aspell"
|
|
|
|
ispell-extra-args '("--sug-mode=ultra" "--run-together"))
|
2019-03-18 15:52:32 +01:00
|
|
|
|
2019-07-22 23:34:23 +02:00
|
|
|
(add-hook 'text-mode-hook
|
|
|
|
(defun +flyspell-remove-run-together-switch-for-aspell-h ()
|
|
|
|
(setq-local ispell-extra-args (remove "--run-together" ispell-extra-args))))
|
2019-03-18 15:52:32 +01:00
|
|
|
|
2019-07-22 23:34:23 +02:00
|
|
|
(defun +flyspell-setup-ispell-extra-args-a (orig-fun &rest args)
|
|
|
|
:around '(ispell-word flyspell-auto-correct-word)
|
2019-04-02 14:03:27 -04:00
|
|
|
(let ((ispell-extra-args (remove "--run-together" ispell-extra-args)))
|
|
|
|
(ispell-kill-ispell t)
|
|
|
|
(apply orig-fun args)
|
2019-07-22 23:34:23 +02:00
|
|
|
(ispell-kill-ispell t))))
|
2019-03-18 15:52:32 +01:00
|
|
|
|
2019-04-02 14:03:27 -04:00
|
|
|
(`hunspell
|
2019-05-06 19:39:35 -04:00
|
|
|
(setq ispell-program-name "hunspell"))
|
2019-02-22 00:20:29 -05:00
|
|
|
|
2019-06-18 17:30:26 +02:00
|
|
|
(_ (doom-log "Spell checker not found. Either install `aspell' or `hunspell'"))))
|
2019-02-22 00:20:29 -05:00
|
|
|
|
|
|
|
|
2019-05-06 19:39:35 -04:00
|
|
|
;;;###package flyspell
|
|
|
|
(progn ; built-in
|
2019-02-26 16:46:26 -05:00
|
|
|
(setq flyspell-issue-welcome-flag nil)
|
|
|
|
|
2019-05-19 01:37:24 -04:00
|
|
|
(when (featurep! +prog)
|
|
|
|
(add-hook 'prog-mode-hook #'flyspell-prog-mode))
|
|
|
|
|
2019-07-22 23:34:23 +02:00
|
|
|
(add-hook 'flyspell-mode-hook
|
|
|
|
(defun +flyspell-inhibit-duplicate-detection-maybe-h ()
|
|
|
|
"Don't mark duplicates when style/grammar linters are present.
|
2019-02-26 16:46:26 -05:00
|
|
|
e.g. proselint and langtool."
|
2019-07-22 23:34:23 +02:00
|
|
|
(when (or (and (bound-and-true-p flycheck-mode)
|
|
|
|
(executable-find "proselint"))
|
|
|
|
(featurep 'langtool))
|
|
|
|
(setq-local flyspell-mark-duplications-flag nil))))
|
|
|
|
|
|
|
|
(add-hook 'flyspell-mode-hook
|
|
|
|
(defun +flyspell-immediately-h ()
|
|
|
|
"Spellcheck the buffer when `flyspell-mode' is enabled."
|
|
|
|
(when (and flyspell-mode +flyspell-immediately)
|
|
|
|
(flyspell-buffer))))
|
2019-02-26 16:46:26 -05:00
|
|
|
|
|
|
|
;; Ensure mode-local predicates declared with `set-flyspell-predicate!' are
|
|
|
|
;; used in their respective major modes.
|
2019-07-22 23:34:23 +02:00
|
|
|
(add-hook 'flyspell-mode-hook #'+flyspell-init-predicate-h))
|
2019-02-22 00:20:29 -05:00
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! flyspell-correct
|
2019-07-22 23:34:23 +02:00
|
|
|
:commands flyspell-correct-word-generic flyspell-correct-previous-word-generic
|
2019-02-22 00:20:29 -05:00
|
|
|
:config
|
2019-04-02 15:33:03 -04:00
|
|
|
(cond ((and (featurep! :completion helm)
|
|
|
|
(require 'flyspell-correct-helm nil t)))
|
|
|
|
((and (featurep! :completion ivy)
|
|
|
|
(require 'flyspell-correct-ivy nil t)))
|
|
|
|
((require 'flyspell-correct-popup nil t)
|
2019-02-22 00:20:29 -05:00
|
|
|
(setq flyspell-popup-correct-delay 0.8)
|
|
|
|
(define-key popup-menu-keymap [escape] #'keyboard-quit))))
|