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

PATCH: $ZLE_LINE_ABORTED



Here's what I think is a useful one-line change.  If there's an error in
the line editor, including ^G, the line being edited gets copied to the
variable ZLE_LINE_ABORTED.  I'm forever aborting what I'm doing and
realising I need something on the line after all.

You can do this:

recover-line() {
  LBUFFER=$ZLE_LINE_ABORTED
  RBUFFER=
}
zle -N recover-line

Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.60
diff -p -u -r1.60 params.yo
--- Doc/Zsh/params.yo	14 Jun 2010 11:58:26 -0000	1.60
+++ Doc/Zsh/params.yo	7 Sep 2010 10:40:43 -0000
@@ -1448,6 +1448,13 @@ item(tt(ZDOTDIR))(
 The directory to search for shell startup files (.zshrc, etc),
 if not tt($HOME).
 )
+vindex(ZLE_LINE_ABORTED)
+item(tt(ZLE_LINE_ABORTED))(
+This parameter is set by the line editor when an error occurs.  It
+contains the line that was being edited at the point of the error.
+`tt(print -zr -- $ZLE_LINE_ABORTED)' can be used to recover the line.
+Only the most recent line of this kind is remembered.
+)
 vindex(ZLE_REMOVE_SUFFIX_CHARS)
 vindex(ZLE_SPACE_SUFFIX_CHARS)
 xitem(tt(ZLE_REMOVE_SUFFIX_CHARS))
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.87
diff -p -u -r1.87 zle.yo
--- Doc/Zsh/zle.yo	6 Sep 2010 08:50:05 -0000	1.87
+++ Doc/Zsh/zle.yo	7 Sep 2010 10:40:43 -0000
@@ -2057,7 +2057,8 @@ tindex(send-break)
 item(tt(send-break) (^G ESC-^G) (unbound) (unbound))(
 Abort the current editor function, e.g. tt(execute-named-command), or the
 editor itself, e.g. if you are in tt(vared). Otherwise abort the parsing of
-the current line.
+the current line.  The aborted line is available in the shell variable
+tt(ZLE_LINE_ABORTED).
 )
 tindex(run-help)
 item(tt(run-help) (ESC-H ESC-h) (unbound) (unbound))(
Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.56
diff -p -u -r1.56 zle_utils.c
--- Src/Zle/zle_utils.c	22 Mar 2010 19:49:07 -0000	1.56
+++ Src/Zle/zle_utils.c	7 Sep 2010 10:40:43 -0000
@@ -967,6 +967,7 @@ showmsg(char const *msg)
 int
 handlefeep(UNUSED(char **args))
 {
+    setsparam("ZLE_LINE_ABORTED", zlegetline(NULL, NULL));
     zbeep();
     region_active = 0;
     return 0;

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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