* Highlight hook @ 2015-09-27 0:28 Mikael Magnusson 2015-12-16 6:02 ` PATCH: Add zle-line-pre-redraw hook for highlighting Mikael Magnusson 0 siblings, 1 reply; 7+ messages in thread From: Mikael Magnusson @ 2015-09-27 0:28 UTC (permalink / raw) To: zsh workers I've pushed a branch (mikachu/redrawhook) that adds a hook called zle-line-pre-redraw (maybe not the best name). This is called whenever the line is edited or the cursor moves (hopefully). As you may spot from the first commit date, I've used this for a while. There were some problems with calling it from inside zrefresh() (not to mention how inefficient that is with how often zrefresh() gets called), but so far none of those have showed up with where I call it now. If there are no major problems with this, it might be nice for the highlighters to not have to wrap every single widget in zsh to call the highlighting when the line changes, since that also has other side effects. -- Mikael Magnusson ^ permalink raw reply [flat|nested] 7+ messages in thread
* PATCH: Add zle-line-pre-redraw hook for highlighting 2015-09-27 0:28 Highlight hook Mikael Magnusson @ 2015-12-16 6:02 ` Mikael Magnusson 2015-12-16 8:05 ` Bart Schaefer 0 siblings, 1 reply; 7+ messages in thread From: Mikael Magnusson @ 2015-12-16 6:02 UTC (permalink / raw) To: zsh-workers 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Add zle-line-pre-redraw hook for highlighting 2015-12-16 6:02 ` PATCH: Add zle-line-pre-redraw hook for highlighting Mikael Magnusson @ 2015-12-16 8:05 ` Bart Schaefer 2015-12-19 9:49 ` Daniel Shahaf 0 siblings, 1 reply; 7+ messages in thread From: Bart Schaefer @ 2015-12-16 8:05 UTC (permalink / raw) To: Mikael Magnusson; +Cc: Zsh hackers list [-- Attachment #1: Type: text/plain, Size: 255 bytes --] On Dec 15, 2015 10:27 PM, "Mikael Magnusson" <mikachu@gmail.com> wrote: > > If anyone has a better idea for the name of the hook, there > should be plenty of time to bikeshed before the next release :). How about just "...-pre-draw" instead of "pre-re"? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Add zle-line-pre-redraw hook for highlighting 2015-12-16 8:05 ` Bart Schaefer @ 2015-12-19 9:49 ` Daniel Shahaf 2016-01-10 22:17 ` m0viefreak 0 siblings, 1 reply; 7+ messages in thread From: Daniel Shahaf @ 2015-12-19 9:49 UTC (permalink / raw) To: Bart Schaefer; +Cc: Mikael Magnusson, Zsh hackers list Bart Schaefer wrote on Wed, Dec 16, 2015 at 00:05:01 -0800: > On Dec 15, 2015 10:27 PM, "Mikael Magnusson" <mikachu@gmail.com> wrote: > > I haven't received any complaints about 36650 from testers, so I'll go ahead > > and push this. Hooray! This should fix between 2 and 5 z-sy-h issues: https://github.com/zsh-users/zsh-syntax-highlighting/issues/245 > > If anyone has a better idea for the name of the hook, there > > should be plenty of time to bikeshed before the next release :). > > How about just "...-pre-draw" instead of "pre-re"? "pre-redraw" seems fine to me: the double "re" is not redundant, and "redraw" is the usual term for "the action performed by ^L". Cheers, Daniel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Add zle-line-pre-redraw hook for highlighting 2015-12-19 9:49 ` Daniel Shahaf @ 2016-01-10 22:17 ` m0viefreak 2016-01-11 15:26 ` Mikael Magnusson 0 siblings, 1 reply; 7+ messages in thread From: m0viefreak @ 2016-01-10 22:17 UTC (permalink / raw) To: Daniel Shahaf, Bart Schaefer; +Cc: Mikael Magnusson, Zsh hackers list On 19.12.2015 10:49, Daniel Shahaf wrote: > Bart Schaefer wrote on Wed, Dec 16, 2015 at 00:05:01 -0800: >> On Dec 15, 2015 10:27 PM, "Mikael Magnusson" <mikachu@gmail.com> wrote: >>> I haven't received any complaints about 36650 from testers, so I'll go ahead >>> and push this. > > Hooray! > > This should fix between 2 and 5 z-sy-h issues: > https://github.com/zsh-users/zsh-syntax-highlighting/issues/245 One remaining issue with this approach is the fact that this new hook is not triggered when a minibuffer such as isearch is active and BUFFER changes. Is it possible to add support for that, too? I don't know the zle internals very well, and I couldn't figure out the right spot to place a call to the hook without causing performance issues due to multiple (useless) calls. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Add zle-line-pre-redraw hook for highlighting 2016-01-10 22:17 ` m0viefreak @ 2016-01-11 15:26 ` Mikael Magnusson 2016-01-13 0:57 ` Daniel Shahaf 0 siblings, 1 reply; 7+ messages in thread From: Mikael Magnusson @ 2016-01-11 15:26 UTC (permalink / raw) To: m0viefreak; +Cc: Daniel Shahaf, Bart Schaefer, Zsh hackers list On Sun, Jan 10, 2016 at 11:17 PM, m0viefreak <m0viefreak.cm@googlemail.com> wrote: > > > On 19.12.2015 10:49, Daniel Shahaf wrote: >> Bart Schaefer wrote on Wed, Dec 16, 2015 at 00:05:01 -0800: >>> On Dec 15, 2015 10:27 PM, "Mikael Magnusson" <mikachu@gmail.com> wrote: >>>> I haven't received any complaints about 36650 from testers, so I'll go ahead >>>> and push this. >> >> Hooray! >> >> This should fix between 2 and 5 z-sy-h issues: >> https://github.com/zsh-users/zsh-syntax-highlighting/issues/245 > > One remaining issue with this approach is the fact that this new hook is > not triggered when a minibuffer such as isearch is active and BUFFER > changes. > > Is it possible to add support for that, too? > > I don't know the zle internals very well, and I couldn't figure out the > right spot to place a call to the hook without causing performance > issues due to multiple (useless) calls. You can probably add your redraw hook at the end of your zle-isearch-update and zle-isearch-exit hooks (not sure if both are needed). If you don't use them already, just point them directly at your redraw hook function. -- Mikael Magnusson ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Add zle-line-pre-redraw hook for highlighting 2016-01-11 15:26 ` Mikael Magnusson @ 2016-01-13 0:57 ` Daniel Shahaf 0 siblings, 0 replies; 7+ messages in thread From: Daniel Shahaf @ 2016-01-13 0:57 UTC (permalink / raw) To: Mikael Magnusson; +Cc: m0viefreak, Zsh hackers list Mikael Magnusson wrote on Mon, Jan 11, 2016 at 16:26:22 +0100: > On Sun, Jan 10, 2016 at 11:17 PM, m0viefreak > <m0viefreak.cm@googlemail.com> wrote: > > > > > > On 19.12.2015 10:49, Daniel Shahaf wrote: > >> Bart Schaefer wrote on Wed, Dec 16, 2015 at 00:05:01 -0800: > >>> On Dec 15, 2015 10:27 PM, "Mikael Magnusson" <mikachu@gmail.com> wrote: > >>>> I haven't received any complaints about 36650 from testers, so I'll go ahead > >>>> and push this. > >> > >> Hooray! > >> > >> This should fix between 2 and 5 z-sy-h issues: > >> https://github.com/zsh-users/zsh-syntax-highlighting/issues/245 > > > > One remaining issue with this approach is the fact that this new hook is > > not triggered when a minibuffer such as isearch is active and BUFFER > > changes. > > > > Is it possible to add support for that, too? > > > > I don't know the zle internals very well, and I couldn't figure out the > > right spot to place a call to the hook without causing performance > > issues due to multiple (useless) calls. > > You can probably add your redraw hook at the end of your > zle-isearch-update and zle-isearch-exit hooks (not sure if both are > needed). If you don't use them already, just point them directly at > your redraw hook function. Like the enclosed patch, then? I'd use this in z-sy-h, and in that context I can't ask every user to change their zle-isearch-update hook, and there's no equivalent of $chpwd_functions for that hook either. I've tested this patch from (an experimental branch of) z-sy-h and it seems to work fine: highlighting is now applied during isearch. (The underline 'isearch' highlighting was not applied to the fg=green parts of the command-line, but that's a separate issue.) Cheers, Daniel diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c index 95d96c9..abd6e17 100644 --- a/Src/Zle/zle_hist.c +++ b/Src/Zle/zle_hist.c @@ -1480,6 +1480,7 @@ doisearch(char **args, int dir, int pattern) isearch_active = 0; ref: zlecallhook("zle-isearch-update", NULL); + redrawhook(); zrefresh(); if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) { int i; @@ -1694,6 +1695,7 @@ doisearch(char **args, int dir, int pattern) statusline = NULL; unmetafy_line(); zlecallhook("zle-isearch-exit", NULL); + redrawhook(); if (exitfn) exitfn(zlenoargs); selectkeymap(okeymap, 1); diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 7862d48..6e2bfde 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1025,7 +1025,8 @@ getrestchar(int inchar, char *outstr, int *outcount) /**/ #endif -static void redrawhook() +/**/ +void redrawhook(void) { Thingy initthingy; if ((initthingy = rthingy_nocreate("zle-line-pre-redraw"))) { ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-01-13 0:57 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-09-27 0:28 Highlight hook Mikael Magnusson 2015-12-16 6:02 ` PATCH: Add zle-line-pre-redraw hook for highlighting Mikael Magnusson 2015-12-16 8:05 ` 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
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).