zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: accept-line-and-down-history and push-input
Date: Tue, 26 Oct 2010 16:19:47 +0100	[thread overview]
Message-ID: <20101026161947.19279c58@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <101026075546.ZM28500@torch.brasslantern.com>

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


      reply	other threads:[~2010-10-26 16:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-26  8:06 Mikael Magnusson
2010-10-26 14:55 ` Bart Schaefer
2010-10-26 15:19   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101026161947.19279c58@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).