From ea16bb66c3b4ca2d8a093af669e47517bc6aeeab Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Fri, 13 Nov 2020 15:37:20 +0100 Subject: [PATCH 1/2] Fix behaviour without aspell If aspell (or a spell-fu acceptable equivalent) warn the user. If it failed to bind +spell-correct-interface, and bind that. Remove previous hack. It prevents use of +spell/correct if spell-fu does not try to highlight a word. This is extreamly common is docstrings, for example. I think having +spell/correct should check any word it is called upon, even without general text highlighting. --- modules/checkers/spell/autoload/+spell-fu.el | 20 ++++++++++++++------ modules/checkers/spell/config.el | 14 ++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/modules/checkers/spell/autoload/+spell-fu.el b/modules/checkers/spell/autoload/+spell-fu.el index f8d26a3e2..cf65b39fe 100644 --- a/modules/checkers/spell/autoload/+spell-fu.el +++ b/modules/checkers/spell/autoload/+spell-fu.el @@ -50,12 +50,20 @@ (defun +spell/correct () "Correct spelling of word at point." (interactive) - ;; HACK Fake awareness for our personal dictionary by stopping short if - ;; spell-fu hasn't highlighted the current word. This is necessary - ;; because ispell/aspell struggles to find our - ;; `ispell-personal-dictionary' if it's not in $HOME. - (unless (memq 'spell-fu-incorrect-face (face-at-point nil t)) - (user-error "%S is correct" (thing-at-point 'word t))) + ;; spell-fu fails to initialize correctly if it can't find aspell or a similar + ;; program. We want to signal the error, not tell the user that every word is + ;; spelled correctly. + (unless (;; This is what spell-fu uses to check for the aspell executable + or (and ispell-really-aspell ispell-program-name) + (executable-find "aspell")) + (user-error "Aspell is required for spell checking")) + ;; HACK When spell-fu fails to initialize correctly, the init form for the + ;; spell-fu use-package! is not called. This leaves emacs to assume that + ;; certain variables are initialized when they are not. We bind what we + ;; need. + (unless (boundp '+spell-correct-interface) + (+spell-defun-correct-interface)) + (ispell-set-spellchecker-params) (save-current-buffer (ispell-accept-buffer-local-defs)) diff --git a/modules/checkers/spell/config.el b/modules/checkers/spell/config.el index 5886d7979..68273c8f3 100644 --- a/modules/checkers/spell/config.el +++ b/modules/checkers/spell/config.el @@ -70,19 +70,21 @@ (eval-if! (not (featurep! +flyspell)) - (use-package! spell-fu - :when (executable-find "aspell") - :hook (text-mode . spell-fu-mode) - :general ([remap ispell-word] #'+spell/correct) - :init + (defun +spell-defun-correct-interface () (defvar +spell-correct-interface (cond ((featurep! :completion ivy) #'+spell-correct-ivy-fn) ((featurep! :completion helm) #'+spell-correct-helm-fn) (#'+spell-correct-generic-fn)) - "Function to use to display corrections.") + "Function to use to display corrections.")) + (use-package! spell-fu + :when (executable-find "aspell") + :hook (text-mode . spell-fu-mode) + :general ([remap ispell-word] #'+spell/correct) + :init + (+spell-defun-correct-interface) (defvar +spell-excluded-faces-alist '((markdown-mode . (markdown-code-face From a31dced7bc7009fd1fd2e5a0d2bf20b505b25baa Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Fri, 13 Nov 2020 20:51:54 +0100 Subject: [PATCH 2/2] Requested changes -- move defvar to preface We can now remove the redundant hack. --- modules/checkers/spell/autoload/+spell-fu.el | 6 ------ modules/checkers/spell/config.el | 13 ++++++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/modules/checkers/spell/autoload/+spell-fu.el b/modules/checkers/spell/autoload/+spell-fu.el index cf65b39fe..25a0a1063 100644 --- a/modules/checkers/spell/autoload/+spell-fu.el +++ b/modules/checkers/spell/autoload/+spell-fu.el @@ -57,12 +57,6 @@ or (and ispell-really-aspell ispell-program-name) (executable-find "aspell")) (user-error "Aspell is required for spell checking")) - ;; HACK When spell-fu fails to initialize correctly, the init form for the - ;; spell-fu use-package! is not called. This leaves emacs to assume that - ;; certain variables are initialized when they are not. We bind what we - ;; need. - (unless (boundp '+spell-correct-interface) - (+spell-defun-correct-interface)) (ispell-set-spellchecker-params) (save-current-buffer diff --git a/modules/checkers/spell/config.el b/modules/checkers/spell/config.el index 68273c8f3..b28bc4b05 100644 --- a/modules/checkers/spell/config.el +++ b/modules/checkers/spell/config.el @@ -70,21 +70,20 @@ (eval-if! (not (featurep! +flyspell)) - (defun +spell-defun-correct-interface () + (use-package! spell-fu + :when (executable-find "aspell") + :hook (text-mode . spell-fu-mode) + :general ([remap ispell-word] #'+spell/correct) + :preface (defvar +spell-correct-interface (cond ((featurep! :completion ivy) #'+spell-correct-ivy-fn) ((featurep! :completion helm) #'+spell-correct-helm-fn) (#'+spell-correct-generic-fn)) - "Function to use to display corrections.")) + "Function to use to display corrections.") - (use-package! spell-fu - :when (executable-find "aspell") - :hook (text-mode . spell-fu-mode) - :general ([remap ispell-word] #'+spell/correct) :init - (+spell-defun-correct-interface) (defvar +spell-excluded-faces-alist '((markdown-mode . (markdown-code-face