zsh-users
 help / color / mirror / code / Atom feed
* How to restart zle without invoking 'accept-line'?
@ 2013-10-30 11:30 Thiago Padilha
  2013-10-30 15:31 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Thiago Padilha @ 2013-10-30 11:30 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 529 bytes --]

I've written the zsh-autosuggestions widget using 'recursive-edit' as it
was needed for updating zle asynchronously with zle -F. Heres the relevant
initialization code:

autosuggest-start() {
autosuggest-resume
zle recursive-edit
integer rv=$?
autosuggest-pause
(( rv )) || zle accept-line
return rv
}

zle-line-init() {
zle autosuggest-start
}

This code propagates accept-line to the main zle widget(user presses
enter), but how can I handle like ctrl+c which would normally cause zle to
restart without executing the command?

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

* Re: How to restart zle without invoking 'accept-line'?
  2013-10-30 11:30 How to restart zle without invoking 'accept-line'? Thiago Padilha
@ 2013-10-30 15:31 ` Bart Schaefer
  2013-11-03 21:53   ` Thiago Padilha
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2013-10-30 15:31 UTC (permalink / raw)
  To: Thiago Padilha, zsh-users

On Oct 30,  9:30am, Thiago Padilha wrote:
} 
} This code propagates accept-line to the main zle widget(user presses
} enter), but how can I handle like ctrl+c which would normally cause zle to
} restart without executing the command?

For that specific case I believe this will do it:

setopt localtraps
trap 'zle send-break' INT QUIT


There are really only three ways to restart ZLE:  accept-line (and all the
variants), send-break, and push-line-or-edit.


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

* Re: How to restart zle without invoking 'accept-line'?
  2013-10-30 15:31 ` Bart Schaefer
@ 2013-11-03 21:53   ` Thiago Padilha
  2013-11-04 18:14     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Thiago Padilha @ 2013-11-03 21:53 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 1827 bytes --]

Bart, thanks for your help

I've tried to use the passthrough example from the keymap+widget tip you
gave on the other thread:

```zsh
autoload keymap+widget
keymap+widget

bindkey -N newkeymap main
recursive-edit-and-accept() {
local -a __accepted
zle -N newkeymap+accept-line end-recursive-edit
zle recursive-edit -K newkeymap || zle send-break
if [[ ${__accepted[0]} != end-recursive-edit ]]
then zle "${__accepted[@]}"; return
else return 0
fi
}
zle -N recursive-edit-and-accept
end-recursive-edit() {
__accepted=($WIDGET ${=NUMERIC:+-n $NUMERIC} "$@")
zle .accept-line
return 0
}
zle-line-init() {
zle recursive-edit-and-accept
}
zle -N zle-line-init
```

This works when I press enter(accept-line) but for ctrl+c I still need to
press two times to restart zle. If I bind 'recursive-edit-and-accept to a
key and activate it outside zle-line-init, everything works as expected.

It seems 'zle send-break' doesn't work when called from zle-line-init,
maybe some protection added against the following case:

```zsh
zle-line-init() {
  zle send-break
}
zle -N zle-line-init
```

Do you think its possible to work around this problem? I really would like
to activate my widget automatically instead of pressing a key combination
everytime.

Thanks again




On Wed, Oct 30, 2013 at 12:31 PM, Bart Schaefer
<schaefer@brasslantern.com>wrote:

> On Oct 30,  9:30am, Thiago Padilha wrote:
> }
> } This code propagates accept-line to the main zle widget(user presses
> } enter), but how can I handle like ctrl+c which would normally cause zle
> to
> } restart without executing the command?
>
> For that specific case I believe this will do it:
>
> setopt localtraps
> trap 'zle send-break' INT QUIT
>
>
> There are really only three ways to restart ZLE:  accept-line (and all the
> variants), send-break, and push-line-or-edit.
>

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

* Re: How to restart zle without invoking 'accept-line'?
  2013-11-03 21:53   ` Thiago Padilha
@ 2013-11-04 18:14     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2013-11-04 18:14 UTC (permalink / raw)
  To: Zsh-Users List

On Nov 3,  7:53pm, Thiago Padilha wrote:
} 
} I've tried to use the passthrough example from the keymap+widget tip you
} gave on the other thread:
} 
[...]
} 
} This works when I press enter(accept-line) but for ctrl+c I still need to
} press two times to restart zle.

I'm sorry, I hadn't fully comprehended that you were setting up to jump
directly into this from zle-line-init.

You can't actually restart zle from zle-line-init because, technically,
zle hasn't started *yet* at that point.  Send-break will interrupt
whatever zle-line-init is doing, but then you just fall on through to
the "instance" of zle that was already starting.

} If I bind 'recursive-edit-and-accept to a key and activate it outside
} zle-line-init, everything works as expected.

That is a clue to how you might make this work:

(1) bind recursive-edit-and-accept to a key string

(2) in zle-line-init, use "zle -U" to put that string on the input

This way, when zle-line-init ends, the first thing that will be run by
the editor is the command to switch to recursive-edit-and-accept.

By the way, you don't need to put the "zle -N ... end-recursive-edit"
inside the function body of recursive-edit-and-accept.  The zle -N may
be done just once, and keymap+widget will take care of the rest.


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

end of thread, other threads:[~2013-11-04 18:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-30 11:30 How to restart zle without invoking 'accept-line'? Thiago Padilha
2013-10-30 15:31 ` Bart Schaefer
2013-11-03 21:53   ` Thiago Padilha
2013-11-04 18:14     ` Bart Schaefer

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