d12frosted / flyspell-correct

Distraction-free words correction with flyspell via selected interface.
Other
200 stars 14 forks source link

Use actions for save commands in ivy interface #8

Closed d12frosted closed 8 years ago

d12frosted commented 8 years ago

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

manuel-uberti commented 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.

manuel-uberti commented 8 years ago

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.

manuel-uberti commented 8 years ago

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.

abo-abo commented 8 years ago

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).

manuel-uberti commented 8 years ago

Thank you, I'll give it a try.

d12frosted commented 8 years ago

Ah sorry, I was offline. Meanwhile fetched solution for this. Let me push to separate branch.

manuel-uberti commented 8 years ago

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...

manuel-uberti commented 8 years ago

@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 ;)

d12frosted commented 8 years ago

But still wondering in the dark... Just tested your code. It works beautifully.

Then I'll push 3b2b2e3 to master. Glad that it works. 😸