From 1329e0e05754bee70a8236d84d34d01ca42acea7 Mon Sep 17 00:00:00 2001 From: Trevor Arjeski Date: Sat, 4 Jan 2025 08:45:29 +0300 Subject: [PATCH 1/2] [5.6.1] Improve use of flyspell's API in erc-spelling * lisp/erc/erc-spelling.el: Change top-level assignment of `erc-mode' symbol-property `flyspell-mode-predicate' from `erc-spelling-flyspell-verify' to `erc-spelling--flyspell-input-p'. (erc-spelling-mode, erc-spelling-disable): Remove local member from `flyspell-incorrect-hook'. (erc-spelling-init): Add `erc-spelling--flyspell-check' to `flyspell-incorrect-hook' locally. Don't bother explicitly setting `flyspell-generic-check-word-predicate' because Flyspell already does that for clients using the `flyspell-mode-predicte' interface. (erc-spelling--flyspell-check, erc-spelling--flyspell-input-p): New functions, essentially the two halves of a reworked and bifurcated `erc-spelling-flyspell-verify'. Though used as a predicate, the first is not named as such because it performs side effects. (Bug#75327) Copyright-paperwork-exempt: yes --- lisp/erc/erc-spelling.el | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lisp/erc/erc-spelling.el b/lisp/erc/erc-spelling.el index 01e587af368..d6099d4991c 100644 --- a/lisp/erc/erc-spelling.el +++ b/lisp/erc/erc-spelling.el @@ -48,6 +48,7 @@ spelling (erc-spelling-init (current-buffer))))) ((remove-hook 'erc-connect-pre-hook #'erc-spelling-init) (dolist (buffer (erc-buffer-list)) + (remove-hook 'flyspell-incorrect-hook #'erc-spelling--flyspell-check t) (with-current-buffer buffer (flyspell-mode 0))))) (defcustom erc-spelling-dictionaries nil @@ -78,7 +79,7 @@ erc-spelling-init (if dicts (cadr (car dicts)) (erc-with-server-buffer ispell-local-dictionary))))) - (setq flyspell-generic-check-word-predicate #'erc-spelling-flyspell-verify) + (add-hook 'flyspell-incorrect-hook #'erc-spelling--flyspell-check 20 t) (flyspell-mode 1))) (defun erc-spelling-unhighlight-word (word) @@ -109,9 +110,23 @@ erc-spelling-flyspell-verify nil) (t t))))) +(defun erc-spelling--flyspell-check (beg end _) + "Return non-nil and remove overlay if text between BEG and END is correct." + (or (and erc-channel-users + (erc-get-channel-user (buffer-substring-no-properties beg end)) + (always (flyspell-unhighlight-at beg))) + (and erc-input-marker (> beg erc-input-marker) (eq (char-before beg) ?/) + (or (= beg (1+ erc-input-marker)) ; allow /unknown if initial + (erc-command-symbol (buffer-substring-no-properties beg end))) + (always (flyspell-unhighlight-at beg))))) + +(defun erc-spelling--flyspell-input-p () + "Return non-nil if flyspell should check the prompt input at point." + (>= (point) erc-input-marker)) + (put 'erc-mode 'flyspell-mode-predicate - #'erc-spelling-flyspell-verify) + #'erc-spelling--flyspell-input-p) (provide 'erc-spelling) -- 2.47.1