diff options
author | Chad Loder <cloder@cvs.openbsd.org> | 2005-06-03 15:16:23 +0000 |
---|---|---|
committer | Chad Loder <cloder@cvs.openbsd.org> | 2005-06-03 15:16:23 +0000 |
commit | 2d27e91488c2a84af3958899f86ecb8e164e3633 (patch) | |
tree | fcbe5f1bd4ad3423f5e52e1af9601aadcabaf528 /usr.bin | |
parent | 32ce00245412ee82612eece7ad32b97f79c6f70e (diff) |
Like emacs, handle ^W during incremental search. Pressing ^W during
search will add the rest of the word from the current buffer to the
pattern buffer. Testing and comments by kjell and marc
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/search.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/usr.bin/mg/search.c b/usr.bin/mg/search.c index 1564b74d95e..a6d88e4206d 100644 --- a/usr.bin/mg/search.c +++ b/usr.bin/mg/search.c @@ -1,4 +1,4 @@ -/* $OpenBSD: search.c,v 1.17 2005/05/27 08:08:18 cloder Exp $ */ +/* $OpenBSD: search.c,v 1.18 2005/06/03 15:16:22 cloder Exp $ */ /* * Search commands. @@ -10,6 +10,7 @@ */ #include "def.h" +#include <ctype.h> #ifndef NO_MACRO #include "macro.h" @@ -157,7 +158,9 @@ isearch(int dir) int cbo; int success; int pptr; - + int firstc; + int xcase; + int i; char opat[NPAT]; #ifndef NO_MACRO @@ -275,6 +278,42 @@ isearch(int dir) } is_prompt(dir, pptr < 0, success); break; + case CCHR('W'): + /* add the rest of the current word to the pattern */ + clp = curwp->w_dotp; + cbo = curwp->w_doto; + firstc = 1; + if (dir == SRCH_BACK) { + /* when isearching backwards, cbo is the start of the pattern */ + cbo += pptr; + } + + /* if the search is case insensitive, add to pattern using lowercase */ + xcase = 0; + for (i = 0; pat[i]; i++) + if (ISUPPER(CHARMASK(pat[i]))) + xcase = 1; + + while (cbo < llength(clp)) { + c = lgetc(clp, cbo++); + if ((!firstc && !isalnum(c)) || pptr == NPAT) + break; + + firstc = 0; + if (!xcase && ISUPPER(c)) + c = TOLOWER(c); + + pat[pptr++] = c; + pat[pptr] = '\0'; + /* cursor only moves when isearching forwards */ + if (dir == SRCH_FORW) { + curwp->w_doto = cbo; + curwp->w_flag |= WFMOVE; + update(); + } + } + is_prompt(dir, pptr < 0, success); + break; case CCHR('H'): case CCHR('?'): is_undo(&pptr, &dir); |