Correct few defaults of spell-checking's layer

- 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.
This commit is contained in:
Fabien Dubosson 2015-11-01 17:27:44 +01:00 committed by syl20bnr
parent c0570e7481
commit 456dcb3086
3 changed files with 31 additions and 2 deletions

View File

@ -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 |

View File

@ -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.")

View File

@ -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")