Skip to content

Commit

Permalink
elisp: Don't assume that flyspell is loaded when starting alectryon-mode
Browse files Browse the repository at this point in the history
Fixes GH-88.
  • Loading branch information
cpitclaudel committed Sep 25, 2022
1 parent 739b46d commit 8a1f305
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions etc/elisp/alectryon.el
Expand Up @@ -405,6 +405,18 @@ Current document must have a file name."

(defvar flyspell-prog-text-faces)

(defun alectryon--flyspell-hook ()
"Hook run when Flyspell is loaded in this buffer."
(when (bound-and-true-p flyspell-mode)
(make-local-variable 'flyspell-prog-text-faces)
(cl-pushnew 'alectryon-comment flyspell-prog-text-faces)))

(defun alectryon--flyspell-unhook ()
"Remove Flyspell customizations."
(when (bound-and-true-p flyspell-mode)
(setq-local flyspell-prog-text-faces
(remq 'alectryon-comment flyspell-prog-text-faces))))

;;;###autoload
(define-minor-mode alectryon-mode
"Mode for Literate Coq files.
Expand All @@ -419,16 +431,17 @@ In reST mode:
(alectryon--record-original-mode)
(alectryon--invoke 'flycheck-mode)
(add-hook 'write-contents-functions #'alectryon--save t t)
(make-local-variable 'flyspell-prog-text-faces)
(cl-pushnew 'alectryon-comment flyspell-prog-text-faces)
(add-hook 'flyspell-mode-hook #'alectryon--flyspell-hook)
(alectryon--flyspell-hook)
(alectryon--mode-case (alectryon--coq-mode 1) (alectryon--rst-mode 1)))
(t
(unless (alectryon--in-original-mode)
(alectryon--toggle)
(message "Reverted to %s mode." mode-name))
(kill-local-variable 'alectryon--original-mode)
(remove-hook 'write-contents-functions #'alectryon--save t)
(setq-local flyspell-prog-text-faces (remq 'alectryon-comment flyspell-prog-text-faces))
(remove-hook 'flyspell-mode-hook #'alectryon--flyspell-hook)
(alectryon--flyspell-unhook)
(alectryon--mode-case (alectryon--coq-mode -1) (alectryon--rst-mode -1))))
(alectryon--refontify))

Expand Down

0 comments on commit 8a1f305

Please sign in to comment.