tools/flyspell: conform to new conventions

This commit is contained in:
Henrik Lissner 2019-07-22 23:34:23 +02:00
parent 90f5128de2
commit 287e61a72c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 21 additions and 23 deletions

View file

@ -14,7 +14,7 @@
(add-to-list '+flyspell--predicate-alist (cons mode predicate)))) (add-to-list '+flyspell--predicate-alist (cons mode predicate))))
;;;###autoload ;;;###autoload
(defun +flyspell|init-predicate () (defun +flyspell-init-predicate-h ()
"TODO" "TODO"
(when-let (pred (assq major-mode +flyspell--predicate-alist)) (when-let (pred (assq major-mode +flyspell--predicate-alist))
(setq-local flyspell-generic-check-word-predicate (cdr pred)))) (setq-local flyspell-generic-check-word-predicate (cdr pred))))

View file

@ -27,17 +27,16 @@ Since spellchecking can be slow in some buffers, this can be disabled with:
(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"))
(defun +flyspell|remove-run-together-switch-for-aspell () (add-hook 'text-mode-hook
(setq-local ispell-extra-args (remove "--run-together" ispell-extra-args))) (defun +flyspell-remove-run-together-switch-for-aspell-h ()
(add-hook 'text-mode-hook #'+flyspell|remove-run-together-switch-for-aspell) (setq-local ispell-extra-args (remove "--run-together" ispell-extra-args))))
(defun +flyspell*setup-ispell-extra-args (orig-fun &rest args) (defun +flyspell-setup-ispell-extra-args-a (orig-fun &rest args)
:around '(ispell-word flyspell-auto-correct-word)
(let ((ispell-extra-args (remove "--run-together" ispell-extra-args))) (let ((ispell-extra-args (remove "--run-together" ispell-extra-args)))
(ispell-kill-ispell t) (ispell-kill-ispell t)
(apply orig-fun args) (apply orig-fun args)
(ispell-kill-ispell t))) (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))
(`hunspell (`hunspell
(setq ispell-program-name "hunspell")) (setq ispell-program-name "hunspell"))
@ -52,29 +51,28 @@ Since spellchecking can be slow in some buffers, this can be disabled with:
(when (featurep! +prog) (when (featurep! +prog)
(add-hook 'prog-mode-hook #'flyspell-prog-mode)) (add-hook 'prog-mode-hook #'flyspell-prog-mode))
(defun +flyspell|inhibit-duplicate-detection-maybe () (add-hook 'flyspell-mode-hook
"Don't mark duplicates when style/grammar linters are present. (defun +flyspell-inhibit-duplicate-detection-maybe-h ()
"Don't mark duplicates when style/grammar linters are present.
e.g. proselint and langtool." e.g. proselint and langtool."
(when (or (and (bound-and-true-p flycheck-mode) (when (or (and (bound-and-true-p flycheck-mode)
(executable-find "proselint")) (executable-find "proselint"))
(featurep 'langtool)) (featurep 'langtool))
(setq-local flyspell-mark-duplications-flag nil))) (setq-local flyspell-mark-duplications-flag nil))))
(add-hook 'flyspell-mode-hook #'+flyspell|inhibit-duplicate-detection-maybe)
(defun +flyspell|immediately () (add-hook 'flyspell-mode-hook
"Spellcheck the buffer when `flyspell-mode' is enabled." (defun +flyspell-immediately-h ()
(when (and flyspell-mode +flyspell-immediately) "Spellcheck the buffer when `flyspell-mode' is enabled."
(flyspell-buffer))) (when (and flyspell-mode +flyspell-immediately)
(add-hook 'flyspell-mode-hook #'+flyspell|immediately) (flyspell-buffer))))
;; Ensure mode-local predicates declared with `set-flyspell-predicate!' are ;; Ensure mode-local predicates declared with `set-flyspell-predicate!' are
;; used in their respective major modes. ;; used in their respective major modes.
(add-hook 'flyspell-mode-hook #'+flyspell|init-predicate)) (add-hook 'flyspell-mode-hook #'+flyspell-init-predicate-h))
(def-package! flyspell-correct (def-package! flyspell-correct
:commands (flyspell-correct-word-generic :commands flyspell-correct-word-generic flyspell-correct-previous-word-generic
flyspell-correct-previous-word-generic)
:config :config
(cond ((and (featurep! :completion helm) (cond ((and (featurep! :completion helm)
(require 'flyspell-correct-helm nil t))) (require 'flyspell-correct-helm nil t)))