1

flyspell-auto-correct-previous-word is a great way to quickly correct mistakes in a buffer. I get a lot of false positives though, and I would like to quickly add them to my dictionary in an analogous way.

How can I make a command to do this? Confusingly, flyspell-auto-correct-previous-pos is always nil for me.

1

1 Answer 1

1

If I understand your question correctly this should solve it. The add-false-postive command jumps back to the previous error, adds it to the dict, cleans up and jumps back.

(defun goto-previous-spelling-error () "Go to previous spelling error." (interactive) (push-mark (point) t nil) (let ((pos (point)) (min (point-min))) (while (and (> pos min) (let ((ovs (overlays-at pos)) (r '())) (while (and (not r) (consp ovs)) (if (flyspell-overlay-p (car ovs)) (setq r t) (setq ovs (cdr ovs)))) (not r))) (backward-word 1) (setq pos (point))) (goto-char pos))) (defun add-false-postive () "Add previous false positive to dict" (interactive) (goto-previous-spelling-error) (let* ((flyspell-info (flyspell-get-word)) (word (car flyspell-info)) (bounds (cdr flyspell-info))) (flyspell-do-correct 'save nil word (point) (car bounds) (cadr bounds) (point)) (flyspell-delete-region-overlays (car bounds) (cadr bounds)) (exchange-point-and-mark) (deactivate-mark)) 
1
  • This is excellent. I would recommend adding (deactivate-mark) to your add-false-positive function body, as currently it leaves the mark at the last flyspell error, which looks odd for people using transient mark mode. Commented Sep 23, 2015 at 18:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.