zsh-users
 help / color / mirror / code / Atom feed
* accept-line-and-down-history and push-input
@ 2010-10-26  8:06 Mikael Magnusson
  2010-10-26 14:55 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2010-10-26  8:06 UTC (permalink / raw)
  To: Zsh Users

I sometimes use accept-line-and-down-history to rerun a series of
commands, but occasionally need to run another command at some point
in the middle, but when returning from push-input, I'm left at the end
of history, not where I was. Is there some clever way I can wrap
push-input, or something, to make this work?

In case it wasn't absolutely clear,
% : one
% : two
% : three
% : lots of other history here
up to the first and ctrl-o gives
% : two
then push-input and running something again leaves
% : two
as expected but ctrl-o now gives an empty command line, I would like
it to leave me at
% : three

-- 
Mikael Magnusson


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

* Re: accept-line-and-down-history and push-input
  2010-10-26  8:06 accept-line-and-down-history and push-input Mikael Magnusson
@ 2010-10-26 14:55 ` Bart Schaefer
  2010-10-26 15:19   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2010-10-26 14:55 UTC (permalink / raw)
  To: Zsh Users

On Oct 26, 10:06am, Mikael Magnusson wrote:
}
} I sometimes use accept-line-and-down-history to rerun a series of
} commands, but occasionally need to run another command at some point
} in the middle, but when returning from push-input, I'm left at the end
} of history, not where I was. Is there some clever way I can wrap
} push-input, or something, to make this work?

You can read/assign to HISTNO.  Something like this:

    with-saved-history-position() {
      typeset -g RESTORE_HISTNO=$HISTNO
      zle .$WIDGET "$@"
    }
    zle -N push-input with-saved-history-position

    zle-line-init() {
      [[ -n $RESTORE_HISTNO ]] && { 
	HISTNO=$RESTORE_HISTNO
	typeset -g RESTORE_HISTNO=''
      }
    }
    zle -N zle-line-init

(I'm beginning to think that zle-line-init should be a builtin widget
that calls an array of hook functions, ala precmd.)

-- 


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

* Re: accept-line-and-down-history and push-input
  2010-10-26 14:55 ` Bart Schaefer
@ 2010-10-26 15:19   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2010-10-26 15:19 UTC (permalink / raw)
  To: Zsh Users

On Tue, 26 Oct 2010 07:55:44 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> (I'm beginning to think that zle-line-init should be a builtin widget
> that calls an array of hook functions, ala precmd.)

I've been thinking along those lines, except that the array of hook
functions would be the alternative to the widget, as with chpwd and
friends, i.e. you could still define zle-line-init if you wanted a
simple life but zle_line_init_functions could contain an additional set
of widgets.  Something like the following.

  zle_line_init_functions=(zle-le-test)
  zle-le-test() { zle -M Initialised.; }
  zle -N zle-le-test

Not sure how to keep the name of the array entirely within zle, but I'm
not sure it's necessary: using variables with a prefix zle_ is natural
enough.

Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.57
diff -p -u -r1.57 zle_utils.c
--- Src/Zle/zle_utils.c	20 Sep 2010 09:27:46 -0000	1.57
+++ Src/Zle/zle_utils.c	26 Oct 2010 15:16:42 -0000
@@ -1250,21 +1250,48 @@ viundochange(char **args)
 void
 zlecallhook(char *name, char *arg)
 {
-    Thingy thingy = rthingy_nocreate(name);
+    Thingy thingy;
     int saverrflag, savretflag;
-    char *args[3];
+    char *args[3], *arrname, **funcarray, *ptr;
+    const char suffix[] = "_functions";
 
-    if (!thingy)
-	return;
+    /* Get the name of the corresponding hook array */
+    arrname = zalloc(strlen(name) + strlen(suffix) + 1);
+    sprintf(arrname, "%s%s", name, suffix);
+    for (ptr = arrname; *ptr; ptr++) {
+	if (*ptr == '-')
+	    *ptr = '_';
+    }
 
     saverrflag = errflag;
     savretflag = retflag;
 
-    args[0] = thingy->nam;
     args[1] = arg;
     args[2] = NULL;
-    execzlefunc(thingy, args, 1);
-    unrefthingy(thingy);
+
+    thingy = rthingy_nocreate(name);
+    if (thingy) {
+	args[0] = thingy->nam;
+	execzlefunc(thingy, args, 1);
+	unrefthingy(thingy);
+    }
+
+    funcarray = getaparam(arrname);
+    if (funcarray) {
+	/* in case the array changes during use */
+	funcarray = arrdup(funcarray);
+	for (; *funcarray; funcarray++) {
+	    errflag = 0;
+	    retflag = 0;
+
+	    thingy = rthingy_nocreate(*funcarray);
+	    if (thingy) {
+		args[0] = thingy->nam;
+		execzlefunc(thingy, args, 1);
+		unrefthingy(thingy);
+	    }
+	}
+    }
 
     errflag = saverrflag;
     retflag = savretflag;


-- 
Peter Stephenson <pws@csr.com>            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


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

end of thread, other threads:[~2010-10-26 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-26  8:06 accept-line-and-down-history and push-input Mikael Magnusson
2010-10-26 14:55 ` Bart Schaefer
2010-10-26 15:19   ` Peter Stephenson

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