Fastest solution to spell check camel case code or plain text
- Fast
- Spell check camel case code without any extra setup
- Support both Aspell and Hunspell
- Powerful and easy to set up
Screenshot:
Wucuo is uploaded to http://melpa.org. The best way to install is Emacs package manager.
If using GNU Guix, Wucuo and its dependencies can be installed via guix install emacs-guix
.
Please install either Aspell or Hunspell and the dictionaries at first.
This program does not mess up your Flyspell configuration. It assumes Flyspell is already configured properly.
But if you get some problem on Flyspell configuration, check sample configuration in “Tips” section.
Add below code into ~/.emacs
to enable wucuo
,
(add-hook 'prog-mode-hook #'wucuo-start)
(add-hook 'text-mode-hook #'wucuo-start)
The spell checking starts when current buffer is saved.
See wucuo-check-nil-font-face
on how to check plain text (text without font).
Please note Wucuo is a complete solution. You should turn off flyspell-prog-mode
and flyspell-mode
before using this program.
Wucuo uses Flyspell API. So the good news is your configuration for flyspell still works.
Flyspell provides two minor modes, flyspell-prog-mode
and flyspell-mode
. They also use Flyspell API.
This program replaces these two minor modes.
Flyspell configuration is shared by flyspell-prog-mode
, flyspell-mode
, and wucuo
.
Even you don’t use this program, you still need configure flyspell.
If your existing Flyspell configuration already works, you don’t need read this section.
This section is to help users who have problem to setup flyspell.
You could read my article What’s the best spell check setup in emacs and my stackexchange answers on flyspell to learn the Flyspell knowledge.
Please install command line program Aspell and insert below code into ~/.emacs
,
(setq ispell-program-name "aspell")
;; You could add extra option "--camel-case" for camel case code spell checking if Aspell 0.60.8+ is installed
;; @see https://github.com/redguardtoo/emacs.d/issues/796
(setq ispell-extra-args '("--sug-mode=ultra" "--lang=en_US" "--run-together" "--run-together-limit=16"))
Please install command line program hunspell and insert below code into ~/.emacs
,
(setq ispell-program-name "hunspell")
;; reset the hunspell so it STOPS querying locale!
;; "en_US" is the key to lookup in `ispell-local-dictionary-alist`
(setq ispell-local-dictionary "en_US")
;; two dictionaries "en_US" and "zh_CN" are used. Feel free to remove "zh_CN"
;; If `ispell-local-dictionary-alist' is nil, `ispell-local-dictionary' is passed
;; to hunpsell cli program as dictionary.
(setq ispell-local-dictionary-alist
'(("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_US" "zh_CN") nil utf-8)))
;; new variable `ispell-hunspell-dictionary-alist' is defined in Emacs
;; If it's nil, Emacs tries to automatically set up the dictionaries.
(when (boundp 'ispell-hunspell-dictionary-alist)
(setq ispell-hunspell-dictionary-alist ispell-local-dictionary-alist))
The function wucuo-spell-check-file
will spell check one file and report typos.
The function wucuo-spell-check-directory
will spell check files under one directory and report typos.
Above functions could be used through Emacs CLI.
Example to use aspell to syntax check all files under current directory,
emacs -batch -Q -L ~/projs/wucuo -l ~/projs/wucuo/wucuo.el --eval '(let ((ispell-program-name "aspell") (ispell-extra-args (wucuo-aspell-cli-args t))) (wucuo-spell-check-directory "."))'
Example to use hunspell to syntax check one file,
emacs -batch -Q -L ~/projs/wucuo -l ~/projs/wucuo/wucuo.el --eval '(let ((ispell-program-name "hunspell") (ispell-local-dictionary "en_US")) (wucuo-spell-check-file "README.org"))'
The default value of wucuo-flyspell-start-mode
is “fast”.
If wucuo-flyspell-start-mode
is “fast”, wucuo-start
calls flyspell-region
to check visible region in current window periodically.
If wucuo-flyspell-start-mode
is “normal”, wucuo-start
calls flyspell-buffer
periodically.
The interval of buffer checking or region checking is controlled by wucuo-update-interval
.
Wucuo only checks typo in current buffer or the visible region. So it’s much faster than flyspell-mode
.
You can define a function in wucuo-spell-check-buffer-predicate
. If the function returns t, the spell checking of current buffer will continue. If it returns nil, the spell checking is skipped.
Here is sample to skip checking in specified major modes,
(setq wucuo-spell-check-buffer-predicate
(lambda ()
(not (memq major-mode
'(dired-mode
log-edit-mode
compilation-mode
help-mode
profiler-report-mode
speedbar-mode
gud-mode
calc-mode
Info-mode)))))
See wucuo-aspell-language-to-use
and wucuo-hunspell-dictionary-base-name
By default, wucuo-font-faces-to-check
has already set up the font faces to spell check. You can adjust this variable to add or remove font faces.
If you only need add some extra font faces to check, it’s recommended to set up wucuo-personal-font-faces-to-check
,
(setq wucuo-personal-font-faces-to-check '(font-lock-comment-face))
There are two solutions.
(defun my-checker (word)
"If WORD is typo, return t."
;; add your own setup code here
t)
(setq wucuo-extra-predicate #'my-checker)
If you use Aspell, run M-x wucuo-create-aspell-personal-dictionary
to create a plain text dictionary ~/.aspell.en.pws
.
The “en” in “.aspell.en.pws” means the personal dictionary is an English dictionary. It’s actually language code assigned to the English. Aspell’s option --lang
uses same language code (“en” is default value).
If you use Hunspell, run M-x wucuo-create-hunspell-personal-dictionary
to create a plain text dictionary ~/.hunspell_en_US
. “en_US” is the language code used by Hunspell’s option -d
.
Here is my .aspell.en.pws.
Hunspell’s personal dictionary is in the same format as Aspell.
Please note it’s reported that the dictionary file should be utf-8 encoded.
(setq ispell-extra-args "--run-together")
Or if you need replace the default configuration of multiple major modes, you can use below code,
(setq wucuo-modes-whose-predicate-ignored '("typescript-mode"))
Use wucuo-current-font-face
to detect font face at point.
In wucuo-flyspell-start-mode
is “normal”, wucuo-spell-check-buffer-max
specifies the maximum size of buffer to check.
In wucuo-flyspell-start-mode
is “fast”, wucuo-spell-check-region-max
specifies the maximum size of visible region to check.
Report bug at https://github.com/redguardtoo/wucuo.