zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: Add zle-line-pre-redraw hook for highlighting
Date: Wed, 16 Dec 2015 07:02:34 +0100	[thread overview]
Message-ID: <1450245754-2760-1-git-send-email-mikachu@gmail.com> (raw)
In-Reply-To: <CAHYJk3QvRnYxLMb8XsoWB1hU92Qti_fEKt1JgxkyDARrhf1g7g@mail.gmail.com>

I haven't received any complaints about 36650 from testers, so I'll go ahead
and push this. If anyone has a better idea for the name of the hook, there
should be plenty of time to bikeshed before the next release :).

---
 Doc/Zsh/zle.yo     |  5 +++++
 Src/Zle/zle_main.c | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 7047b43..9c46232 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -1087,6 +1087,11 @@ widget:
 example(zle-isearch-exit+LPAR()RPAR() { zle -M ""; }
 zle -N zle-isearch-exit)
 )
+tindex(zle-line-pre-redraw)
+item(tt(zle-line-pre-redraw))(
+Executed whenever the input line is about to be redrawn, providing an
+opportunity to update the region_highlight array.
+)
 tindex(zle-line-init)
 item(tt(zle-line-init))(
 Executed every time the line editor is started to read a new line
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 1f0c07d..7862d48 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1025,6 +1025,31 @@ getrestchar(int inchar, char *outstr, int *outcount)
 /**/
 #endif
 
+static void redrawhook()
+{
+    Thingy initthingy;
+    if ((initthingy = rthingy_nocreate("zle-line-pre-redraw"))) {
+	int lastcmd_prev = lastcmd;
+	int old_incompfunc = incompfunc;
+	char *args[2];
+	Thingy lbindk_save = lbindk, bindk_save = bindk;
+	refthingy(lbindk_save);
+	refthingy(bindk_save);
+	args[0] = initthingy->nam;
+	args[1] = NULL;
+	incompfunc = 0;
+	execzlefunc(initthingy, args, 0);
+	incompfunc = old_incompfunc;
+	unrefthingy(initthingy);
+	unrefthingy(lbindk);
+	unrefthingy(bindk);
+	lbindk = lbindk_save;
+	bindk = bindk_save;
+	/* we can't set ZLE_NOTCOMMAND since it's not a legit widget, so
+	 * restore lastcmd manually so that we don't mess up the global state */
+	lastcmd = lastcmd_prev;
+    }
+}
 
 /**/
 void
@@ -1084,6 +1109,8 @@ zlecore(void)
 	    errflag |= ERRFLAG_ERROR;
 	    break;
 	}
+
+	redrawhook();
 #ifdef HAVE_POLL
 	if (baud && !(lastcmd & ZLE_MENUCMP)) {
 	    struct pollfd pfd;
@@ -1113,6 +1140,7 @@ zlecore(void)
 		zrefresh();
 
 	freeheap();
+
     }
 
     region_active = 0;
@@ -1191,7 +1219,7 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
     vistartchange = -1;
     zleline = (ZLE_STRING_T)zalloc(((linesz = 256) + 2) * ZLE_CHAR_SIZE);
     *zleline = ZWC('\0');
-    virangeflag = lastcmd = done = zlecs = zlell = mark = 0;
+    virangeflag = lastcmd = done = zlecs = zlell = mark = yankb = yanke = 0;
     vichgflag = 0;
     viinsbegin = 0;
     statusline = NULL;
@@ -1812,6 +1840,7 @@ recursiveedit(UNUSED(char **args))
 {
     int locerror;
 
+    redrawhook();
     zrefresh();
     zlecore();
 
-- 
2.6.1


  reply	other threads:[~2015-12-16  6:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-27  0:28 Highlight hook Mikael Magnusson
2015-12-16  6:02 ` Mikael Magnusson [this message]
2015-12-16  8:05   ` PATCH: Add zle-line-pre-redraw hook for highlighting Bart Schaefer
2015-12-19  9:49     ` Daniel Shahaf
2016-01-10 22:17       ` m0viefreak
2016-01-11 15:26         ` Mikael Magnusson
2016-01-13  0:57           ` Daniel Shahaf

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=1450245754-2760-1-git-send-email-mikachu@gmail.com \
    --to=mikachu@gmail.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).