zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>,
	zsh-workers@sunsite.auc.dk
Subject: Re: The `zle' command and traps
Date: Sat, 11 Mar 2000 07:57:21 +0000	[thread overview]
Message-ID: <1000311075721.ZM19210@candle.brasslantern.com> (raw)
In-Reply-To: <200003091221.NAA25853@beta.informatik.hu-berlin.de>

On Mar 9,  1:21pm, Sven Wischnowsky wrote:
} Subject: Re: The `zle' command and traps
}
} Bart Schaefer wrote:
} 
} > 	TMOUT=2 ; TRAPALRM() { zle -R "Hi there, I'm a trap." }
} > 
} > Of course if the signal arrives when ZLE is not active, this generates an
} > ugly warning message.
} 
} I was about to add a/some test(s) for sfcontext in bin_zle()
} but... this is quite cool, isn't it? ;-)

Yes, I confess I thought so too ... but some things don't work so well.
For example, try using "zle -M ..." instead of -R in that trap.

Or try

	TRAPINT() { zle push-input }

and then type ctrl-C.  Note that the line gets pushed onto the buffer
stack, but the display is not refreshed so you can't tell.  You need an
explicit refresh:

	TRAPINT() { zle push-input ; zle -R }

(An explicit refresh makes the "zle -M" trap work as well.)

I'm also concerned about what happens if a zle widget is invoked from a
trap in the middle of some interactive thing like menu-selection.  That
could get messy quickly, especially if it's something that alters the
buffer.
 
} So, should we disallow it completely?

I can't decide.  The message modes and refresh seem harmless enough, but
perhaps we should refuse to execute widgets from within traps?

} Or make the zle builtin be quiet if zle isn't active?

That isn't strictly necessary as one can redirect stdout to hide the
warning.  However, it'd be nice if zle returned a non-zero status when
it fails; try typing

	zle -R "not echoed" || echo zle failed

and you'll get

	zle: can only be called from widget function

but not "zle failed".

} Make the zle special parameters accessible (read-only) in traps if zle
} is active?

If we allow widgets to be called, you can cause the special parameters
to become available by using "zle widgetname".  So instead of writing

	TRAPINT() { .... something with $BUFFER .... }

One writes

	widgetname() { .... something with $BUFFER .... }
	zle -N widgetname
	TRAPINT() { zle widgetname }

Can you extend read-only-ness of the parameters to the point that widgets
are restricted as well?  I.e., if you call from a trap a builtin widget
that moves the cursor or inserts/deletes characters, it would fail?

If we can restrict widgets to those that do "safe" things, then we can
allow "zle widgetname" and there's no need for the special parameters to
be visible directly to the trap function.  If instead we must prohibit
widget-calling entirely, then perhaps the parameters should be available
to the trap function.

} Add a way to detect if zle is active?

That would be nice.  "zle" with no arguments silently returning 0 or 1
would be sufficient (it now says "zle: widgets can only be called ...").

While we're on the subject ... CURSOR is almost equivalent to emacs'
(point).  Why is there no MARK variable?  I find myself wanting to play
with the region and therefore doing things like

	local -i point=$CURSOR
	zle exchange-point-and-mark
	local -i mark=$CURSOR
	zle exchange-point-and-mark

} Add a way to detect if (the shell thinks that) there is a
} completion list displayed below the prompt? Etc, etc?

Hrm.  That may be getting too esoteric.  Hard to say.

While we're on the subject of zle behavior:

	zle -U frob

This results in "brof" being inserted onto the command line.  The docs
refer to the "input queue" not the "input stack" -- why is it LIFO?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


  reply	other threads:[~2000-03-11  8:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-09 12:21 Sven Wischnowsky
2000-03-11  7:57 ` Bart Schaefer [this message]
2000-03-14 18:24   ` zle -U Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2000-03-04  4:46 The `zle' command and traps Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1000311075721.ZM19210@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).