The winget utility on Windows 11 is a revelation. Here’s how I set it up.
in my main init.el:
;; Check spelling with flyspell and hunspell
;; https://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html
(use-package flyspell
:bind
("C-c w s s" . ispell)
("C-c w s i" . endless/ispell-word-then-abbrev)
("C-;" . flyspell-auto-correct-previous-word)
(:map ctl-x-map
("C-i" . endless/ispell-word-then-abbrev) ; see
)
:custom
(ispell-dictionary ews-hunspell-dictionaries)
(flyspell-mark-duplications-flag nil) ;; Writegood mode does this
(org-fold-core-style 'overlays) ;; Fix Org mode bug
(flyspell-prog-text-faces '(font-lock-comment-face font-lock-doc-face))
:defer t
:hook
(text-mode . flyspell-mode)
)
This code from endlesspraentheses goes in my ews.el library:
;; ispell and abbrev, the Perfectâ„¢ auto-correct
;;
(add-to-list ‘ispell-skip-region-alist ‘(“^\s*:PROPERTIES\:$” . “^\s*:END\:$”))
(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”)))
)
Emacs on Mac, be it NS or Cocoa, works well with the brew installed hunspell.
brew install hunspell
In my mac-ns.el (which loads in my init.el):
(use-package flyspell
:custom
(ispell-program-name "hunspell")
)
All I do here is set the hunspell executable.
In Windows 11 as administrator I run the following:
winget install fsfhu.hunspell
… and download the dictionaries as described by VXLabs here. I placed the extracted files in a synced dict directory linked to from my home.
(use-package flyspell
:custom
(ispell-program-name "~/AppData/Local/Microsoft/WinGet/Links/hunspell.exe")
(ispell-local-dictionary "en_US")
(ispell-local-dictionary-alist '(("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_US") nil utf-8)))
:init
(setopt
ispell-hunspell-dict-paths-alist '(("en_US" "~/plrjorg/dict/en_US.aff"))
)
)
For completion’s sake, here’s the one little defcustom from Emacs Writing Studio:
(defcustom ews-hunspell-dictionaries "en_US"
"Comma-separated list of Hunspell dictionaries."
:group 'ews
:type 'list)
Apologies for the janky formatting yet again.
