zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] zle: Call zle-line-pre-redraw when popping from bufstack.
@ 2016-09-25 13:25 Daniel Shahaf
  2016-09-25 14:00 ` Mikael Magnusson
  2016-09-26  9:59 ` PATCH: Call the pre-redraw hook if there is text in the buffer on init Mikael Magnusson
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-09-25 13:25 UTC (permalink / raw)
  To: zsh-workers

---
I'd appreciate another pair of eyes; it looks correct but I'm not very
familiar with this part of the code.

Originally reported as <https://github.com/zsh-users/zsh-syntax-highlighting/issues/40>.

Thanks,

Daniel

 Src/Zle/zle_main.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 9a83d41..89a545b 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1162,7 +1162,16 @@ zlecore(void)
     popheap();
 }
 
-/* Read a line.  It is returned metafied. */
+/* Read a line.  It is returned metafied.
+ *
+ * Parmaeters:
+ * - lp: left prompt, e.g., $PS1
+ * - rp: right prompt, e.g., $RPS1
+ * - flags: ZLRF_* flags (I think), see zlereadflags
+ * - context: ZLCON_* flags (I think), see zlecontext
+ * - init: "zle-line-init"
+ * - finish: "zle-line-finish"
+ */
 
 /**/
 char *
@@ -1171,6 +1180,7 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
     char *s, **bracket;
     int old_errno = errno;
     int tmout = getiparam("TMOUT");
+    int redraw_required = 0;
 
 #if defined(HAVE_POLL) || defined(HAVE_SELECT)
     /* may not be set, but that's OK since getiparam() returns 0 == off */
@@ -1242,6 +1252,7 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
     initundo();
     fixsuffix();
     if ((s = getlinknode(bufstack))) {
+	redraw_required = 1;
 	setline(s, ZSL_TOEND);
 	zsfree(s);
 	if (stackcs != -1) {
@@ -1293,6 +1304,12 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
     prefixflag = 0;
     region_active = 0;
 
+    if (redraw_required) {
+	/* If we popped a command from bufstack, syntax highlight it, now
+	 * that zle is active. */
+	redrawhook();
+    }
+
     zrefresh();
 
     unqueue_signals();	/* Should now be safe to acknowledge SIGWINCH */


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

* Re: [PATCH] zle: Call zle-line-pre-redraw when popping from bufstack.
  2016-09-25 13:25 [PATCH] zle: Call zle-line-pre-redraw when popping from bufstack Daniel Shahaf
@ 2016-09-25 14:00 ` Mikael Magnusson
  2016-09-26  9:59 ` PATCH: Call the pre-redraw hook if there is text in the buffer on init Mikael Magnusson
  1 sibling, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2016-09-25 14:00 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh workers

On Sun, Sep 25, 2016 at 3:25 PM, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> ---
> I'd appreciate another pair of eyes; it looks correct but I'm not very
> familiar with this part of the code.
>
> Originally reported as <https://github.com/zsh-users/zsh-syntax-highlighting/issues/40>.

It's a nice looking patch, but it doesn't actually make any difference
for me. If it did, calling the syntax hilight hook from the
zle-line-init hook function should have worked too, since that hook is
called 3 lines later.

The only thing I've found that makes it work is calling redrawhook()
from inside zrefresh() but we obviously don't want to do that.

-- 
Mikael Magnusson


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

* PATCH: Call the pre-redraw hook if there is text in the buffer on init
  2016-09-25 13:25 [PATCH] zle: Call zle-line-pre-redraw when popping from bufstack Daniel Shahaf
  2016-09-25 14:00 ` Mikael Magnusson
@ 2016-09-26  9:59 ` Mikael Magnusson
  2016-09-30  4:54   ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2016-09-26  9:59 UTC (permalink / raw)
  To: zsh-workers

[ As it turns out, the reason Daniel's patch didn't work for me was a
problem in my hook function, it just did an early return for optimization
based on how many times it was called since the last accept-line,
and that was off by one when popping the buffer apparently, I've just
removed that check now.

If you want to commit your comment at the top, there's a typo for Parmaeters. ]

Either way, I think this approach might be better. It will highlight
any text that may also have been added by the zle-line-init hook, in
addition to also highlighting popped text.

---
 Src/Zle/zle_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 90e38042be..7a3cf249cf 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1299,6 +1299,9 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
 
     zlecallhook(init, NULL);
 
+    if (zleline && *zleline)
+	redrawhook();
+
     if ((bracket = getaparam("zle_bracketed_paste")) && arrlen(bracket) == 2)
 	fputs(*bracket, shout);
 
-- 
2.8.2


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

* Re: PATCH: Call the pre-redraw hook if there is text in the buffer on init
  2016-09-26  9:59 ` PATCH: Call the pre-redraw hook if there is text in the buffer on init Mikael Magnusson
@ 2016-09-30  4:54   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-09-30  4:54 UTC (permalink / raw)
  To: zsh-workers

On Sep 26, 11:59am, Mikael Magnusson wrote:
}
} Either way, I think this approach might be better. It will highlight
} any text that may also have been added by the zle-line-init hook, in
} addition to also highlighting popped text.

This looks fine to me.


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

end of thread, other threads:[~2016-09-30  4:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-25 13:25 [PATCH] zle: Call zle-line-pre-redraw when popping from bufstack Daniel Shahaf
2016-09-25 14:00 ` Mikael Magnusson
2016-09-26  9:59 ` PATCH: Call the pre-redraw hook if there is text in the buffer on init Mikael Magnusson
2016-09-30  4:54   ` Bart Schaefer

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