From 456dcb3086b730b00f67a0560b696b18e36c26e0 Mon Sep 17 00:00:00 2001 From: Fabien Dubosson Date: Sun, 1 Nov 2015 17:27:44 +0100 Subject: [PATCH] Correct few defaults of spell-checking's layer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Disable `auto-dictionary-mode` by default. Add a layer's variable to enable it. Its behaviour has some impact on user-defined dictionary preferences, it has some bugs in daemon mode, and not all languages are supported. It's why it better to have it disabled by default. - Toggle off `auto-dictionary-mode` when spell-checking is toggled off. - Call `flyspell-buffer` when toggling **on** spell-checking to reveal mistakes (probably the wanted behaviour when activating spell-checking) - When `auto-dictionary-mode` is enabled, if a buffer's dictionary is manually changed with `SPC S d`, it is restored after toggling spell-checking on/off, otherwise `auto-dictionary` will thy to guess it again. --- layers/spell-checking/README.org | 12 ++++++++++++ layers/spell-checking/config.el | 3 +++ layers/spell-checking/packages.el | 18 ++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/layers/spell-checking/README.org b/layers/spell-checking/README.org index bf615be77..fc58f879a 100644 --- a/layers/spell-checking/README.org +++ b/layers/spell-checking/README.org @@ -6,6 +6,7 @@ - [[Layer][Layer]] - [[Spell Checker Configuration][Spell Checker Configuration]] - [[Disabling by default][Disabling by default]] + - [[Enabling auto-dictionary-mode][Enabling auto-dictionary-mode]] - [[Key Bindings][Key Bindings]] * Description @@ -38,6 +39,17 @@ toggled off with ~SPC t S~. You can default this to off by setting the variable '((spell-checking :variables spell-checking-enable-by-default nil))) #+END_SRC +** Enabling auto-dictionary-mode +=auto-dictionary-mode= tries to detect the current language from the buffer +content, and activate the corresponding dictionary. You can enable it by setting +the variable =spell-checking-enable-auto-dictionary= to something other than +=nil=: + +#+BEGIN_SRC emacs-lisp +(setq-default dotspacemacs-configuration-layers + '((spell-checking :variables spell-checking-enable-auto-dictionary t))) +#+END_SRC + * Key Bindings | Key Binding | Description | diff --git a/layers/spell-checking/config.el b/layers/spell-checking/config.el index 72edd529e..16b9b4933 100644 --- a/layers/spell-checking/config.el +++ b/layers/spell-checking/config.el @@ -18,3 +18,6 @@ (defvar spell-checking-enable-by-default t "Enable spell checking by default.") + +(defvar spell-checking-enable-auto-dictionary nil + "Specify if auto-dictionary should be enabled or not.") diff --git a/layers/spell-checking/packages.el b/layers/spell-checking/packages.el index 10c459d75..8db874ae8 100644 --- a/layers/spell-checking/packages.el +++ b/layers/spell-checking/packages.el @@ -20,6 +20,7 @@ (defun spell-checking/init-auto-dictionary () (use-package auto-dictionary :defer t + :if spell-checking-enable-auto-dictionary :init (add-hook 'flyspell-mode-hook 'auto-dictionary-mode))) @@ -36,8 +37,21 @@ (spacemacs|add-toggle spelling-checking :status flyspell-mode - :on (flyspell-mode) - :off (flyspell-mode -1) + :on + (progn + (flyspell-mode) + ;; Redefine the buffer local dictionary if it was set, otherwise + ;; auto-dictionary will replace it with guessed one. + (when (and (fboundp 'adict-change-dictionary) ispell-local-dictionary) + (adict-change-dictionary ispell-local-dictionary)) + ;; Reanalyze the whole buffer to show mistakes. It's probably the + ;; wanted behaviour when activating spell-checking. + (flyspell-buffer)) + :off + (progn + (flyspell-mode -1) + ;; Also disable auto-dictionary when disabling spell-checking. + (when (fboundp 'auto-dictionary-mode) (auto-dictionary-mode -1))) :documentation "Enable automatic spell checking." :evil-leader "tS")