Subject: Re: bug#69703: Ispell process restarted too often

From: Juri Linkov <[email-masked]>
Date: Thu, 14 Mar 2024 19:50:08 +0200

BTW, currently the order or enabling minor modes and
reading dir-local variables looks wrong: after visiting a file
first minor modes are enabled, then dir-local-variables
are set in the buffer.

So with (add-hook 'text-mode-hook 'flyspell-mode)
Ispell starts the Ispell process with the global dictionary.
Then later reads 'ispell-personal-dictionary' from .dir-locals.el
and restarts the Ispell process with another dictionary.

A workaround for configs is to force 'hack-dir-local-variables'
before enabling 'flyspell-mode' that is not a nice hack:

  (defun my-flyspell-mode ()
    ;; Avoid duplicate calls when ‘flyspell-mode’ is enabled by ‘.dir-locals.el’,
    ;; because the first call uses the global value of ‘ispell-personal-dictionary’,
    ;; and so restarts the Ispell process.
    (unless (progn (hack-dir-local-variables)
                   (member '(mode . flyspell) file-local-variables-alist))
      (flyspell-mode)))

  (add-hook 'text-mode-hook 'my-flyspell-mode)