Skip to content
master
Go to file
Code

Latest commit

Files

Permalink
Failed to load latest commit information.

README.org

wucuo

wucuo.png

https://travis-ci.org/redguardtoo/wucuo.svg?branch=master http://melpa.org/packages/wucuo-badge.svg http://stable.melpa.org/packages/wucuo-badge.svg

Fastest solution to spell check camel case code or plain text

  • Fast
  • Works out of box
  • Support both Aspell and Hunspell
  • Powerful and easy to set up

Screenshot:

demo.png

huge-file-demo-nq8.png

Install

Wucuo is uploaded to http://melpa.org. The best way to install is Emacs package manager.

Setup

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.

Usage

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.

Please note Wucuo is a complete solution. You should turn off flyspell-prog-mode and flyspell-mode before using this program.

Flyspell is a packages which Wucuo is based on. So the good news is your configuration for flyspell still works.

Flyspell provides two minor modes, flyspell-prog-mode and flyspell-mode which uses Flyspell API.

This program replaces these two minor modes, using same Flyspell API.

See wucuo-check-nil-font-face on how to check plain text (text without font).

Tips

Configure Flyspell

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.

aspell configuration sample

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 since Aspell 0.60.8 
;; @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"))

hunspell configuration sample

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!
(setq ispell-local-dictionary "myhunspell") ; "myhunspell" is key to lookup in `ispell-local-dictionary-alist`
;; two dicitionaries "en_US" and "zh_CN" are used. Feel free to remove "zh_CN"
(setq ispell-local-dictionary-alist
      '(("myhunspell" "[[: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))

Spell check file and directory

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 (using Aspell),

emacs -batch -Q -l ~/projs/wucuo/wucuo.el --eval '(let* ((ispell-program-name "aspell") (ispell-extra-args (wucuo-aspell-cli-args t))) (wucuo-spell-check-directory "."))'

Start mode

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.

Checking buffer or region only is more efficient than flyspell-mode.

Skip spell checking under certain circumstances

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)))))

Change dictionaries

See wucuo-aspell-language-to-use and wucuo-hunspell-dictionary-base-name

Only check words with specified font faces

(setq wucuo-personal-font-faces-to-check '(font-lock-comment-face))

Flyspell wrongly mark some word as typo

There are three solutions.

Emacs Lisp setup

(defun my-checker (word)
  "If WORD is typo, return t."
  t)
(setq wucuo-extra-predicate #'my-checker)

Create personal dictionary

Aspell, run M-x wucuo-create-aspell-personal-dictionary. The plain text dictionary ~/.aspell.en.pws is created if its option --lang is “en” (“en” is default value).

Hunspell, run M-x wucuo-create-hunspell-personal-dictionary. The plain text dictionary ~/.hunspell_en_US is created if its option -d contains “en_US”.

Here is my ~/.aspell.en.pws.

Hunspell’s personal dictionary is same as aspell.

Speed up checking if aspell is used

(setq ispell-extra-args "--run-together")

Ignore major mode’s own flyspell predicate

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"))

Detect font face at point

Use wucuo-current-font-face to detect font face at point.

Skip spell checking when buffer or visible region is too big

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.

Contact me

Report bug at https://github.com/redguardtoo/wucuo.

About

Fastest solution to spell check camel case code or plain text

Resources

Packages

No packages published

Languages

You can’t perform that action at this time.