zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: tweak to `zle -I'
@ 2002-06-07 10:50 Peter Stephenson
  2002-06-07 15:54 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2002-06-07 10:50 UTC (permalink / raw)
  To: Zsh hackers list

Experience with this suggests it's useful for the zle display only to be
invalidated on the first call to `zle -I'.  This allows a complex
function executing while zle is active to call `zle -I' every time it
needs to output without remembering the state.  Since, obviously, the
state is remembered internally anyway this is more convenient.

If this sounds like double dutch, the old behaviour of

% widget() { zle -I; print This is line 1; zle -I; print This is line 2; }
% zle -N widget
% My command line<ESC>xwidget

was

% My command line
This is line 1
% My command line
This is line 2
% My command line

and the new behaviour is

% My command line
This is line 1
This is line 2
% My command line

I can't see any reason why anyone would want the old behaviour.
You never get a chance to edit on that middle command line.

The manual page also reflects experience a bit better.

Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.6
diff -u -r1.6 zle_thingy.c
--- Src/Zle/zle_thingy.c	5 Jun 2002 21:12:08 -0000	1.6
+++ Src/Zle/zle_thingy.c	7 Jun 2002 10:42:30 -0000
@@ -672,7 +672,7 @@
 static int
 bin_zle_invalidate(char *name, char **args, char *ops, char func)
 {
-    if (zleactive) {
+    if (zleactive && !trashedzle) {
 	trashzle();
 	return 0;
     } else
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.19
diff -u -r1.19 zle.yo
--- Doc/Zsh/zle.yo	6 Jun 2002 09:04:47 -0000	1.19
+++ Doc/Zsh/zle.yo	7 Jun 2002 10:42:30 -0000
@@ -472,8 +472,9 @@
 fi)
 )
 item(tt(-I))(
-Unusually, this option is only useful em(outside) ordinary widget functions.
-It invalidates the current zle display in preparation for output; usually
+Unusually, this option is most useful outside ordinary widget functions,
+though it may be used within if normal output to the terminal is required.
+It invalidates the current zle display in preparation for output; typically
 this will be from a trap function.  It has no effect if zle is not
 active.  When a trap exits, the shell checks to see if the display needs
 restoring, hence the following will print output in such a way as not to
@@ -481,17 +482,22 @@
 
 example(TRAPUSR1() {
     # Invalidate zle display
-  zle -I
+  [[ -o zle ]] && zle -I
     # Show output
   print Hello
 })
 
-Note that there are better ways of manipulating the display from within zle
-widgets.  In general, the trap function may need to test whether zle is
-loaded before using this method; if it is not, there is no point in loading
-it specially since the line editor will not be active.
+Note that there are normally better ways of manipulating the display from
+within zle widgets.  In general, the trap function may need to test whether
+zle is active before using this method (as shown in the example), since the
+tt(zsh/zle) module may not even be loaded; if it is not, the command can be
+skipped.
 
-The status is zero if zle was active, else one.
+It is possible to call `tt(zle -I)' several times before control is
+returned to the editor; the display will only be invalidated the first time
+to minimise disruption to the display.
+
+The status is zero if the current zle display was invalidated, else one.
 )
 item(var(widget) tt([ -n) var(num) tt(]) tt([ -N ]) var(args) ...)(
 Invoke the specified widget.  This can only be done when ZLE is

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: PATCH: tweak to `zle -I'
  2002-06-07 10:50 PATCH: tweak to `zle -I' Peter Stephenson
@ 2002-06-07 15:54 ` Bart Schaefer
  2002-06-07 16:22   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2002-06-07 15:54 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Fri, 7 Jun 2002, Peter Stephenson wrote:

> Experience with this suggests it's useful for the zle display only to be
> invalidated on the first call to `zle -I'.

This is fine, but ...

> +The status is zero if the current zle display was invalidated, else one.

What's the status on the second and subsequent calls?  (I suppose I could
try it, but I don't have a current build yet.)

I think the status should be 1 if the display *would have been* invalided,
even if it wasn't because it already has been, if you see what I mean.


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

* Re: PATCH: tweak to `zle -I'
  2002-06-07 15:54 ` Bart Schaefer
@ 2002-06-07 16:22   ` Peter Stephenson
  2002-06-07 16:44     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2002-06-07 16:22 UTC (permalink / raw)
  To: Zsh hackers list

Bart Schaefer wrote:
> > +The status is zero if the current zle display was invalidated, else one.
> 
> What's the status on the second and subsequent calls?  (I suppose I could
> try it, but I don't have a current build yet.)
> 
> I think the status should be 1 if the display *would have been* invalided,
> even if it wasn't because it already has been, if you see what I mean.

Do you mean 0?  It currently returns 1 on subsequent calls.  I suppose
you mean 0 should indicate zle was active, i.e as follows.

Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.7
diff -u -r1.7 zle_thingy.c
--- Src/Zle/zle_thingy.c	7 Jun 2002 10:57:25 -0000	1.7
+++ Src/Zle/zle_thingy.c	7 Jun 2002 16:18:23 -0000
@@ -672,8 +672,9 @@
 static int
 bin_zle_invalidate(char *name, char **args, char *ops, char func)
 {
-    if (zleactive && !trashedzle) {
-	trashzle();
+    if (zleactive) {
+	if (!trashedzle)
+	    trashzle();
 	return 0;
     } else
 	return 1;
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.20
diff -u -r1.20 zle.yo
--- Doc/Zsh/zle.yo	7 Jun 2002 10:57:25 -0000	1.20
+++ Doc/Zsh/zle.yo	7 Jun 2002 16:20:41 -0000
@@ -498,7 +498,9 @@
 Note that there are normally better ways of manipulating the display from
 within zle widgets; see, for example, `tt(zle -R)' above.
 
-The status is zero if the current zle display was invalidated, else one.
+The status is zero if zle is active and the current zle display has
+been invalidated (even if this was by a previous call to `tt(zle -I)'),
+else one.
 )
 item(var(widget) tt([ -n) var(num) tt(]) tt([ -N ]) var(args) ...)(
 Invoke the specified widget.  This can only be done when ZLE is

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: PATCH: tweak to `zle -I'
  2002-06-07 16:22   ` Peter Stephenson
@ 2002-06-07 16:44     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2002-06-07 16:44 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Fri, 7 Jun 2002, Peter Stephenson wrote:

> Do you mean 0?  It currently returns 1 on subsequent calls.  I suppose
> you mean 0 should indicate zle was active, i.e as follows.

Ah, yes, that is what I meant, thanks for reverting my inverted logic.


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

end of thread, other threads:[~2002-06-07 16:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-07 10:50 PATCH: tweak to `zle -I' Peter Stephenson
2002-06-07 15:54 ` Bart Schaefer
2002-06-07 16:22   ` Peter Stephenson
2002-06-07 16:44     ` 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).