zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: Add a hook on isearch
Date: Mon, 20 Sep 2010 10:02:55 +0100	[thread overview]
Message-ID: <20100920100255.15fffe27@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <100918130049.ZM31211@torch.brasslantern.com>

On Sat, 18 Sep 2010 13:00:49 -0700
Bart Schaefer <schaefer@brasslantern.com> 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 <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


  parent reply	other threads:[~2010-09-20  9:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-18 16:50 Mikael Magnusson
2010-09-18 20:00 ` Bart Schaefer
2010-09-19 14:54   ` Mikael Magnusson
2010-09-20  9:02   ` Peter Stephenson [this message]
2010-09-23  9:40 ` Peter Stephenson

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=20100920100255.15fffe27@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=zsh-workers@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).