Honestly, I don't know if this is a good way to solve this issue, but it works (though fragile) and it shows a method that is applicable in other case.
Test case (since the Young Grandfather (tYG) forgot to post one):
(with-temp-buffer
(setq ispell-program-name "hunspell")
(switch-to-buffer (current-buffer))
(insert "speling")
(ispell-word))
You see what tYG talks about by evaluating and clicking r
.
(Leave out the hunspell
part if that's better for you).
Since ispell-command-loop
is very complicated, it's not easy to mess with its internals. But we can use a fragile advice around it, see (info "(elisp) Advising Functions")
. Note that we are using Stefan Monnier's new, hip and super-nice nadvice.el
package!
(defun rasmus/ispell-loop-get-rid-of-misspeled-word (orig-fun &rest args)
"Around-advice to avoid the misspeled word when typing r in ispell."
(require 'cl)
(cl-letf* (((symbol-function #'read-string*) (symbol-function #'read-string))
((symbol-function #'read-string)
(lambda (prompt &optional initial-input history default-value
inherit-input-method)
(if (equal prompt "Replacement for: ")
(read-string* prompt)
(read-string* prompt initial-input history default-value
inherit-input-method)))))
(apply orig-fun args)))
(advice-add 'ispell-command-loop :around
#'rasmus/ispell-loop-get-rid-of-misspeled-word)
Run the test again. The misspelled word should be gone.
Bonus: do C-h
f
ispell-command-loop
C-j
. It should contain a line like
:around advice: `rasmus/ispell-loop-get-rid-of-misspeled-word'
.
(read-string "Replacement for: " word nil)
to(read-string "Replacement for: " nil nil)
which is a bit of a hack, but does work. Having a limited knowledge of emacs and ispell, I would prefer something I can stick in my .emacs file :)