How to log spelling replacements in emacs?

43 Views Asked by At

I want to log to a file the ispell replacements that get made (whether manual r, or from a list 0...)

Every time a "correction" is made, there are two words that are relevant:

  1. The word that ispell identifies as incorrect.
  2. The word that ends up in its place. [maybe "" when its skipped]

I just want to log these pairs to a file for "analysis" (and possibly flashcards)

I am still browsing code to see if there is a place to wedge this in. I see ispell-update-post-hook used in ispell-command-loop but I'm not sure if that's what I want. I also am not sure how I'd both get the above pair of words and write them to a file, as the hook doesn't (elisp ignorance?) seem to provide access.

1

There are 1 best solutions below

0
On

This code does what you've requested. It does not check for duplicates in the file that's generated, it simply appends to the existing file.

(defvar save-ispell-words-file "~/spell_check.txt")
(defadvice ispell-command-loop (after save-ispell-words activate)
  "Save the misspelled words and their replacements"
  (when (or (null ad-return-value)
            (stringp ad-return-value))
    (save-excursion
      (set-buffer (find-file-noselect save-ispell-words-file))
      (goto-char (point-max))
      (insert (format "%s %s\n" (ad-get-arg 2) (if (null ad-return-value) "\"\"" ad-return-value)))
      (save-buffer))))

Tested with Emacs 27.2.