zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 0/2] Custom init and finish hooks with vared
@ 2013-03-23 14:46 Frank Terbeck
  2013-03-23 14:46 ` [PATCH 1/2] zle: Make sure state changes are refreshed after init hook Frank Terbeck
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Frank Terbeck @ 2013-03-23 14:46 UTC (permalink / raw)
  To: zsh-workers

So, I wanted to write a function that helps me write commit messages with
git from the command line, roughly like this:

#+begin_src shell-script
local msg name email
name=$(git config --get user.name)
email=$(git config --get user.email)
msg="

Signed-off-by: $name <$email>"

vared -p $' - type your commit message -\n' msg
printf '%s\n' "$msg" | git commit -F-
#+begin_src shell-script

Of course, I wanted to have the cursor at the very beginning of the
vared buffer after vared started up. I could have done it by using
$CONTEXT and some other state-handling variables all within
`zle-line-init', but I think being able to do it the way the second
patch of this series implements is way more elegant.

Documentation update coming up, unless someone screams "this has no
chance of making it into the core!"... ;)

Regards, Frank


Frank Terbeck (2):
  zle: Make sure state changes are refreshed after init hook
  Let vared define custom init and finish hooks

 Src/Zle/zle_main.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

-- 
1.8.2.rc1


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

* [PATCH 1/2] zle: Make sure state changes are refreshed after init hook
  2013-03-23 14:46 [PATCH 0/2] Custom init and finish hooks with vared Frank Terbeck
@ 2013-03-23 14:46 ` Frank Terbeck
  2013-06-17 14:53   ` Mikael Magnusson
  2013-03-23 14:46 ` [PATCH 2/2] Let vared define custom init and finish hooks Frank Terbeck
  2013-03-23 17:07 ` [PATCH 3/2] Add documentation for the new -i and -f options of vared Frank Terbeck
  2 siblings, 1 reply; 5+ messages in thread
From: Frank Terbeck @ 2013-03-23 14:46 UTC (permalink / raw)
  To: zsh-workers

If `zrefresh' is not called _after_ the zle-line-init hook, any changes
made to the editor's state (be it changes to $CURSOR or $BUFFER or
called widgets like `clear-screen') will only be picked up after the
first character is typed into the editor.
---
 Src/Zle/zle_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index e1a575b..5157ad3 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1219,12 +1219,12 @@ zleread(char **lp, char **rp, int flags, int context)
     initmodifier(&zmod);
     prefixflag = 0;
 
-    zrefresh();
-
     unqueue_signals();	/* Should now be safe to acknowledge SIGWINCH */
 
     zlecallhook("zle-line-init", NULL);
 
+    zrefresh();
+
     zlecore();
 
     if (errflag)
-- 
1.8.2.rc1


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

* [PATCH 2/2] Let vared define custom init and finish hooks
  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-03-23 14:46 ` Frank Terbeck
  2013-03-23 17:07 ` [PATCH 3/2] Add documentation for the new -i and -f options of vared Frank Terbeck
  2 siblings, 0 replies; 5+ messages in thread
From: Frank Terbeck @ 2013-03-23 14:46 UTC (permalink / raw)
  To: zsh-workers

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


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

* [PATCH 3/2] Add documentation for the new -i and -f options of vared
  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-03-23 14:46 ` [PATCH 2/2] Let vared define custom init and finish hooks Frank Terbeck
@ 2013-03-23 17:07 ` Frank Terbeck
  2 siblings, 0 replies; 5+ messages in thread
From: Frank Terbeck @ 2013-03-23 17:07 UTC (permalink / raw)
  To: zsh-workers

---
 Doc/Zsh/zle.yo | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 3e8c25a..3549fda 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -308,6 +308,7 @@ cindex(parameters, editing)
 cindex(editing parameters)
 xitem(tt(vared) [ tt(-Aache) ] [ tt(-p) var(prompt) ] [ tt(-r) var(rprompt) ])
 xitem(  [ tt(-M) var(main-keymap) ] [ tt(-m) var(vicmd-keymap) ])
+xitem(  [ tt(-i) var(init-widget) ] [ tt(-f) var(finish-widget) ])
 item(  [ tt(-t) var(tty) ] var(name))(
 The value of the parameter var(name) is loaded into the edit
 buffer, and the line editor is invoked.  When the editor exits,
@@ -343,6 +344,10 @@ to override tt(viins) and tt(vicmd).  For emacs-style editing, only tt(-M)
 is normally needed but the tt(-m) option may still be used.  On exit, the
 previous keymaps will be restored.
 
+tt(Vared) calls the usual `tt(zle-line-init)' and `tt(zle-line-finish)'
+hooks before and after it takes control. Using the tt(-i) and tt(-f)
+options, it is possible to replace these with other costum widgets.
+
 If `tt(-t) var(tty)' is given, var(tty) is the name of a terminal device
 to be used instead of the default tt(/dev/tty).  If var(tty) does not
 refer to a terminal an error is reported.
-- 
1.8.2.rc1


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

* Re: [PATCH 1/2] zle: Make sure state changes are refreshed after init hook
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Mikael Magnusson @ 2013-06-17 14:53 UTC (permalink / raw)
  To: Frank Terbeck; +Cc: zsh workers

This patch causes a hang on startup with this .zshrc

zle -N zle-line-init foo
zle -N set-local-history bar
foo() { zle set-local-history -n 1 }
bar() { zle reset-prompt }

This patch fixes it, see also the commit a ways above,

     /*
      * On some windowing systems we may enter this function before the
      * terminal is fully opened and sized, resulting in an infinite
      * series of SIGWINCH when the handler prints the prompt before we
      * have done so here.  Therefore, hold any such signal until the
      * first full refresh has completed.  The important bit is that the
      * handler must not see zleactive = 1 until ZLE really is active.
      * See the end of adjustwinsize() in Src/utils.c
      */

@@ -1229,6 +1229,8 @@
     initmodifier(&zmod);
     prefixflag = 0;

+    zrefresh();
+
     unqueue_signals(); /* Should now be safe to acknowledge SIGWINCH */

     zlecallhook(init, NULL);


On 23 March 2013 15:46, Frank Terbeck <ft@bewatermyfriend.org> wrote:
> If `zrefresh' is not called _after_ the zle-line-init hook, any changes
> made to the editor's state (be it changes to $CURSOR or $BUFFER or
> called widgets like `clear-screen') will only be picked up after the
> first character is typed into the editor.
> ---
>  Src/Zle/zle_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
> index e1a575b..5157ad3 100644
> --- a/Src/Zle/zle_main.c
> +++ b/Src/Zle/zle_main.c
> @@ -1219,12 +1219,12 @@ zleread(char **lp, char **rp, int flags, int context)
>      initmodifier(&zmod);
>      prefixflag = 0;
>
> -    zrefresh();
> -
>      unqueue_signals(); /* Should now be safe to acknowledge SIGWINCH */
>
>      zlecallhook("zle-line-init", NULL);
>
> +    zrefresh();
> +
>      zlecore();
>
>      if (errflag)
> --
> 1.8.2.rc1
>



-- 
Mikael Magnusson


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

end of thread, other threads:[~2013-06-17 14:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] Let vared define custom init and finish hooks Frank Terbeck
2013-03-23 17:07 ` [PATCH 3/2] Add documentation for the new -i and -f options of vared Frank Terbeck

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