From dda94cd1c0e1b3ec5f7c7d6002c75b4ce90a2c68 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 24 Apr 2017 15:44:07 +0200 Subject: Emacs: Spell-check camelCased words correctly Configure "run-together" for aspell --- emacs/.emacs.d/init.org | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) 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 -- cgit 1.4.1