Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: tweak to `zle -I'



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@xxxxxxx>                  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.
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author