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

[Feature Reqeust] General Function to build async candidates #2110

Open
cireu opened this issue Jun 27, 2019 · 2 comments
Open

[Feature Reqeust] General Function to build async candidates #2110

cireu opened this issue Jun 27, 2019 · 2 comments

Comments

@cireu
Copy link
Contributor

cireu commented Jun 27, 2019

We have counsel--async-command to call shell command for completion candidates, however this command doesn't suitable for generalized async work. E.g.url-retrieve.

I try a beta version of async callback to insert candidate to current ivy completing session

(defun ivy--async-callback (result)
  "Insert RESULT to current ivy completing session."
  (when (eq this-command (ivy-state-caller ivy-last))
    (let* ((len (length result))
           (ivy--prompt (format "%d++ %s"
                                len (ivy-state-prompt ivy-last))))
      (ivy--set-candidates (if ivy--all-candidates
                               (append ivy--all-candidates result)
                             result))
      (ivy--insert-minibuffer (ivy--format ivy--all-candidates)))))
@abo-abo
Copy link
Owner

abo-abo commented Jun 27, 2019

Nice idea. And the code looks good. Can you post a full ivy-read demo?

I think it would be nice to:

  • introduce this function,
  • maybe make it use a logic similar to counsel-async-filter-update-time if needed,
  • have counsel--async-filter re-use this new function.

@cireu
Copy link
Contributor Author

cireu commented Jun 27, 2019

introduce this function

My idea is to introduce such API.

(defun ivy-build-async-candidates (fetcher &optional awaiting-message)
  "Build a asynchronous candidates collection for ivy completing session.

FETCHER should accept `ivy--async-callback' as arguements, and call it
each time new candidates arrives with candidates, candidates should be
 a string or a list of strings.

AWAITING-MESSAGE will be shown when there's no candidates have been arrived.
"
  (error "Unimplemented!"))

But there are some problems I encountered and some behaviours I can't confirm.

  1. How to do the clean up? If a completing session was aborted manually (like C-g), callback should stop accepting and inserting candidates. Should we force user to pass :unwind to ivy-read to do this (like counsel--async-command based fucntions) or modified the definition of ivy-read to do the clean up automatically? Or someone have better idea.

  2. What kind of result should be called with ivy--async-callback, a list of strings or more?

maybe make it use a logic similar to counsel-async-filter-update-time if needed,
have counsel--async-filter re-use this new function.

I think these can be easily done, if we can confirm the choive above.

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

No branches or pull requests

2 participants