Last active
March 1, 2019 10:20
-
-
Save c02y/56c0c4303f125a700026b043b4898094 to your computer and use it in GitHub Desktop.
about flyspell of Emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/anaconda3/share/emacs/26.1/lisp/textmodes/flyspell* | |
condai conda-forge hunspell | |
;; spell check | |
;; find aspell and hunspell automatically | |
(cond | |
;; try hunspell at first | |
;; if hunspell does NOT exist, use aspell | |
;; Using hunspell may produce the "Error enabling Flyspell mode: (stringp nil)" problem | |
((executable-find "hunspell") | |
(setq ispell-program-name "hunspell") | |
(setq ispell-local-dictionary "en_US") | |
(setq ispell-local-dictionary-alist | |
;; Please note the list `("-d" "en_US")` contains ACTUAL parameters passed to hunspell | |
;; You could use `("-d" "en_US,en_US-med")` to check with multiple dictionaries | |
'(("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_US") nil utf-8) | |
))) | |
((executable-find "aspell") | |
(setq ispell-program-name "aspell") | |
;; Please note ispell-extra-args contains ACTUAL parameters passed to aspell | |
(setq ispell-extra-args '("--sug-mode=ultra" "--lang=en_US")) | |
(message "hunspell not found, use aspell for spell-check!"))) | |
(setq ispell-personal-dictionary "~/.emacs.d/ispell_en_US") | |
(require 'flyspell) | |
(dolist (mode '(prog-mode-hook | |
emacs-lisp-mode-hook | |
python-mode-hook)) | |
(add-hook mode | |
'(lambda () | |
(flyspell-prog-mode)))) | |
;; in prog-mode, make flyspell only work in comments | |
;; original value: '(font-lock-string-face font-lock-comment-face font-lock-doc-face) | |
(with-eval-after-load 'flyspell-prog-mode | |
(setq flyspell-prog-text-faces | |
(delq 'font-lock-string-face | |
flyspell-prog-text-faces))) | |
(eval-after-load "flyspell" | |
'(define-key flyspell-mouse-map [mouse-1] #'flyspell-correct-word) | |
;;(define-key flyspell-mouse-map [mouse-3] #'undefined) | |
) | |
(require 'flyspell-correct-helm) | |
(bind-keys :map flyspell-mode-map | |
:prefix-map my-flyspell-mode-prefix-map | |
:prefix "C-M-x" | |
;; use `C-u prefix i` to correct multiple words(backwards), C-u C-u to forwards | |
("x" . flyspell-correct-wrapper) | |
("b" . flyspell-buffer) | |
("n" . flyspell-correct-next) | |
("p" . flyspell-correct-previous) | |
;; correct the wrong word with prefix+i, next time auto-correct it, defined bellow | |
("i" . endless/ispell-word-then-abbrev)) | |
;; | |
(add-hook 'ispell-initialize-spellchecker-hook | |
(lambda () | |
(setq ispell-base-dicts-override-alist | |
'((nil ; default | |
"[A-Za-z]" "[^A-Za-z]" "[']" t | |
("-d" "en_US" "-i" "utf-8") nil utf-8) | |
("american" ; Yankee English | |
"[A-Za-z]" "[^A-Za-z]" "[']" t | |
("-d" "en_US" "-i" "utf-8") nil utf-8) | |
("british" ; British English | |
"[A-Za-z]" "[^A-Za-z]" "[']" t | |
("-d" "en_GB" "-i" "utf-8") nil utf-8))))) | |
;; | |
;; source: http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html | |
(defun endless/simple-get-word () | |
(car-safe (save-excursion (ispell-get-word nil)))) | |
(defun endless/ispell-word-then-abbrev (p) | |
"Call `ispell-word', then create an abbrev for it. | |
With prefix P, create local abbrev. Otherwise it will | |
be global. | |
If there's nothing wrong with the word at point, keep | |
looking for a typo until the beginning of buffer. You can | |
skip typos you don't want to fix with `SPC', and you can | |
abort completely with `C-g'." | |
(interactive "P") | |
(let (bef aft) | |
(save-excursion | |
(while (if (setq bef (endless/simple-get-word)) | |
;; Word was corrected or used quit. | |
(if (ispell-word nil 'quiet) | |
nil ; End the loop. | |
;; Also end if we reach `bob'. | |
(not (bobp))) | |
;; If there's no word at point, keep looking | |
;; until `bob'. | |
(not (bobp))) | |
(backward-word) | |
(backward-char)) | |
(setq aft (endless/simple-get-word))) | |
(if (and aft bef (not (equal aft bef))) | |
(let ((aft (downcase aft)) | |
(bef (downcase bef))) | |
(define-abbrev | |
(if p local-abbrev-table global-abbrev-table) | |
bef aft) | |
(message "\"%s\" now expands to \"%s\" %sally" | |
bef aft (if p "loc" "glob"))) | |
(user-error "No typo at or before point")))) | |
(setq save-abbrevs 'silently) | |
(setq-default abbrev-mode t) | |
install flyspell-correct-helm package | |
;; put this after org-mode config part, or flyspell-mode won't be enabled, even eval-after-load won't work | |
(add-hook 'org-mode-hook 'flyspell-mode) | |
change | |
(flyspell-mode . "") | |
to | |
(flyspell-mode. " Fs") | |
rename ~/.emacs.d/hunspell_en_US to ~/.emacs.d/ispell_en_US | |
according to https://stackoverflow.com/questions/21880139/what-is-with-eval-after-load-in-emacs-lisp | |
change all eval-after-load to with-eval-after-load | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment