zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] add-zle-hook-widget zle-line-pre-redraw issue
@ 2016-07-23 21:23 Daniel Shahaf
  2016-07-24  1:14 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2016-07-23 21:23 UTC (permalink / raw)
  To: zsh-workers

Hooks registered with «add-zle-hook-widget zle-line-pre-redraw $hook»
aren't invoked.  In contrast, hooks registered with zle-line-finish are
invoked.

The reason appears to be that, while in azhw:zle-line-init $WIDGET is
"zle-line-init", in azhw:zle-line-pre-redraw $WIDGET is the name of the
widget the user invoked (e.g., "self-insert"), so the 'zstyle -a' does
not find the registered hooks.

Each of the following alternative patches solves the issue:

First option:
[[[
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index ac31d4e..9f2742a 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1054,7 +1055,7 @@ void redrawhook(void)
 	args[0] = initthingy->nam;
 	args[1] = NULL;
 	incompfunc = 0;
-	execzlefunc(initthingy, args, 0);
+	execzlefunc(initthingy, args, 1);
 	incompfunc = old_incompfunc;
 	unrefthingy(initthingy);
 	unrefthingy(lbindk);
]]]

Second option:
[[[
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index ac31d4e..90e54d6 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1044,6 +1044,10 @@ getrestchar(int inchar, char *outstr, int *outcount)
 void redrawhook(void)
 {
     Thingy initthingy;
+
+    zlecallhook("zle-line-pre-redraw", NULL);
+    return;
+
     if ((initthingy = rthingy_nocreate("zle-line-pre-redraw"))) {
 	int lastcmd_prev = lastcmd;
 	int old_incompfunc = incompfunc;
]]]

The principal differences seem to be which set of globals is
saved/restored or changed/restored; however, which set it should be is
all Greek to me.

Cheers,

Daniel
(I haven't tested the other hook types.)


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

* Re: [PATCH] add-zle-hook-widget zle-line-pre-redraw issue
  2016-07-23 21:23 [PATCH] add-zle-hook-widget zle-line-pre-redraw issue Daniel Shahaf
@ 2016-07-24  1:14 ` Bart Schaefer
  2016-07-24 21:30   ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-07-24  1:14 UTC (permalink / raw)
  To: zsh-workers

On Jul 23,  9:23pm, Daniel Shahaf wrote:
}
} The reason appears to be that, while in azhw:zle-line-init $WIDGET is
} "zle-line-init", in azhw:zle-line-pre-redraw $WIDGET is the name of the
} widget the user invoked (e.g., "self-insert"), so the 'zstyle -a' does
} not find the registered hooks.

If zsh-syntax-highlighting doesn't depend on that behavior, it's probably
unlikely that anything else does.

However, Mikael will have to weigh in on whether he chose do to this
intentionally.

} Each of the following alternative patches solves the issue:

The "second option" obviously isn't finished / leaves a lot of dead
code behind.  However, I think the first option is the correct one,
unless there's a good reason to leave $WIDGET alone; the context
that's being saved/restored by redrawhook() is important, because
we're in the middle of an arbitrary other widget

This is actually related to what I was saying about it not being
appropriate to stick a list of callbacks on any widget.

We can easily special-case add-zle-hook-widget to find the name another
way for this particular hook.  $funcstack[1] for example.

Incidentally, I tried making ALL the possible hooks be

    zle -M "$WIDGET $funcstack[1]"

and learned two things.  (1) pre-redraw is in fact the only hook that
doesn't change $WIDGET, and (2) having all the hooks call "zle -M"
garbles the output quite thoroughly, especially in vi mode.


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

* Re: [PATCH] add-zle-hook-widget zle-line-pre-redraw issue
  2016-07-24  1:14 ` Bart Schaefer
@ 2016-07-24 21:30   ` Daniel Shahaf
  2016-07-28  2:34     ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2016-07-24 21:30 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Sat, Jul 23, 2016 at 18:14:45 -0700:
> On Jul 23,  9:23pm, Daniel Shahaf wrote:
> }
> } The reason appears to be that, while in azhw:zle-line-init $WIDGET is
> } "zle-line-init", in azhw:zle-line-pre-redraw $WIDGET is the name of the
> } widget the user invoked (e.g., "self-insert"), so the 'zstyle -a' does
> } not find the registered hooks.
> 
> If zsh-syntax-highlighting doesn't depend on that behavior, it's probably
> unlikely that anything else does.

z-sy-h assumes that zle-line-finish sets $WIDGET, but doesn't assume
anything else about $WIDGET.

> } Each of the following alternative patches solves the issue:
> 
> The "second option" obviously isn't finished / leaves a lot of dead
> code behind.

Indeed it isn't: the unidiff I'd sent was not the unidiff I would commit
if that option is chosen.  Its purpose was not to be committed as is,
only to unambiguously explain what the second alternative was.

Sorry if that wasn't clear.

> However, I think the first option is the correct one,
> unless there's a good reason to leave $WIDGET alone; the context
> that's being saved/restored by redrawhook() is important, because
> we're in the middle of an arbitrary other widget
> 
> This is actually related to what I was saying about it not being
> appropriate to stick a list of callbacks on any widget.
> 
> We can easily special-case add-zle-hook-widget to find the name another
> way for this particular hook.  $funcstack[1] for example.

Okay, so let's wait for Mikael to weigh in, then we can choose between
making pre-redraw set $WIDGET or making a-z-h-w handle pre-redraw's not
doing so.

> Incidentally, I tried making ALL the possible hooks be
> 
>     zle -M "$WIDGET $funcstack[1]"
> 
> and learned two things.  (1) pre-redraw is in fact the only hook that
> doesn't change $WIDGET, and (2) having all the hooks call "zle -M"
> garbles the output quite thoroughly, especially in vi mode.

Thanks for checking (1).  I can reproduce (2), the prompt character
doesn't render and <accept-line> doesn't move down the screen.

Cheers,

Daniel


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

* Re: [PATCH] add-zle-hook-widget zle-line-pre-redraw issue
  2016-07-24 21:30   ` Daniel Shahaf
@ 2016-07-28  2:34     ` Mikael Magnusson
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2016-07-28  2:34 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh workers

On Sun, Jul 24, 2016 at 11:30 PM, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Bart Schaefer wrote on Sat, Jul 23, 2016 at 18:14:45 -0700:
>> On Jul 23,  9:23pm, Daniel Shahaf wrote:
>> }
>> } The reason appears to be that, while in azhw:zle-line-init $WIDGET is
>> } "zle-line-init", in azhw:zle-line-pre-redraw $WIDGET is the name of the
>> } widget the user invoked (e.g., "self-insert"), so the 'zstyle -a' does
>> } not find the registered hooks.
>>
>> If zsh-syntax-highlighting doesn't depend on that behavior, it's probably
>> unlikely that anything else does.
>
> z-sy-h assumes that zle-line-finish sets $WIDGET, but doesn't assume
> anything else about $WIDGET.
>
>> } Each of the following alternative patches solves the issue:
>>
>> The "second option" obviously isn't finished / leaves a lot of dead
>> code behind.
>
> Indeed it isn't: the unidiff I'd sent was not the unidiff I would commit
> if that option is chosen.  Its purpose was not to be committed as is,
> only to unambiguously explain what the second alternative was.
>
> Sorry if that wasn't clear.
>
>> However, I think the first option is the correct one,
>> unless there's a good reason to leave $WIDGET alone; the context
>> that's being saved/restored by redrawhook() is important, because
>> we're in the middle of an arbitrary other widget
>>
>> This is actually related to what I was saying about it not being
>> appropriate to stick a list of callbacks on any widget.
>>
>> We can easily special-case add-zle-hook-widget to find the name another
>> way for this particular hook.  $funcstack[1] for example.
>
> Okay, so let's wait for Mikael to weigh in, then we can choose between
> making pre-redraw set $WIDGET or making a-z-h-w handle pre-redraw's not
> doing so.

I don't think I made a conscious decision about this when writing the
code, so if there's any dissimilarity between this and other things
it's probably unintentional. I don't use $WIDGET myself in my callback
either. I think I just copied the part that sets args[0] a bit blindly
from another callback, but in that one I bet it uses initthingy->nam
for the rthingy_nocreate() call too. So to summarize, feel free to
change it.

-- 
Mikael Magnusson


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

end of thread, other threads:[~2016-07-28 14:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-23 21:23 [PATCH] add-zle-hook-widget zle-line-pre-redraw issue Daniel Shahaf
2016-07-24  1:14 ` Bart Schaefer
2016-07-24 21:30   ` Daniel Shahaf
2016-07-28  2:34     ` Mikael Magnusson

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