zsh-users
 help / color / mirror / code / Atom feed
* How to exit function on a trap (INT)
@ 2018-10-16 17:10 Sebastian Gniazdowski
  2018-10-16 17:53 ` Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2018-10-16 17:10 UTC (permalink / raw)
  To: Zsh Users

Hello,
I have an adhoc tests-related autoload-*function* `test-id-as':

https://github.com/zdharma/zplugin/blob/c1fc6d9325f97264ff155210fedd6bebc421b5e4/doc/test-id-as

It's doing `setopt localtraps' and essentially `trap '...; return 0;'
EXIT INT TERM QUIT

The problem: Single Ctrl-C doesn't stop the function, I have to hold
the key combination, see fast sequence of interrupted states of the
trying-to-execute-anyway function, to finally luckily "reach" the exit
of the function, via dense Ctrl-C signaling (result of continuous hold
of Ctrl-C keys).

I have some experience with functions and traps, and I recall I was
successfully exiting functions this way. Should this method work? What
can be wrong?

The actual trap setup is little long, but it simply has `; return 0;'
at the end:

trap '[[ $argv1 != "--keep" ]] && { ZPLGM[PLUGINS_DIR]=$plg_bkp;
ZPLGM[SNIPPETS_DIR]=$snp_bkp; } || { print; print "Kept
${ZPLGM[PLUGINS_DIR]} :: ${ZPLGM[SNIPPETS_DIR]}"; }; return 0;' EXIT
INT TERM QUIT

-- 
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] 2+ messages in thread

* Re: How to exit function on a trap (INT)
  2018-10-16 17:10 How to exit function on a trap (INT) Sebastian Gniazdowski
@ 2018-10-16 17:53 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2018-10-16 17:53 UTC (permalink / raw)
  To: zsh-users

Sebastian Gniazdowski wrote on Tue, 16 Oct 2018 19:10 +0200:
> Hello,
> I have an adhoc tests-related autoload-*function* `test-id-as':
> 
> https://github.com/zdharma/zplugin/blob/c1fc6d9325f97264ff155210fedd6bebc421b5e4/doc/test-id-as

Please send a minimal example that's runnable from 'zsh -f'.

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

end of thread, other threads:[~2018-10-16 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-16 17:10 How to exit function on a trap (INT) Sebastian Gniazdowski
2018-10-16 17:53 ` Daniel Shahaf

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