我认为flyspell-correct-word
的行为应该扩展到一个命令,该命令可以纠正所有出现错误拼写的单词。这当然与底层拼写纠正中的句法错误无关。我不知道aspell / ispell是否支持这种修正。它还希望将这两者组合成一个命令,用于查询用户是否要以query-replace
方式纠正 next 出现(y,n,q,Y,N ,!) 。有没有人实施过这些想法?
答案 0 :(得分:3)
尝试将以下代码添加到.emacs中,这似乎可以执行您要求的操作(虽然它不会提示您进行替换(这看起来有点麻烦)):
(setq flyspell-insert-function 'flyspell-insert-and-replace-all)
(defvar flyspell-last-replacements nil)
(defun flyspell-insert-and-replace-all (word)
(unless (eq flyspell-auto-correct-pos pos) ; same check as done in flyspell-auto-correct-word
(setq flyspell-last-replacements nil))
(save-excursion
(dolist (word-markers flyspell-last-replacements)
(delete-region (car word-markers) (cdr word-markers))
(goto-char (car word-markers))
(insert word)))
(insert word)
(save-excursion
(let ((do-replacement (not flyspell-last-replacements)))
(while (re-search-forward (concat "\\<" flyspell-auto-correct-word "\\>") nil t)
(replace-match word)
;; and, when doing first search/replace, record all the positions
(when do-replacement
(let ((end-marker (point-marker))
(begin-marker (make-marker)))
(set-marker begin-marker (- (point) (length word)))
(set-marker-insertion-type end-marker t)
(set-marker-insertion-type begin-marker nil)
(add-to-list 'flyspell-last-replacements (cons begin-marker end-marker))))))))