From b644f8abd7caefcf4d491187778ec5622b0e7ea4 Mon Sep 17 00:00:00 2001 From: Fabien Dubosson Date: Tue, 20 Oct 2015 15:05:24 +0200 Subject: [PATCH] Move auto-dictionary to spell-checking and activate it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit moves the – previously disabled – `auto-dictionary` code to the `spell-checking` layer and activate it. It is now enabled by default, but can be disabled by setting `spell-checking-auto-dictionary` to `nil`. `auto-dictionary` comes with some interesting improvements: - Tries to automatically detect what is the language of the buffer and activate the corresponding dictionary. - When a buffer is opened, all spelling mistakes are shown without needing first to be under the cursor. - When the dictionary is changed, the whole buffer is reanalyzed for spelling mistakes (close #2088). --- layers/+distribution/spacemacs/packages.el | 11 ----------- layers/spell-checking/README.org | 13 ++++++++++++- layers/spell-checking/config.el | 7 +++++-- layers/spell-checking/funcs.el | 10 +++++++++- layers/spell-checking/packages.el | 15 ++++++++++++--- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/layers/+distribution/spacemacs/packages.el b/layers/+distribution/spacemacs/packages.el index 10de12b8a..55fe238b5 100644 --- a/layers/+distribution/spacemacs/packages.el +++ b/layers/+distribution/spacemacs/packages.el @@ -17,7 +17,6 @@ ace-window adaptive-wrap aggressive-indent - auto-dictionary auto-highlight-symbol avy buffer-move @@ -168,16 +167,6 @@ (add-hook 'diff-auto-refine-mode-hook 'spacemacs/toggle-aggressive-indent-off) (spacemacs|diminish aggressive-indent-mode " Ⓘ" " I")))) -(defun spacemacs/init-auto-dictionary () - (use-package auto-dictionary - :disabled t - :defer t - :init - (progn - (add-hook 'flyspell-mode-hook '(lambda () (auto-dictionary-mode 1))) - (evil-leader/set-key - "Sd" 'adict-change-dictionary)))) - (defun spacemacs/init-auto-highlight-symbol () (use-package auto-highlight-symbol :defer t diff --git a/layers/spell-checking/README.org b/layers/spell-checking/README.org index 287dab6a0..fe4d6abb6 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]] + - [[#disabling-auto-dictionary][Disabling auto-dictionary]] - [[#key-bindings][Key Bindings]] * Description @@ -29,7 +30,7 @@ dictionary used by =ispell-program-name= (instead of using this variable you can also use the key binding ~SPC S d~). ** Disabling by default -By default, spell-checking is enabled in all available major modes and may be +By default, =spell-checking= is enabled in all available major modes and may be toggled off with ~SPC t S~. You can default this to off by setting the variable =spell-checking-enable-by-default= to =nil=: @@ -38,6 +39,16 @@ 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 +** Disabling auto-dictionary +By default, =spell-checking= tries to detect the current language from the +buffer content, and activate the corresponding dictionary. You can default this +to off by setting the variable =spell-checking-auto-dictionary= to =nil=: + +#+BEGIN_SRC emacs-lisp +(setq-default dotspacemacs-configuration-layers + '((spell-checking :variables spell-checking-auto-dictionary nil))) +#+END_SRC + * Key Bindings | Key Binding | Description | diff --git a/layers/spell-checking/config.el b/layers/spell-checking/config.el index 0e1ba29c5..f9152bde6 100644 --- a/layers/spell-checking/config.el +++ b/layers/spell-checking/config.el @@ -10,11 +10,14 @@ ;; ;;; License: GPLv3 -;; Variables - ;; Command Prefixes (spacemacs/declare-prefix "S" "spelling") +;; Variables + (defvar spell-checking-enable-by-default t "Enable spell checking by default.") + +(defvar spell-checking-auto-dictionary t + "Enable auto-dictionary by default.") diff --git a/layers/spell-checking/funcs.el b/layers/spell-checking/funcs.el index 1a08d6f08..28f57a4ea 100644 --- a/layers/spell-checking/funcs.el +++ b/layers/spell-checking/funcs.el @@ -10,9 +10,17 @@ ;; ;;; License: GPLv3 -(defun spacemacs/add-flyspell-hook (mode &optional target) +(defun spell-checking/add-flyspell-hook (mode &optional target) "Enable flyspell for the given MODE, if `spell-checking-enable-by-default' is true." (when spell-checking-enable-by-default (let ((mode-hook (intern (format "%S-hook" mode)))) (add-hook mode-hook 'flyspell-mode)))) + +(defun spell-checking/change-dictionary () + "Change the dictionary. Use the ispell version if +auto-dictionary is not used, use the adict version otherwise." + (interactive) + (if spell-checking-auto-dictionary + (adict-change-dictionary) + (call-interactively 'ispell-change-dictionary))) diff --git a/layers/spell-checking/packages.el b/layers/spell-checking/packages.el index 944f94f5f..801f5a0a9 100644 --- a/layers/spell-checking/packages.el +++ b/layers/spell-checking/packages.el @@ -12,17 +12,26 @@ (setq spell-checking-packages '( + auto-dictionary flyspell helm-flyspell )) +(defun spell-checking/init-auto-dictionary () + (use-package auto-dictionary + :defer t + :if spell-checking-auto-dictionary + :init + (add-hook 'flyspell-mode-hook 'auto-dictionary-mode))) + (defun spell-checking/init-flyspell () (use-package flyspell :defer t + :commands (spell-checking/change-dictionary) :init (progn - (spacemacs/add-flyspell-hook 'org-mode) - (spacemacs/add-flyspell-hook 'text-mode) + (spell-checking/add-flyspell-hook 'org-mode) + (spell-checking/add-flyspell-hook 'text-mode) (when spell-checking-enable-by-default (add-hook 'prog-mode-hook 'flyspell-prog-mode)) @@ -35,7 +44,7 @@ :evil-leader "tS") (evil-leader/set-key - "Sd" 'ispell-change-dictionary + "Sd" 'spell-checking/change-dictionary "Sn" 'flyspell-goto-next-error)) :config (spacemacs|diminish flyspell-mode " Ⓢ" " S")))