/flyspell-correct

[mirror] Distraction-free words correction with flyspell via selected interface.

Primary LanguageEmacs LispOtherNOASSERTION

flyspell-correct

https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg https://circleci.com/gh/d12frosted/flyspell-correct.svg?style=svg

flyspell-correcthttp://melpa.org/packages/flyspell-correct-badge.svghttps://stable.melpa.org/packages/flyspell-correct-badge.svg
flyspell-correct-ivyhttp://melpa.org/packages/flyspell-correct-ivy-badge.svghttps://stable.melpa.org/packages/flyspell-correct-ivy-badge.svg
flyspell-correct-helmhttp://melpa.org/packages/flyspell-correct-helm-badge.svghttps://stable.melpa.org/packages/flyspell-correct-helm-badge.svg
flyspell-correct-popuphttp://melpa.org/packages/flyspell-correct-popup-badge.svghttps://stable.melpa.org/packages/flyspell-correct-popup-badge.svg

Correcting words with flyspell via custom interface.

Read intro post

This package provides functionality for correcting words via custom interfaces. There are several functions for this:

  • flyspell-correct-wrapper - a beefed wrapper for flyspell-correct-previous and flyspell-correct-next allowing one to correct many words at once (rapid mode) and change correction direction.
  • flyspell-correct-at-point - to correct word at point.
  • flyspell-correct-previous to correct any visible word before the point.
  • flyspell-correct-next to correct any visible word after the point.

In most cases the last function is the most convenient, so don’t forget to bind it.

(define-key flyspell-mode-map (kbd "C-;") #'flyspell-correct-wrapper)

When invoked, it will show the list of corrections suggested by Flyspell.

Most interfaces also allow you to save the new word to your dictionary, accept this spelling in current buffer or for a whole session, or even skip this word (useful in a rapid flow).

Default interface is implemented using completing-read, but it’s highly advised to use flyspell-correct-ido (which comes bundled with this package) or any other interface provided by the following packages: flyspell-correct-ivy, flyspell-correct-helm and flyspell-correct-popup.

Rapid mode

Rapid mode means that you can correct many words in a single invocation of flyspell-correct-wrapper following current direction (usually, backwards). In order to enable it, one should call flyspell-correct-wrapper with universal argument - C-u. For example, C-u C-; will do it.

Deprecations in v0.5

Unfortunately, following functions are renamed and their original name is being deprecated and will be removed in the future (summer 2019).

  • flyspell-correct-next-word-generic -> flyspell-correct-next
  • flyspell-correct-previous-word-generic -> flyspell-correct-previous
  • flyspell-correct-word-generic -> flyspell-correct-at-point

Please make sure to update to new names.

Using flyspell-correct-dummy interface

In order to use flyspell-correct-dummy interface you have to install flyspell-correct package in any preferred way and then add following snippet to relevant part of your init.el file.

(require 'flyspell-correct)
(define-key flyspell-mode-map (kbd "C-;") 'flyspell-correct-wrapper)

This interface does not allow to save or accept current spelling.

Or via use-package.

(use-package flyspell-correct
  :bind ("C-M-;" . flyspell-correct-wrapper))

Using flyspell-correct-ivy interface

In order to use flyspell-correct-ivy interface you have to install flyspell-correct-ivy package in any preferred way and then add following snippet to relevant part of your init.el file.

(require 'flyspell-correct-ivy)
(define-key flyspell-mode-map (kbd "C-;") 'flyspell-correct-wrapper)

Or via use-package.

(use-package flyspell-correct-ivy
  :bind ("C-M-;" . flyspell-correct-wrapper)
  :init
  (setq flyspell-correct-interface #'flyspell-correct-ivy))

Note that in order to access actions in ivy interface you need to press M-o. More on ivy mini buffer key bindings you can read in official documentation.

Using flyspell-correct-avy-menu interface

In order to use flyspell-correct-avy-menu interface you have to install flyspell-correct-avy-menu package in any preferred way and then add following snippet to relevant part of your init.el file.

(require 'flyspell-correct-avy-menu)
(define-key flyspell-mode-map (kbd "C-;") 'flyspell-correct-wrapper)

Or via use-package.

(use-package flyspell-correct-avy-menu
  :bind ("C-M-;" . flyspell-correct-wrapper)
  :init
  (setq flyspell-correct-interface #'flyspell-correct-avy-menu))

Using flyspell-correct-ido interface

In order to use flyspell-correct-ido interface you have to install flyspell-correct package in any preferred way and then add following snippet to relevant part of your init.el file.

(require 'flyspell-correct-ido)
(define-key flyspell-mode-map (kbd "C-;") 'flyspell-correct-wrapper)

Or via use-package.

(use-package flyspell-correct-ido
  :bind ("C-M-;" . flyspell-correct-wrapper)
  :init
  (setq flyspell-correct-interface #'flyspell-correct-ido))

Using flyspell-correct-helm interface

In order to use flyspell-correct-helm interface you have to install flyspell-correct-helm package in any preferred way and then add following snippet to relevant part of your init.el file.

(require 'flyspell-correct-helm)
(define-key flyspell-mode-map (kbd "C-;") 'flyspell-correct-wrapper)

Or via use-package.

(use-package flyspell-correct-helm
  :bind ("C-M-;" . flyspell-correct-wrapper)
  :init
  (setq flyspell-correct-interface #'flyspell-correct-helm))

Using flyspell-correct-popup interface

In order to use flyspell-correct-popup interface you have to install flyspell-correct-popup package in any preferred way and then add following snippet to relevant part of your init.el file.

(require 'flyspell-correct-popup)
(define-key flyspell-mode-map (kbd "C-;") 'flyspell-correct-wrapper)

Or via use-package.

(use-package flyspell-correct-popup
  :bind ("C-M-;" . flyspell-correct-wrapper)
  :init
  (setq flyspell-correct-interface #'flyspell-correct-popup))

There are some cool usability suggestions by @alphapapa shared in d12frosted/flyspell-correct#30 that you might want to use. Enjoy!

Custom interfaces

One can easily implement custom interface for flyspell-correct-at-point (which is used by other correct functions). It has to be a function that takes two arguments - candidates and incorrect word. It has to return either replacement word or (command, word) tuple, where command can be one of the following:

  • skip - meaning that no action is required for current incorrect word;
  • save - meaning that the word must be saved in a dictionary;
  • session - meaning that the word must be saved for the current session;
  • buffer - meaning that the word must be saved for the current buffer.

Check flyspell-correct-popup for example of interface that uses this feature.

Auto correction mode

/Take my advice and don’t use this functionality unless you find flyspell-correct-wrapper function useless for your purposes. Seriously, just try named function for completion. You can find more info in this comment./

This package also provides auto correction minor mode called flyspell-correct-auto-mode. When enabled it will automatically invoke flyspell-correct-previous-word-generic after certain delay configured by flyspell-correct-auto-delay when there is at least one incorrect word.

(add-hook 'flyspell-mode-hook #'flyspell-correct-auto-mode)

One can also configure interface specially for flyspell-correct-previous-word-generic called by flyspell-correct-auto-mode by setting value of flyspell-correct-auto-mode-interface.

Reasoning

There are already packages like helm-flyspell and flyspell-popup. So why would anyone create yet another similar package? The reason is simple - to support another interface or completion system. flyspell-correct started because ivy was missing similar to helm-flyspell package. But I didn’t want to create a package just for ivy. The reasoning is simple - all those packages should have similar functionality but different interface. Adding something new to one of these packages ideally should be reflected in all others. So I decided to create generic package that works with any interfaces. It’s not about one package containing all possible interfaces, but about a package giving you functionality with an interface of your choice.

Screenshots

Ivy interface

images/screenshot-ivy-1.png

images/screenshot-ivy-2.png

Avy Menu interface

TBD

Popup interface

images/screenshot-popup.png

Helm interface

images/screenshot-helm.png

Ido interface

images/screenshot-ido.png

Acknowledgements

This package is available thanks to these people:

Additional thanks to all contributors: