Skip to content

Commit

Permalink
now hunspell can check camel case word
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen Bin committed Jul 6, 2018
1 parent ab5cbda commit 782f32e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
15 changes: 15 additions & 0 deletions README.org
Expand Up @@ -97,6 +97,21 @@ But my =w3m= based utilities can open video/audio/image with the help of =w3m=.
- I recommend aspell for programmers. Non-programmers find hunspell is better on typo correction

If you use hunspell, check [[http://blog.binchen.org/posts/what-s-the-best-spell-check-set-up-in-emacs.html][my article]]. Please note the hunspell executable understands either unix format path or windows format path but not both. You need figure out hunspell version you are using.

You can set =force-to-use-hunspell= in =init-spelling.el= if you prefer hunspell.

This seutp can spell check camel case words either using aspell or hunspell.

Aspell's default personal English dictionary is =$HOME/.aspell.en.pws=. It's content is like:
#+begin_src conf
personal_ws-1.1 en 4
ABN
ACC
ACN
ACT
#+end_src

Hunspell's default personal English dictionary is =$HOME/.hunspell_en_US=. The file format is same as aspell.
**** sbcl (lisp environment)
- Required by lisp =slime=
- Install through OS package manager
Expand Down
53 changes: 40 additions & 13 deletions lisp/init-spelling.el
Expand Up @@ -39,15 +39,30 @@
"A callback to check WORD. Return t if WORD is typo.")

(defun my-flyspell-predicate (word)
"Use aspell to check WORD. If it's typo return true."
(if (string-match-p "^&"
(shell-command-to-string (format "echo %s | %s %s pipe"
word
ispell-program-name
(mapconcat 'identity
(flyspell-detect-ispell-args t)
" "))))
t))
"Use aspell to check WORD. If it's typo return t."
(let* ((cmd (cond
;; aspell: `echo "helle world" | aspell pipe`
((string-match-p "aspell$" ispell-program-name)
(format "echo \"%s\" | %s pipe"
word
ispell-program-name))
;; hunspell: `echo "helle world" | hunspell -a -d en_US`
(t
(format "echo \"%s\" | %s -a -d en_US"
word
ispell-program-name))))
(cmd-output (shell-command-to-string cmd))
rlt)
;; (message "word=%s cmd=%s" word cmd)
;; (message "cmd-output=%s" cmd-output)
(cond
((string-match-p "^&" cmd-output)
;; it's a typo because at least one sub-word is typo
(setq rlt t))
(t
;; not a typo
(setq rlt nil)))
rlt))

(defun js-flyspell-verify ()
(let* ((case-fold-search nil)
Expand All @@ -69,12 +84,15 @@
(cond
((not font-matched)
(setq rlt nil))
((not (string-match-p "aspell$" ispell-program-name))
;; Only override aspell's result
(setq rlt t))

;; ((not (string-match-p "aspell$" ispell-program-name))
;; ;; Only override aspell's result
;; (setq rlt t))

;; ignore two character word
((< (length (setq word (thing-at-point 'word))) 2)
(setq rlt nil))

;; handle camel case word
((and (setq subwords (split-camel-case word)) (> (length subwords) 1))
(let* ((s (mapconcat (lambda (w)
Expand All @@ -86,6 +104,8 @@
(t
w))) subwords " ")))
(setq rlt (my-flyspell-predicate s))))

;; `extra-flyspell-predicate' actually do nothing by default
(t
(setq rlt (funcall extra-flyspell-predicate word))))
rlt))
Expand Down Expand Up @@ -145,9 +165,16 @@ Please note RUN-TOGETHER will make aspell less capable. So it should only be use
;; hunspell will search for a dictionary called `en_US' in the path specified by
;; `$DICPATH'

(defvar force-to-use-hunspell nil
"If t, force to use hunspell. Or else, search aspell at first and fall
back to hunspell if aspell is not found.")

(cond
((executable-find "aspell")
;; use aspell
((and (not force-to-use-hunspell) (executable-find "aspell"))
(setq ispell-program-name "aspell"))

;; use hunspell
((executable-find "hunspell")
(setq ispell-program-name "hunspell")
(setq ispell-local-dictionary "en_US")
Expand Down

0 comments on commit 782f32e

Please sign in to comment.