1

Whenever I ispell-change-dictionary, I have to disable and re-enable flyspell-mode for flyspell to pick up the new dictionary.

Is there a way to automate this? It probably involves a post-command-hook, but I'm not sure how this works, especially the disabling and subsequent re-enabling.

1 Answer 1

1

You can first check if there is a hook for this function and I found ispell-change-dictionary-hook

(defun restart-flyspell-mode ()
  (when flyspell-mode
    (flyspell-mode-off)
    (flyspell-mode-on)))
(add-hook 'ispell-change-dictionary-hook 'restart-flyspell-mode)

If there is not a hook, you can use advice-add like:

(defun restart-flyspell-mode (_dict &optional _arg)
  (when flyspell-mode
    (flyspell-mode-off)
    (flyspell-mode-on)))
(advice-add 'ispell-change-dictionary :after 'restart-flyspell-mode)
7
  • Thanks a lot. I've tested the first snippet and it works. The additional info is very useful as well.
    – henning
    Mar 2, 2022 at 12:02
  • After restarting emacs a second time, I get the following error upon startup: "Symbol's value as variable is void: flyspell-delayed-commands". It's the same error, regardless of which snippet I use. Very strange.
    – henning
    Mar 2, 2022 at 22:48
  • I'm quite sure and I update my snippet to not toggle flyspell-mode unless enabled. Can you check if it's working? Mar 3, 2022 at 1:16
  • That did the trick!
    – henning
    Mar 3, 2022 at 9:04
  • Until it didn't, a few restarts later. Totally weird. emacs --debug-init doesn't help. it only says Debugger entered--Lisp error: (void-variable flyspell-delayed-commands) #f(compiled-function () #<bytecode 0x1556485a5645>)() funcall(#f(compiled-function () #<bytecode 0x1556485a5645>)) mapc(funcall (#f(compiled-function () #<bytecode 0x1556485a5645>))) and then gives the config file. So strange that it works only once.
    – henning
    Mar 3, 2022 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.