-;; Time-stamp: <2015-03-16 09:26:03 kmodi>
+;; Time-stamp: <2015-03-17 09:36:58 kmodi>
 ;;
 ;; Spell check
 ;; ispell, flyspell

;; http://blog.binchen.org/posts/what-s-the-best-spell-check-set-up-in-emacs.html

(use-package ispell
    :defer t
    :config
    (progn
      (cond

         (setq ispell-program-name "hunspell")
         (setq ispell-extra-args   '("-d en_US"))))
      ;; Save a new word to personal dictionary without asking
      (setq ispell-silently-savep t)

      (use-package flyspell
          :config
        (progn
          (setq flyspell-use-meta-tab nil)
          ;; Stop flyspell overriding other key bindings
          (define-key flyspell-mode-map (kbd "C-;") nil)
          (define-key flyspell-mode-map (kbd "C-,") nil)
          (define-key flyspell-mode-map (kbd "C-.") nil)
          (define-key flyspell-mode-map "\M-\t"     nil)

          (add-hook 'prog-mode-hook #'flyspell-prog-mode)
          (with-eval-after-load 'auto-complete
            (ac-flyspell-workaround))
          ;; https://github.com/larstvei/dot-emacs#flyspell
          (add-hook 'text-mode-hook #'turn-on-flyspell)
          (add-hook 'org-mode-hook  #'turn-on-flyspell)

          ;; Flyspell signals an error if there is no spell-checking tool is installed.
          ;; We can advice turn-on=flyspell and flyspell-prog-mode to only try to enable
          ;; flyspell if a spell-checking tool is available.
          (defadvice turn-on-flyspell (around check nil activate)
            "Turns on flyspell only if a spell-checking tool is installed."
            (when (executable-find ispell-program-name)
              ad-do-it))
          (defadvice flyspell-prog-mode (around check nil activate)
            "Turns on flyspell only if a spell-checking tool is installed."
            (when (executable-find ispell-program-name)
              ad-do-it))

          (bind-keys
           :map modi-mode-map
           ("<f12>" . flyspell-auto-correct-previous-word))))))


(provide 'setup-spell)
