Fix too-small abbrev obarray bug with autocorrect

I'm seeing a bug here, but I'm surprised. Surely more people than just
me have run into abbrev tables being cut short because it grew past the
default obarray size?
This commit is contained in:
TEC 2024-03-27 01:05:14 +08:00
parent 44e3a693da
commit d405304d86
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 15 additions and 4 deletions

View File

@ -4279,12 +4279,21 @@ too. We could just not save it, but it seems nice to get the count information.
(defvar autocorrect-abbrev-table--saved-version 0
"The version of `autocorrect-abbrev-table' saved to disk.")
(declare-function math-next-small-prime "calc-comb")
(defun autocorrect--setup-abbrevs ()
"Setup `autocorrect-abbrev-table'.
Also set it as a parent of `global-abbrev-table'."
(unless autocorrect-abbrev-table
(setq autocorrect-abbrev-table
(make-abbrev-table (list :enable-function #'autocorrect--appropriate-p)))
(let ((obarray-default-size
(if (>= emacs-major-version 30)
4 ; In Emacs 30+ obarrays will dynamically grow.
(require 'calc-comb)
(math-next-small-prime
(+ (hash-table-size autocorrect-record-table) 50)))))
(setq autocorrect-abbrev-table
(make-abbrev-table
(list :enable-function #'autocorrect--appropriate-p))))
(abbrev-table-put
global-abbrev-table :parents
(cons autocorrect-abbrev-table
@ -4409,12 +4418,14 @@ split the actual reading and the abbrev generation into two parts though.
"Ensure that all entries of the abbrev table are valid."
(obarray-map
(lambda (misspelling)
(when (stringp misspelling) ; Abbrev's obarrays start with a symbol
(setq misspelling (symbol-name misspelling))
(unless (string-empty-p misspelling) ; Abbrev uses an empty symbol for metadata.
(let ((corrections (gethash misspelling autocorrect-record-table)))
(unless (and (= (length corrections) 1)
(>= (cdar corrections)
autocorrect-count-threshold-history))
(define-abbrev autocorrect-abbrev-table misspelling nil)))))
(define-abbrev autocorrect-abbrev-table misspelling nil)
(unintern misspelling autocorrect-abbrev-table)))))
autocorrect-abbrev-table))
(defun autocorrect--create-history-abbrevs ()