Refactor aspell/hunspell initialization

This commit is contained in:
Henrik Lissner 2019-04-02 14:03:27 -04:00 committed by GitHub
parent 76f98043f1
commit a08e00c4d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,21 +13,24 @@ Since spellchecking can be slow in some buffers, this can be disabled with:
(after! ispell (after! ispell
(setq-default ispell-dictionary "english") (setq-default ispell-dictionary "english")
(add-to-list 'ispell-extra-args "--dont-tex-check-comments")
(let ((no-flags (and (not (featurep! +aspell)) (not (featurep! +hunspell)))))
;; Enable either aspell or hunspell. ;; Enable either aspell or hunspell.
;; If no module flags are given, enable either aspell or hunspell if their ;; If no module flags are given, enable either aspell or hunspell if their
;; ... binary is found. ;; binary is found.
;; If one of the flags `+aspell' or `+hunspell' is given, try to only ;; If one of the flags `+aspell' or `+hunspell' is given, only enable that
;; ... enable that spell checker and not the other. ;; spell checker.
(cond (pcase (cond ((featurep! +aspell) 'aspell)
((and (or no-flags (featurep! +aspell)) ((featurep! +hunspell) 'hunspell)
(executable-find "aspell")) ((executable-find "aspell") 'aspell)
((executable-find "hunspell") 'hunspell))
(`aspell
(setq ispell-program-name "aspell" (setq ispell-program-name "aspell"
ispell-extra-args '("--sug-mode=ultra" "--run-together")) ispell-extra-args '("--sug-mode=ultra" "--run-together"))
(setq-hook! 'text-mode-hook (defun +flyspell|remove-run-together-switch-for-aspell ()
ispell-extra-args (remove "--run-together" ispell-extra-args)) (setq-local ispell-extra-args (remove "--run-together" ispell-extra-args)))
(add-hook 'text-mode-hook #'+flyspell|remove-run-together-switch-for-aspell)
(defun +flyspell*setup-ispell-extra-args (orig-fun &rest args) (defun +flyspell*setup-ispell-extra-args (orig-fun &rest args)
(let ((ispell-extra-args (remove "--run-together" ispell-extra-args))) (let ((ispell-extra-args (remove "--run-together" ispell-extra-args)))
@ -37,8 +40,7 @@ Since spellchecking can be slow in some buffers, this can be disabled with:
(advice-add #'ispell-word :around #'+flyspell*setup-ispell-extra-args) (advice-add #'ispell-word :around #'+flyspell*setup-ispell-extra-args)
(advice-add #'flyspell-auto-correct-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)) (`hunspell
(executable-find "hunspell"))
(setq ispell-program-name "hunspell" (setq ispell-program-name "hunspell"
;; Don't use `ispell-cmd-args', it isn't respected with hunspell. ;; Don't use `ispell-cmd-args', it isn't respected with hunspell.
;; Hack ispell-local-dictionary-alist instead. ;; Hack ispell-local-dictionary-alist instead.
@ -52,9 +54,7 @@ Since spellchecking can be slow in some buffers, this can be disabled with:
nil nil
utf-8)))) utf-8))))
t (user-error "Spell checker not found. Either install `aspell' of `hunspell'"))) (_ (warn "Spell checker not found. Either install `aspell' of `hunspell'"))))
(add-to-list 'ispell-extra-args "--dont-tex-check-comments"))
;; `flyspell' (built-in) ;; `flyspell' (built-in)