2

我认为flyspell-correct-word应该将的行为扩展到一个命令,该命令可以纠正所有出现的感兴趣的拼写错误的单词。这当然与基础拼写更正中的句法错误无关。我不知道 aspell/ispell 是否支持此类更正。它还想将两者组合成一个命令,询问用户是否要以某种方式更正下一次出现query-replace(y,n,q,Y,N,!)。有没有人实施过这些想法?

4

1 回答 1

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))))))))
于 2011-11-14T17:10:00.567 回答