• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    Emacs Lisp
  • Created over 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fastest solution to spell check camel case code or plain text

wucuo

wucuo.png

https://github.com/redguardtoo/wucuo/actions/workflows/test.yml/badge.svg 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
  • Spell check camel case code without any extra setup
  • 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.

If using GNU Guix, Wucuo and its dependencies can be installed via guix install emacs-guix.

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.

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.

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

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

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.

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

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.

Wucuo only checks typo in current buffer or the visible region. So it’s much faster 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

Spell check words with specific font faces

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

Flyspell wrongly mark some word as typo

There are two solutions.

Solution 1, set up Emacs with below code,

(defun my-checker (word)
  "If WORD is typo, return t."
  ;; add your own setup code here
  t)
(setq wucuo-extra-predicate #'my-checker)

Solution 2, create a personal dictionary

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.

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.

More Repositories

1

mastering-emacs-in-one-year-guide

Be great at emacs in one year
6,370
star
2

emacs.d

Fast and robust Emacs setup.
Emacs Lisp
2,411
star
3

find-file-in-project

Quick access to project files in Emacs
Emacs Lisp
428
star
4

evil-nerd-commenter

Comment/uncomment lines efficiently. Like Nerd Commenter in Vim
Emacs Lisp
390
star
5

elpa-mirror

Create local emacs package repository. 15 seconds to install 115 packages.
Emacs Lisp
315
star
6

evil-matchit

Vim matchit ported into Emacs
Emacs Lisp
287
star
7

cpputils-cmake

Easy real time C++ syntax check and intellisense if you use CMake
Emacs Lisp
196
star
8

counsel-etags

Fast, energy-saving, and powerful code navigation solution
Emacs Lisp
174
star
9

eacl

eacl - Emacs auto complete lines by grepping project
Emacs Lisp
97
star
10

vc-msg

Show commit message of current line in Emacs
Emacs Lisp
79
star
11

cliphist

Paste from clipboard manager into Emacs
Emacs Lisp
75
star
12

js-comint

js-comint will send the code from Emacs into node.js or rhino
Emacs Lisp
71
star
13

company-ctags

Fastest Emacs auto-completion using Company and Ctags
Emacs Lisp
56
star
14

pyim-tsinghua-dict

用清华大学开放中文词库数据建立的pyim 输入法]词库. 已基于词频统计信息DF值(Document Frequency)优化
Python
48
star
15

mybigword

Use Zipf frequency of each word to extract English big words
Emacs Lisp
38
star
16

org2nikola

export org into html used by static blog generator like https://github.com/getnikola/nikola
Emacs Lisp
27
star
17

myelpa

Mirror of Emacs packages I'm using
23
star
18

vscode-setup

21
star
19

gmail2bbdb

convert gmail contacts to BBDB file, easy to use, robust, no dependency
Emacs Lisp
20
star
20

vscode-matchit

Jump between matching HTML tags and brackets smartly in VS Code. It's ported from Vim matchit by Benji Fisher
TypeScript
20
star
21

find-by-pinyin-dired

Find file by first Pinyin characters of Chinese Hanzi. 输入拼音首字母定位对应的中文目录/文件
Emacs Lisp
18
star
22

imenu-extra

Add extra items into lsp-mode/js2-mode imenu items
Emacs Lisp
15
star
23

redguardtoo.github.io

my blog
HTML
14
star
24

NinjaWebCoder

Use keyboard to copy code from stackoverflow
HTML
14
star
25

test-git-mergetool

toy project to test git mergetool
14
star
26

dianyou

Search/Analyze mails in Gnus
Emacs Lisp
12
star
27

pyim2fcitx

Conver pyim dictionary to fcitx dictionary
Python
12
star
28

lazyflymake

Lightweight syntax checker for Emacs, alternative of `flymake-mode'
Emacs Lisp
11
star
29

shellcop

Analyze errors reported in Emacs builtin shell
Emacs Lisp
10
star
30

evil-mark-replace

replace string in marked region effectively
Emacs Lisp
9
star
31

counsel-bbdb

Quick search&input email from BBDB based on ivy
Emacs Lisp
9
star
32

js2hl

Highlight/rename things using `js2-mode' parser
Emacs Lisp
8
star
33

shenshou

download subtitles from opensubtitles.org
Emacs Lisp
8
star
34

spell-check-code-in-ci

Free and powerful solution to spell check code at Continuous integration server
Makefile
7
star
35

fastdef

Insert terminology faster
Emacs Lisp
6
star
36

diff-lisp

Diff files&strings in pure Emacs Lisp.
Emacs Lisp
6
star
37

root-dotfiles

my dotfiles as root at Linux host
Shell
6
star
38

jqcuo

Powerful and simple solution to spell check code in command line
Emacs Lisp
6
star
39

jest-coverage-for-files-outside-of-root

jest coverage for files outside of root
JavaScript
5
star
40

find-and-ctags

Use `find' and `ctags' for code navigation
Emacs Lisp
5
star
41

portable-percol

portable percol (https://github.com/mooz/percol)
Python
5
star
42

zhfreq

processing chinese text using word frequency data
Emacs Lisp
4
star
43

my-emacs.d-snapshot

Emacs Lisp
4
star
44

AX88772C_Source

my usb to net adapter
C
4
star
45

test-git-blame

A project to test git blame
JavaScript
3
star
46

roblox-mode

Emacs major mode to edit Roblox Studio rbxlx files
Emacs Lisp
3
star
47

org-mime

org html export for text/html MIME emails
3
star
48

perl-recordmydesktop

perl-recordmydesktop.pl is the frontend for recordMyDesktop screencast tool
Prolog
3
star
49

counsel-ctags

Fast code navigation using Universal Ctags
Emacs Lisp
3
star
50

test-git-log

JavaScript
1
star
51

asus-pce-n53-11n-n600

ASUS PCE-N53 wireless patched driver and gentoo installation mini-guide
C
1
star
52

ms-frontend-sandbox

sandbox for interviewers
JavaScript
1
star
53

helloworld

hello world
C
1
star
54

wxwidgets-help

Look up wxWidgets API in Emacs by using local html manual
Emacs Lisp
1
star