* Add a hook on isearch @ 2010-09-18 16:50 Mikael Magnusson 2010-09-18 20:00 ` Bart Schaefer 2010-09-23 9:40 ` Peter Stephenson 0 siblings, 2 replies; 5+ messages in thread From: Mikael Magnusson @ 2010-09-18 16:50 UTC (permalink / raw) To: zsh workers This might make something explode, but it's probably pretty useful. function _show_surroundings() { typeset -a output typeset -A star star[$HISTNO]="*" for ((i = HISTNO - ${NUMERIC:-5}; i < HISTNO + ${NUMERIC:-5} && i < HISTCMD; i++)); do output=( "$star[$i]$i: $history[$i]" $output ) done zle -M ${(pj:\n:)output} } zle -N zle-isearch-update _show_surroundings % edit .zshrc bck-i-search: edit .zshrc_ 2293: src *2292: edit .zshrc 2291: zle-isearch-update() { zle _show_surroundings } 2290: zle-isearch-update() { zle -M $HISTNO } 2289: zle-isearch-update() { zle -M lol } 2288: zle -N zle-isearch-update 2287: echo $history[HISTCMD] commit 8ab10e2394da712db896662316fb4df304c212ef Author: Mikael Magnusson <mikachu@gmail.com> Date: Sat Sep 18 18:46:38 2010 +0200 Add zle-isearch-update diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c index d9586b8..1daf8e1 100644 --- a/Src/Zle/zle_hist.c +++ b/Src/Zle/zle_hist.c @@ -1472,7 +1472,16 @@ doisearch(char **args, int dir, int pattern) } else isearch_active = 0; ref: + if ((cmd = rthingy_nocreate("zle-isearch-update"))) { + char *args[2]; + args[0] = cmd->nam; + args[1] = NULL; + execzlefunc(cmd, args, 1); + unrefthingy(cmd); + } + zrefresh(); + if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) { int i; aborted = 1; -- Mikael Magnusson ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add a hook on isearch 2010-09-18 16:50 Add a hook on isearch Mikael Magnusson @ 2010-09-18 20:00 ` Bart Schaefer 2010-09-19 14:54 ` Mikael Magnusson 2010-09-20 9:02 ` Peter Stephenson 2010-09-23 9:40 ` Peter Stephenson 1 sibling, 2 replies; 5+ messages in thread From: Bart Schaefer @ 2010-09-18 20:00 UTC (permalink / raw) To: zsh workers On Sep 18, 6:50pm, Mikael Magnusson wrote: } } This might make something explode, but it's probably pretty useful. Maybe it's time for a callhookzle() to go with callhookfunc() and runhookdef()? } ref: } + if ((cmd = rthingy_nocreate("zle-isearch-update"))) { } + char *args[2]; } + args[0] = cmd->nam; } + args[1] = NULL; } + execzlefunc(cmd, args, 1); } + unrefthingy(cmd); } + } } + Seems like there's some global state management that this might not be doing with respect to errflag and retflag. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add a hook on isearch 2010-09-18 20:00 ` Bart Schaefer @ 2010-09-19 14:54 ` Mikael Magnusson 2010-09-20 9:02 ` Peter Stephenson 1 sibling, 0 replies; 5+ messages in thread From: Mikael Magnusson @ 2010-09-19 14:54 UTC (permalink / raw) To: zsh workers On 18 September 2010 22:00, Bart Schaefer <schaefer@brasslantern.com> wrote: > On Sep 18, 6:50pm, Mikael Magnusson wrote: > } > } This might make something explode, but it's probably pretty useful. > > Maybe it's time for a callhookzle() to go with callhookfunc() and > runhookdef()? > > } ref: > } + if ((cmd = rthingy_nocreate("zle-isearch-update"))) { > } + char *args[2]; > } + args[0] = cmd->nam; > } + args[1] = NULL; > } + execzlefunc(cmd, args, 1); > } + unrefthingy(cmd); > } + } > } + > > Seems like there's some global state management that this might not > be doing with respect to errflag and retflag. I did something similar on that patch i just linked to on users that runs on every buffer refresh, and that subtly breaks ^r searching, so I guess this might have similar problems. Unfortunately (for me) I just wrote "some static variables" in that mail, so who knows which ones it actually is... :). -- Mikael Magnusson ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add a hook on isearch 2010-09-18 20:00 ` Bart Schaefer 2010-09-19 14:54 ` Mikael Magnusson @ 2010-09-20 9:02 ` Peter Stephenson 1 sibling, 0 replies; 5+ messages in thread From: Peter Stephenson @ 2010-09-20 9:02 UTC (permalink / raw) To: zsh workers On Sat, 18 Sep 2010 13:00:49 -0700 Bart Schaefer <schaefer@brasslantern.com> wrote: > On Sep 18, 6:50pm, Mikael Magnusson wrote: > Maybe it's time for a callhookzle() to go with callhookfunc() and > runhookdef()? This made me notice the arguments for zle-keymap-select were wrong: for a user-defined widget, the arguments directly turn into function arguments, so argument 0 is always the function name and any additional argument needs to be the next argument (see doshfunc()). Index: Src/Zle/zle_keymap.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v retrieving revision 1.35 diff -p -u -r1.35 zle_keymap.c --- Src/Zle/zle_keymap.c 8 Sep 2010 12:32:32 -0000 1.35 +++ Src/Zle/zle_keymap.c 20 Sep 2010 09:00:46 -0000 @@ -486,22 +486,11 @@ selectkeymap(char *name, int fb) } if(name != curkeymapname) { char *oname = curkeymapname; - Thingy chgthingy; curkeymapname = ztrdup(name); - if (oname && zleactive && strcmp(oname, curkeymapname) && - (chgthingy = rthingy_nocreate("zle-keymap-select"))) { - char *args[2]; - int saverrflag = errflag, savretflag = retflag; - args[0] = oname; - args[1] = NULL; - errflag = retflag = 0; - execzlefunc(chgthingy, args, 1); - unrefthingy(chgthingy); - errflag = saverrflag; - retflag = savretflag; - } + if (oname && zleactive && strcmp(oname, curkeymapname)) + zlecallhook("zle-keymap-select", oname); zsfree(oname); } curkeymap = km; Index: Src/Zle/zle_main.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v retrieving revision 1.125 diff -p -u -r1.125 zle_main.c --- Src/Zle/zle_main.c 8 Sep 2010 12:32:32 -0000 1.125 +++ Src/Zle/zle_main.c 20 Sep 2010 09:00:46 -0000 @@ -1115,7 +1115,6 @@ zleread(char **lp, char **rp, int flags, char *s; int old_errno = errno; int tmout = getiparam("TMOUT"); - Thingy initthingy; #if defined(HAVE_POLL) || defined(HAVE_SELECT) /* may not be set, but that's OK since getiparam() returns 0 == off */ @@ -1215,32 +1214,15 @@ zleread(char **lp, char **rp, int flags, zrefresh(); - if ((initthingy = rthingy_nocreate("zle-line-init"))) { - char *args[2]; - args[0] = initthingy->nam; - args[1] = NULL; - execzlefunc(initthingy, args, 1); - unrefthingy(initthingy); - errflag = retflag = 0; - } + zlecallhook("zle-line-init", NULL); zlecore(); if (errflag) setsparam("ZLE_LINE_ABORTED", zlegetline(NULL, NULL)); - if (done && !exit_pending && !errflag && - (initthingy = rthingy_nocreate("zle-line-finish"))) { - int saverrflag = errflag; - int savretflag = retflag; - char *args[2]; - args[0] = initthingy->nam; - args[1] = NULL; - execzlefunc(initthingy, args, 1); - unrefthingy(initthingy); - errflag = saverrflag; - retflag = savretflag; - } + if (done && !exit_pending && !errflag) + zlecallhook("zle-line-finish", NULL); statusline = NULL; invalidatelist(); Index: Src/Zle/zle_utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v retrieving revision 1.56 diff -p -u -r1.56 zle_utils.c --- Src/Zle/zle_utils.c 22 Mar 2010 19:49:07 -0000 1.56 +++ Src/Zle/zle_utils.c 20 Sep 2010 09:00:46 -0000 @@ -1237,3 +1237,35 @@ viundochange(char **args) } else return undo(args); } + +/* + * Call a ZLE hook: a user-defined widget called at a specific point + * within the line editor. + * + * A single argument arg is passed to the function (in addition to the + * function name). It may be NULL. + */ + +/**/ +void +zlecallhook(char *name, char *arg) +{ + Thingy thingy = rthingy_nocreate(name); + int saverrflag, savretflag; + char *args[3]; + + if (!thingy) + return; + + saverrflag = errflag; + savretflag = retflag; + + args[0] = thingy->nam; + args[1] = arg; + args[2] = NULL; + execzlefunc(thingy, args, 1); + unrefthingy(thingy); + + errflag = saverrflag; + retflag = savretflag; +} -- Peter Stephenson <pws@csr.com> Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Add a hook on isearch 2010-09-18 16:50 Add a hook on isearch Mikael Magnusson 2010-09-18 20:00 ` Bart Schaefer @ 2010-09-23 9:40 ` Peter Stephenson 1 sibling, 0 replies; 5+ messages in thread From: Peter Stephenson @ 2010-09-23 9:40 UTC (permalink / raw) To: zsh workers On Sat, 18 Sep 2010 18:50:42 +0200 Mikael Magnusson <mikachu@gmail.com> wrote: > commit 8ab10e2394da712db896662316fb4df304c212ef > Author: Mikael Magnusson <mikachu@gmail.com> > Date: Sat Sep 18 18:46:38 2010 +0200 > > Add zle-isearch-update I tried this and it seemed to work... There may be things you shouldn't be doing at that point but I'm not sure what they are. The exit hook needed to be after setting statusline to NULL. Apart from that, I'm not sure what the best place is. Index: Doc/Zsh/zle.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v retrieving revision 1.88 diff -p -u -r1.88 zle.yo --- Doc/Zsh/zle.yo 8 Sep 2010 12:32:32 -0000 1.88 +++ Doc/Zsh/zle.yo 23 Sep 2010 09:32:30 -0000 @@ -887,6 +887,28 @@ If they do not exist, no special action provided is identical to that for any other editing widget. startitem() +tindex(zle-isearch-exit) +item(tt(zle-isearch-exit))( +Executed at the end of incremental search at the point where the isearch +prompt is removed from the display. See tt(zle-isearch-update) for +an example. +) +tindex(zle-isearch-update) +item(tt(zle-isearch-update))( +Executed within incremental search when the display is about to be +redrawn. Additional output below the incremental search prompt can be +generated by using `tt(zle -M)' within the widget. For example, + +example(zle-isearch-update+LPAR()RPAR() { zle -M "Line $HISTNO"; } +zle -N zle-isearch-update) + +Note the line output by `tt(zle -M)' is not deleted on exit from +incremental search. This can be done from a tt(zle-isearch-exit) +widget: + +example(zle-isearch-exit+LPAR()RPAR() { zle -M ""; } +zle -N zle-isearch-exit) +) tindex(zle-line-init) item(tt(zle-line-init))( Executed every time the line editor is started to read a new line Index: Src/Zle/zle_hist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_hist.c,v retrieving revision 1.65 diff -p -u -r1.65 zle_hist.c --- Src/Zle/zle_hist.c 27 Apr 2010 08:58:35 -0000 1.65 +++ Src/Zle/zle_hist.c 23 Sep 2010 09:32:31 -0000 @@ -1472,6 +1472,7 @@ doisearch(char **args, int dir, int patt } else isearch_active = 0; ref: + zlecallhook("zle-isearch-update", NULL); zrefresh(); if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) { int i; @@ -1670,6 +1671,7 @@ doisearch(char **args, int dir, int patt } statusline = NULL; unmetafy_line(); + zlecallhook("zle-isearch-exit", NULL); if (exitfn) exitfn(zlenoargs); selectkeymap(okeymap, 1); -- Peter Stephenson <pws@csr.com> Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-09-23 10:31 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-09-18 16:50 Add a hook on isearch Mikael Magnusson 2010-09-18 20:00 ` Bart Schaefer 2010-09-19 14:54 ` Mikael Magnusson 2010-09-20 9:02 ` Peter Stephenson 2010-09-23 9:40 ` Peter Stephenson
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).