here's a patch that's been on the backburner for a while. improvements and comments are appreciated. diff -r 9098c8bcd4d3 sys/src/cmd/mothra/mothra.c --- a/sys/src/cmd/mothra/mothra.c Fri Nov 01 23:39:41 2013 +0100 +++ b/sys/src/cmd/mothra/mothra.c Fri Dec 27 06:49:42 2013 -0800 @@ -9,6 +9,8 @@ #include #include #include +#include #include "mothra.h" #include "rtext.h" int debug=0; /* -d flag causes debug messages to appear in mothra.err */ @@ -86,6 +88,9 @@ void hit3(int, int); void mothon(Www *, int); void killpix(Www *w); +int incsearch(char *, int); char *buttons[]={ "alt display", "moth mode", @@ -691,6 +696,36 @@ } save(urlget(selection, -1), s); break; + case '/': /* begin incremental search */ + s = arg(s); + if (s==0 || *s=='\0') { + if(!incsearch(s, 1)) + message("no next match"); + } else if(!incsearch(s, 0)) { + message("no match for %s", s); + } + + break; case 'q': exits(0); } @@ -1154,3 +1189,137 @@ break; } } + +int +incsearch(char *what, int next) +{ + Rtext *tp; + static char *lastwhat; + static int lastidx; + Reprog *re; + int found, idx; + + found = 0; + idx = 0; + + if(next) { + what = lastwhat; + } + + lastwhat = what; + + if(current == nil || text == nil || what == nil || *what == '\0') + return 0; + + re = regcompnl(what); + if(re){ + for(tp=current->text;tp;tp=tp->next){ + tp->flags &= ~PL_SEL; + idx++; + if(next && idx <= lastidx) + continue; + + if(!tp->text || strlen(tp->text) <= 0) + continue; + + if(regexec(re, tp->text, nil, 0)){ + tp->flags |= PL_SEL; + found = 1; + current->yoffs=tp->topy; + plsetpostextview(text, current->yoffs); + flushimage(display, 1); + lastidx = idx; + message("match: %s", tp->text); + break; + } + } + + free(re); + } + + updtext(current); + + // wrap around + if(!found) + lastidx = 0; + + return found; +}