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

Re: PATCH: $ZLE_LINE_ABORTED



On Tue, 07 Sep 2010 10:31:41 -0400
Greg Klanderman <gak@xxxxxxxxxxxxxx> wrote:
> Cool, I was just wanting something like this the other day.. is there
> a way to capture the line when exiting zle with C-c as well?

Hmm... I'm wondering if I put it in the right place.  sendbreak can abort
other things than the full line edit, and I already claimed that "this
parameter is set by the line editor when an error occurs", which as you
spotted isn't necessarily true.

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 14:42:46 -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 14:42:46 -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; in this case 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_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.124
diff -p -u -r1.124 zle_main.c
--- Src/Zle/zle_main.c	31 Jul 2010 19:36:54 -0000	1.124
+++ Src/Zle/zle_main.c	7 Sep 2010 14:42:46 -0000
@@ -1226,6 +1226,9 @@ zleread(char **lp, char **rp, int flags,
 
     zlecore();
 
+    if (errflag)
+	setsparam("ZLE_LINE_ABORTED", zlegetline(NULL, NULL));
+
     if (done && !exit_pending && !errflag &&
 	(initthingy = rthingy_nocreate("zle-line-finish"))) {
 	int saverrflag = errflag;

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