Homepage: https://github.com/clemera/frog-menu
Author: Clemens Radermacher
Updated:
Quickly pick items from ad hoc menus
This package lets you quickly pick strings from ad hoc menus. Just like a
frog would catch a fly. The menu is built "on the fly" from a collection of
strings. It's presented to the user to choose one of them. One example
where this kind of menu is useful are spelling correction suggestions.
To invoke the menu users can call `frog-menu-read'. How items are displayed
and chosen depends on `frog-menu-type'. The default type `avy-posframe'
uses `avy' and `posframe'. Their handler functions can be used as reference
if you want to define a new `frog-menu-type'.
Here is an example how you would use `frog-menu-read' to implement a
`flyspell-correct-interface':
(defun frog-menu-flyspell-correct (candidates word)
"Run `frog-menu-read' for the given CANDIDATES.
List of CANDIDATES is given by flyspell for the WORD.
Return selected word to use as a replacement or a tuple
of (command . word) to be used by `flyspell-do-correct'."
(let* ((corrects (if flyspell-sort-corrections
(sort candidates 'string<)
candidates))
(actions `(("C-s" "Save word" (save . ,word))
("C-a" "Accept (session)" (session . ,word))
("C-b" "Accept (buffer)" (buffer . ,word))
("C-c" "Skip" (skip . ,word))))
(prompt (format "Dictionary: [%s]" (or ispell-local-dictionary
ispell-dictionary
"default")))
(res (frog-menu-read prompt corrects actions)))
(unless res
(error "Quit"))
res))
(setq flyspell-correct-interface #'frog-menu-flyspell-correct)