Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest binding? #30

Closed
alphapapa opened this issue Apr 13, 2017 · 0 comments
Closed

Suggest binding? #30

alphapapa opened this issue Apr 13, 2017 · 0 comments

Comments

@alphapapa
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants