redguardtoo / emacs.d

Fast and robust Emacs setup.
http://blog.binchen.org
GNU General Public License v3.0
2.39k stars 619 forks source link

[Question] How to add word to dict to pass the spell check, and where is the dict position? #1017

Closed sbwcwso closed 1 year ago

redguardtoo commented 1 year ago

I use wucuo which bases on flyspell, so you need set up flyspell.

See http://blog.binchen.org/posts/what-s-the-best-spell-check-set-up-in-emacs/

The cli program could be aspell or hunspell.

sbwcwso commented 1 year ago

I use wucuo which bases on flyspell, so you need set up flyspell.

See http://blog.binchen.org/posts/what-s-the-best-spell-check-set-up-in-emacs/

The cli program could be aspell or hunspell.

Thank you, I found the follow function from EmacsWiki: Fly Spell which works well.

;;; --------------------------------------------------- adding words to flyspell

(eval-when-compile (require 'cl))

(defun append-aspell-word (new-word)
 (let ((header "personal_ws-1.1")
       (file-name (substitute-in-file-name "$HOME/.aspell.en.pws"))
       (read-words (lambda (file-name)
                    (let ((all-lines (with-temp-buffer
                                      (insert-file-contents file-name)
                                      (split-string (buffer-string) "\n" t))))
                     (if (null all-lines)
                       ""
                      (split-string (mapconcat 'identity (cdr all-lines) "\n")
                                    nil 
                                    t))))))
  (when (file-readable-p file-name)
   (let* ((cur-words (eval (list read-words file-name)))
          (all-words (delq header (cons new-word cur-words)))
          (words (delq nil (remove-duplicates all-words :test 'string=))))
    (with-temp-file file-name     
     (insert (concat header 
                     " en "
                     (number-to-string (length words))
                     "\n"
                     (mapconcat 'identity (sort words #'string<) "\n"))))))
  (unless (file-readable-p file-name)
   (with-temp-file file-name
    (insert (concat header " en 1\n" new-word "\n")))))
 (ispell-kill-ispell t) ; restart ispell
 (flyspell-mode)
 (flyspell-mode))

(defun append-aspell-current ()
 "Add current word to aspell dictionary"
 (interactive)
 (append-aspell-word (thing-at-point 'word)))
redguardtoo commented 1 year ago

See https://github.com/redguardtoo/wucuo#solution-2-create-a-personal-dictionary I usually manually edit my personal dictionary directly.