zsh-workers
 help / color / mirror / code / Atom feed
* Asynchronous completions?
@ 2019-06-04 22:01 Sebastian Gniazdowski
  2019-06-05  7:57 ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2019-06-04 22:01 UTC (permalink / raw)
  To: Zsh hackers list

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Asynchronous completions?
  2019-06-04 22:01 Asynchronous completions? Sebastian Gniazdowski
@ 2019-06-05  7:57 ` Mikael Magnusson
  2019-06-05  9:47   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2019-06-05  7:57 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh hackers list

On 6/5/19, Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> 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.
...
> I'm not familiar with coding completions. Could someone else start the
> async-completions trend?

async-completions doesn't make any sense, you can't do anything else
while completing and you can already abort it by pressing ctrl-c. If
you want to show a message first, you can already do so, it will be
overwritten by the completion list once that's finished building. For
example I wrap the complete-word etc widgets with a function that
changes the cursor color, and then changes it back after, but you
could display a message instead if you want.

function _generic_cursorcol() {
  #zle -R completing...
  cursorcol cyan
  { _generic "$@" } always {
    cursorcol_normal
  }
}
() for 1 {
  zle -C $1 $1 _generic_cursorcol
} complete-word reverse-menu-complete complete-word menu-complete
menu-expand-or-complete



-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Asynchronous completions?
  2019-06-05  7:57 ` Mikael Magnusson
@ 2019-06-05  9:47   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2019-06-05  9:47 UTC (permalink / raw)
  To: zsh-workers

On Wed, 2019-06-05 at 09:57 +0200, Mikael Magnusson wrote:
> If you want to show a message first, you can already do so, it will be
> overwritten by the completion list once that's finished building.

See also the show-completer style (not quite the same thing).

pws


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-05  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-04 22:01 Asynchronous completions? Sebastian Gniazdowski
2019-06-05  7:57 ` Mikael Magnusson
2019-06-05  9:47   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).