From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17270 invoked by alias); 20 Sep 2010 09:03:09 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28282 Received: (qmail 7657 invoked from network); 20 Sep 2010 09:03:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Mon, 20 Sep 2010 10:02:55 +0100 From: Peter Stephenson To: zsh workers Subject: Re: Add a hook on isearch Message-ID: <20100920100255.15fffe27@pwslap01u.europe.root.pri> In-Reply-To: <100918130049.ZM31211@torch.brasslantern.com> References: <100918130049.ZM31211@torch.brasslantern.com> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.18.9; i686-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 20 Sep 2010 09:02:55.0621 (UTC) FILETIME=[9D3DCB50:01CB58A2] X-Scanned-By: MailControl A-06-00-00 (www.mailcontrol.com) on 10.68.0.130 On Sat, 18 Sep 2010 13:00:49 -0700 Bart Schaefer wrote: > On Sep 18, 6:50pm, Mikael Magnusson wrote: > Maybe it's time for a callhookzle() to go with callhookfunc() and > runhookdef()? This made me notice the arguments for zle-keymap-select were wrong: for a user-defined widget, the arguments directly turn into function arguments, so argument 0 is always the function name and any additional argument needs to be the next argument (see doshfunc()). Index: Src/Zle/zle_keymap.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v retrieving revision 1.35 diff -p -u -r1.35 zle_keymap.c --- Src/Zle/zle_keymap.c 8 Sep 2010 12:32:32 -0000 1.35 +++ Src/Zle/zle_keymap.c 20 Sep 2010 09:00:46 -0000 @@ -486,22 +486,11 @@ selectkeymap(char *name, int fb) } if(name != curkeymapname) { char *oname = curkeymapname; - Thingy chgthingy; curkeymapname = ztrdup(name); - if (oname && zleactive && strcmp(oname, curkeymapname) && - (chgthingy = rthingy_nocreate("zle-keymap-select"))) { - char *args[2]; - int saverrflag = errflag, savretflag = retflag; - args[0] = oname; - args[1] = NULL; - errflag = retflag = 0; - execzlefunc(chgthingy, args, 1); - unrefthingy(chgthingy); - errflag = saverrflag; - retflag = savretflag; - } + if (oname && zleactive && strcmp(oname, curkeymapname)) + zlecallhook("zle-keymap-select", oname); zsfree(oname); } curkeymap = km; Index: Src/Zle/zle_main.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v retrieving revision 1.125 diff -p -u -r1.125 zle_main.c --- Src/Zle/zle_main.c 8 Sep 2010 12:32:32 -0000 1.125 +++ Src/Zle/zle_main.c 20 Sep 2010 09:00:46 -0000 @@ -1115,7 +1115,6 @@ zleread(char **lp, char **rp, int flags, char *s; int old_errno = errno; int tmout = getiparam("TMOUT"); - Thingy initthingy; #if defined(HAVE_POLL) || defined(HAVE_SELECT) /* may not be set, but that's OK since getiparam() returns 0 == off */ @@ -1215,32 +1214,15 @@ zleread(char **lp, char **rp, int flags, zrefresh(); - if ((initthingy = rthingy_nocreate("zle-line-init"))) { - char *args[2]; - args[0] = initthingy->nam; - args[1] = NULL; - execzlefunc(initthingy, args, 1); - unrefthingy(initthingy); - errflag = retflag = 0; - } + zlecallhook("zle-line-init", NULL); zlecore(); if (errflag) setsparam("ZLE_LINE_ABORTED", zlegetline(NULL, NULL)); - if (done && !exit_pending && !errflag && - (initthingy = rthingy_nocreate("zle-line-finish"))) { - int saverrflag = errflag; - int savretflag = retflag; - char *args[2]; - args[0] = initthingy->nam; - args[1] = NULL; - execzlefunc(initthingy, args, 1); - unrefthingy(initthingy); - errflag = saverrflag; - retflag = savretflag; - } + if (done && !exit_pending && !errflag) + zlecallhook("zle-line-finish", NULL); statusline = NULL; invalidatelist(); 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 20 Sep 2010 09:00:46 -0000 @@ -1237,3 +1237,35 @@ viundochange(char **args) } else return undo(args); } + +/* + * Call a ZLE hook: a user-defined widget called at a specific point + * within the line editor. + * + * A single argument arg is passed to the function (in addition to the + * function name). It may be NULL. + */ + +/**/ +void +zlecallhook(char *name, char *arg) +{ + Thingy thingy = rthingy_nocreate(name); + int saverrflag, savretflag; + char *args[3]; + + if (!thingy) + return; + + saverrflag = errflag; + savretflag = retflag; + + args[0] = thingy->nam; + args[1] = arg; + args[2] = NULL; + execzlefunc(thingy, args, 1); + unrefthingy(thingy); + + errflag = saverrflag; + retflag = savretflag; +} -- Peter Stephenson 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