zsh-workers
 help / color / mirror / code / Atom feed
From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh-workers@zsh.org
Subject: [PATCH 2/2] Let vared define custom init and finish hooks
Date: Sat, 23 Mar 2013 15:46:38 +0100	[thread overview]
Message-ID: <1364049998-22603-3-git-send-email-ft@bewatermyfriend.org> (raw)
In-Reply-To: <1364049998-22603-1-git-send-email-ft@bewatermyfriend.org>

Using this, you can do things like this in a more straight-forward
manner:

foo-init() { CURSOR=0; }
zle -N foo-init
foo=$'Some longer\nbuffer with\nmultiple lines.'

vared -i foo-init foo
---
 Src/Zle/zle_main.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 5157ad3..9a4265f 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1105,7 +1105,7 @@ zlecore(void)
 
 /**/
 char *
-zleread(char **lp, char **rp, int flags, int context)
+zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
 {
     char *s;
     int old_errno = errno;
@@ -1221,7 +1221,7 @@ zleread(char **lp, char **rp, int flags, int context)
 
     unqueue_signals();	/* Should now be safe to acknowledge SIGWINCH */
 
-    zlecallhook("zle-line-init", NULL);
+    zlecallhook(init, NULL);
 
     zrefresh();
 
@@ -1231,7 +1231,7 @@ zleread(char **lp, char **rp, int flags, int context)
 	setsparam("ZLE_LINE_ABORTED", zlegetline(NULL, NULL));
 
     if (done && !exit_pending && !errflag)
-	zlecallhook("zle-line-finish", NULL);
+	zlecallhook(finish, NULL);
 
     statusline = NULL;
     invalidatelist();
@@ -1471,7 +1471,7 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
     Param pm = 0;
     int ifl;
     int type = PM_SCALAR, obreaks = breaks, haso = 0, oSHTTY = 0;
-    char *p1, *p2, *main_keymapname, *vicmd_keymapname;
+    char *p1, *p2, *main_keymapname, *vicmd_keymapname, *init, *finish;
     Keymap main_keymapsave = NULL, vicmd_keymapsave = NULL;
     FILE *oshout = NULL;
 
@@ -1499,6 +1499,8 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
     p2 = OPT_ARG_SAFE(ops,'r');
     main_keymapname = OPT_ARG_SAFE(ops,'M');
     vicmd_keymapname = OPT_ARG_SAFE(ops,'m');
+    init = OPT_ARG_SAFE(ops,'i');
+    finish = OPT_ARG_SAFE(ops,'f');
 
     if (type != PM_SCALAR && !OPT_ISSET(ops,'c')) {
 	zwarnnam(name, "-%s ignored", type == PM_ARRAY ? "a" : "A");
@@ -1600,6 +1602,7 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
 
 	haso = 1;
     }
+
     /* edit the parameter value */
     zpushnode(bufstack, s);
 
@@ -1615,7 +1618,10 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
     if (OPT_ISSET(ops,'h'))
 	hbegin(2);
     isfirstln = OPT_ISSET(ops,'e');
-    t = zleread(&p1, &p2, OPT_ISSET(ops,'h') ? ZLRF_HISTORY : 0, ZLCON_VARED);
+
+    t = zleread(&p1, &p2, OPT_ISSET(ops,'h') ? ZLRF_HISTORY : 0, ZLCON_VARED,
+		init ? init : "zle-line-init",
+		finish ? finish : "zle-line-finish");
     if (OPT_ISSET(ops,'h'))
 	hend(NULL);
     isfirstln = ifl;
@@ -1880,7 +1886,8 @@ zle_main_entry(int cmd, va_list ap)
 	flags = va_arg(ap, int);
 	context = va_arg(ap, int);
 
-	return zleread(lp, rp, flags, context);
+	return zleread(lp, rp, flags, context,
+		       "zle-line-init", "zle-line-finish");
     }
 
     case ZLE_CMD_ADD_TO_LINE:
@@ -1926,7 +1933,7 @@ zle_main_entry(int cmd, va_list ap)
 
 static struct builtin bintab[] = {
     BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaM:ldDANmrsLRp", NULL),
-    BUILTIN("vared",   0, bin_vared,   1,  1, 0, "aAcehM:m:p:r:t:", NULL),
+    BUILTIN("vared",   0, bin_vared,   1,  1, 0, "aAcef:hi:M:m:p:r:t:", NULL),
     BUILTIN("zle",     0, bin_zle,     0, -1, 0, "aAcCDFgGIKlLmMNrRTU", NULL),
 };
 
-- 
1.8.2.rc1


  parent reply	other threads:[~2013-03-23 14:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-23 14:46 [PATCH 0/2] Custom init and finish hooks with vared Frank Terbeck
2013-03-23 14:46 ` [PATCH 1/2] zle: Make sure state changes are refreshed after init hook Frank Terbeck
2013-06-17 14:53   ` Mikael Magnusson
2013-03-23 14:46 ` Frank Terbeck [this message]
2013-03-23 17:07 ` [PATCH 3/2] Add documentation for the new -i and -f options of vared Frank Terbeck

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=1364049998-22603-3-git-send-email-ft@bewatermyfriend.org \
    --to=ft@bewatermyfriend.org \
    --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).