d12frosted / flyspell-correct

Distraction-free words correction with flyspell via selected interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggest binding?

alphapapa opened this issue · comments

Hi,

I just set up this binding and have found it really useful:

(use-package flyspell-correct-popup
  :bind (:map popup-menu-keymap
              ("TAB" . popup-next)
              ("S-TAB" . popup-previous)))

I use it in combination with this function which I bind to C-;.

(defun ap/iedit-or-flyspell ()
  "Call `iedit-mode' or correct misspelling with flyspell, depending..."
  (interactive)
  (if (or iedit-mode
          (and (derived-mode-p 'prog-mode)
               (not (or (nth 4 (syntax-ppss))
                        (nth 3 (syntax-ppss))))))
      ;; prog-mode is active and point is in a comment, string, or
      ;; already in iedit-mode
      (iedit-mode)
    ;; Not prog-mode or not in comment or string
    (if (not (equal flyspell-previous-command this-command))
        ;; FIXME: This mostly works, but if there are two words on the
        ;; same line that are misspelled, it doesn't work quite right
        ;; when correcting the earlier word after correcting the later
        ;; one

        ;; First correction; autocorrect
        (call-interactively 'flyspell-auto-correct-previous-word)
      ;; First correction was not wanted; use popup to choose
      (progn
        (save-excursion
          (undo))  ; This doesn't move point, which I think may be the problem.
        (flyspell-region (line-beginning-position) (line-end-position))
        (call-interactively 'flyspell-correct-previous-word-generic)))))

Here's how this works: if I press the key in a comment or a string, it calls flyspell-auto-correct-previous-word at first, automatically correcting the previous marked misspelling to the initial suggestion. If I press the key again, it undoes the correction and calls flyspell-correct-previous-word-generic, which is set to flyspell-correct-popup, which shows the popup list of suggested corrections, and I can then press TAB and S-TAB to choose one and RET to select it. And if I press C-; in code, it activates iedit-mode instead.

I don't know that you'd want to add all of that to the readme, but I thought that the TAB/S-TAB binding would be generally appreciated by most people, as it's a lot easier than C-n/p for choosing. :)

Thanks for your work on this package! Spell correction is so nice on Emacs now!