summary refs log tree commit diff stats
path: root/emacs/.emacs.d
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r--emacs/.emacs.d/init.org42
1 files changed, 41 insertions, 1 deletions
diff --git a/emacs/.emacs.d/init.org b/emacs/.emacs.d/init.org
index a2a664a8..8d25e6cf 100644
--- a/emacs/.emacs.d/init.org
+++ b/emacs/.emacs.d/init.org
@@ -2208,7 +2208,47 @@ I derived a mode for twig, in order to use its =mode-hook=.
 #+BEGIN_SRC emacs-lisp
 (use-package flyspell
   :config (progn
-            (add-hook 'text-mode-hook (lambda () (flyspell-mode +1)))
+            (defun flyspell-detect-ispell-args (&optional run-together)
+              "If RUN-TOGETHER is true, spell check the CamelCase words.
+ Please note RUN-TOGETHER will make aspell less capable. So it should only be used in prog-mode-hook."
+              (let (args)
+                (when ispell-program-name
+                  (cond
+                   ((string-match "aspell$" ispell-program-name)
+                    (setq args (list "--sug-mode=ultra"))
+                    (if run-together
+                        (setq args (append args '("--run-together" "--run-together-limit=16" "--run-together-min=2")))))
+                   ((string-match "hunspell$" ispell-program-name)
+                    (setq args nil))))
+                args))
+            ;; `ispell-extra-args' is *always* used when start CLI aspell process
+            (setq-default ispell-extra-args (flyspell-detect-ispell-args t))
+            ;; (setq ispell-cmd-args (flyspell-detect-ispell-args))
+            (defadvice ispell-word (around my-ispell-word activate)
+              (let ((old-ispell-extra-args ispell-extra-args))
+                (ispell-kill-ispell t)
+                ;; use emacs original arguments
+                (setq ispell-extra-args (flyspell-detect-ispell-args))
+                ad-do-it
+                ;; restore our own ispell arguments
+                (setq ispell-extra-args old-ispell-extra-args)
+                (ispell-kill-ispell t)))
+
+            (defadvice flyspell-auto-correct-word (around my-flyspell-auto-correct-word activate)
+              (let* ((old-ispell-extra-args ispell-extra-args))
+                (ispell-kill-ispell t)
+                ;; use emacs original arguments
+                (setq ispell-extra-args (flyspell-detect-ispell-args))
+                ad-do-it
+                ;; restore our own ispell arguments
+                (setq ispell-extra-args old-ispell-extra-args)
+                (ispell-kill-ispell t)))
+            (setq flyspell-issue-message-flag nil)
+
+            (defun fly-text-mode-hook-setup ()
+              ;; Turn off RUN-TOGETHER option when spell check text-mode
+              (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
+            (add-hook 'text-mode-hook 'fly-text-mode-hook-setup)
             (add-hook 'prog-mode-hook #'flyspell-prog-mode)))
 #+END_SRC