Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Asynchronous completions?



Hello,
I've just waited a bit after: git checkout <TAB>. The delay was caused
by the completion script loading all revisions, while I only wanted
branches.

This gave me an idea – to use exec {FD}< <(...) and zle -F to update
the completion, after first displaying "Loading all revisions". In one
project I'm passing as much as 13000 lines through the {FD} after each
keypress without any problems.

The method is very simple, e.g.:

handler() {            (git)-[feature/redrawhook]
        local IFS=$'\n'
        read -u $FD line
        zle -F $FD # Better not forget about this, strange things happen
        zle -M "$line"
}
zle -N handler

exec {FD}< <(sleep 2; echo Hello World)
true # workaround pre-5.7.1-dev-0 bug fixed in 44214
zle -F -w $FD handler

I'm not familiar with coding completions. Could someone else start the
async-completions trend?

For more examples on the <(...) / zle -F technique take a look at a
patch that introduced asynchronous man-database query into
fast-syntax-highlighting (to highlight if a man page given is correct
or not): https://github.com/zdharma/fast-syntax-highlighting/commit/3e7d5eb0eb70d5c570a680da3ae49d26e1a77f69

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



Messages sorted by: Reverse Date, Date, Thread, Author