diff options
author | Alan Pearce | 2017-04-24 15:44:07 +0200 |
---|---|---|
committer | Alan Pearce | 2017-04-24 15:44:07 +0200 |
commit | dda94cd1c0e1b3ec5f7c7d6002c75b4ce90a2c68 (patch) | |
tree | 265de076785c07076f5d5975a2ac67e18bd03f06 /emacs/.emacs.d | |
parent | ebf4da622c7c25ea7768de7b94925db7c4a1e8c4 (diff) | |
download | nixfiles-dda94cd1c0e1b3ec5f7c7d6002c75b4ce90a2c68.tar.lz nixfiles-dda94cd1c0e1b3ec5f7c7d6002c75b4ce90a2c68.tar.zst nixfiles-dda94cd1c0e1b3ec5f7c7d6002c75b4ce90a2c68.zip |
Emacs: Spell-check camelCased words correctly
Configure "run-together" for aspell
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r-- | emacs/.emacs.d/init.org | 42 |
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 |