Closed d12frosted closed 8 years ago
Thanks! I'm not very good with Elisp, but I guess what we need here is something like:
(ivy-set-actions
'flyspell-correct-word-generic
'(("s" [...] "Save")
("S" [...] "Accept (session)")
("b" [...] "Accept (buffer)")))
Just need to figure out the actual actions to call.
Studying the code a bit further, I guess every action should be able to call flyspell-do-correct
with the given command ('save
, 'buffer
or 'session
).
Problem is (for me, at least) figuring out the other parameters for flyspell-do-correct
:
(defun flyspell-do-correct (replace poss word cursor-location start end save)
[...]
I may be getting it all wrong, though.
Still studying (I know, I suck :) ).
(let ((res (funcall flyspell-correct-interface (third poss) word)))
(cond ((stringp res)
(flyspell-do-correct res poss word cursor-location start end opoint))
(t
(let ((cmd (car res))
(wrd (cdr res)))
(if (string= wrd word)
(flyspell-do-correct cmd poss wrd cursor-location start end opoint)
(progn
(flyspell-do-correct cmd poss wrd cursor-location start end opoint)
(flyspell-do-correct wrd poss word cursor-location start end opoint)))))))
It seems to me that ivy-actions should be able to return a result that flyspell-correct-word-generic
can use when it is about to call flyspell-do-correct
.
We might need @abo-abo's help here, because I'm a bit lost.
If you want actions, just write them down. You'll need these stand-alone functions:
(defun flyspell-correct-save-word ()
;;
)
(defun flyspell-correct-accept-session ()
;;
)
(defun flyspell-correct-accept-buffer ()
;;
)
Once you have them, it's really easy. And it's nice to have them in any case, maybe even make them (interactive)
.
Thank you, I'll give it a try.
Ah sorry, I was offline. Meanwhile fetched solution for this. Let me push to separate branch.
Thank you, @d12frosted. I was working with something like this:
(ivy-set-actions
'flyspell-correct-word-generic
'(("s" (lambda (x) (flyspell-correct-save-word (intern x))) "Save")
("S" (lambda (x) (flyspell-correct-accept-session (intern x))) "Accept (session)")
("b" (lambda (x) (flyspell-correct-accept-buffer (intern x))) "Accept (buffer)")))
But still wondering in the dark...
@d12frosted Just tested your code. It works beautifully. Thank you (and @abo-abo) for your patience in solving this.
P.s.: I'll talk about this package on my blog on Monday ;)
But still wondering in the dark... Just tested your code. It works beautifully.
Then I'll push 3b2b2e3 to master. Glad that it works. 😸
Instead of placing commands inside of list of candidates, use actions for them.
Following https://github.com/abo-abo/swiper/issues/455
CC @manuel-uberti