diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-11 21:12:43 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-11 21:12:43 -0500 |
| commit | b25c12ecd0e8bf8b3f56f6741181eb7e1d82ac7e (patch) | |
| tree | 8d0aa0de7f4693e3e30fab3b360e9c2e0d28b2c9 /tests | |
| parent | 9b906b32b6eccc289aca61b412d828f0daf32f72 (diff) | |
| download | dotemacs-b25c12ecd0e8bf8b3f56f6741181eb7e1d82ac7e.tar.gz dotemacs-b25c12ecd0e8bf8b3f56f6741181eb7e1d82ac7e.zip | |
fix(flyspell-and-abbrev): stop re-scanning the whole buffer on every C-'
cj/flyspell-then-abbrev ran a bare flyspell-buffer guarded by (unless flyspell-mode ...), but nothing turned flyspell-mode on, so the guard never tripped. Every C-' press re-scanned the whole buffer, which is O(buffer) per keypress in large files. I routed the scan through cj/flyspell-on-for-buffer-type instead, so the mode sticks after the first press and the buffer is scanned once.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-flyspell-and-abbrev.el | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test-flyspell-and-abbrev.el b/tests/test-flyspell-and-abbrev.el index ef8cc637..3b494d5e 100644 --- a/tests/test-flyspell-and-abbrev.el +++ b/tests/test-flyspell-and-abbrev.el @@ -97,5 +97,27 @@ (cj/flyspell-on-for-buffer-type))) (should mode-called))) +;; --------------------------- cj/flyspell-then-abbrev ------------------------- + +(ert-deftest test-flyspell-then-abbrev-enables-mode-not-bare-rescan () + "Regression: cj/flyspell-then-abbrev routes the initial scan through +cj/flyspell-on-for-buffer-type, which enables flyspell-mode so it sticks. +The bare flyspell-buffer it replaced never turned the mode on, so the guard +never tripped and every C-' press re-scanned the whole buffer (O(buffer) per +keypress in large files)." + (let (on-called scan-called) + (cl-letf (((symbol-function 'cj/--require-spell-checker) #'ignore) + ((symbol-function 'cj/flyspell-on-for-buffer-type) + (lambda () (setq on-called t))) + ((symbol-function 'flyspell-buffer) + (lambda (&rest _) (setq scan-called t))) + ((symbol-function 'cj/flyspell-goto-previous-misspelling) + (lambda (&rest _) nil))) + (with-temp-buffer + (text-mode) + (cj/flyspell-then-abbrev nil))) + (should on-called) + (should-not scan-called))) + (provide 'test-flyspell-and-abbrev) ;;; test-flyspell-and-abbrev.el ends here |
