diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2001-12-25 13:43:51 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2001-12-25 13:43:51 +0000 |
commit | 3bf20cf505324a545c1a777e1c3fa8621c0c8fbc (patch) | |
tree | 8f8e6e50a9bdfb0d74f3592503bf0566b88592f2 | |
parent | [w3m-dev 02723] cleanup resizing (diff) | |
download | w3m-3bf20cf505324a545c1a777e1c3fa8621c0c8fbc.tar.gz w3m-3bf20cf505324a545c1a777e1c3fa8621c0c8fbc.zip |
[w3m-dev 02726] incremental search
From: Fumitoshi UKAI <ukai@debian.or.jp>
Diffstat (limited to '')
-rw-r--r-- | ChangeLog | 33 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | doc-jp/README.func | 2 | ||||
-rw-r--r-- | doc/README.func | 2 | ||||
-rw-r--r-- | doc/keymap.default | 4 | ||||
-rw-r--r-- | fm.h | 16 | ||||
-rw-r--r-- | funcname.tab | 4 | ||||
-rw-r--r-- | keybind.c | 4 | ||||
-rw-r--r-- | linein.c | 25 | ||||
-rw-r--r-- | main.c | 106 | ||||
-rw-r--r-- | proto.h | 9 |
11 files changed, 190 insertions, 16 deletions
@@ -1,3 +1,34 @@ +2001-12-25 Fumitoshi UKAI <ukai@debian.or.jp> + + * [w3m-dev 02726] incremental search + * NEWS: incremental search + * fm.h (inputLineHist) define by inputLineHistSearch + * fm.h (COPY_BUFPOTISION): added + * fm.h (SAVE_BUFPOSITION): ditto + * fm.h (RESTORE_BUFPOSITION): ditto + * funcname.tab (ISEARCH): added + * funcname.tab (ISEARCH_BACK): added + * keybind.c (GlobalKeymap): C-s = ISEARCH, C-r = ISEARCH_BACK + * linein.c (inputLineHistSearch): renamed from inputLineHist, + new arg incrfunc() for increment search + * linein.c (inputLineHistSearch): add cursorX, cursorY + * main.c (srchcore): remove displayBuffer, onA + * main.c (dispincsrch): added + * main.c (isrch): ditto + * main.c (isrchfor): ditto + * main.c (isrchbak): ditto + * main.c (srch): add displayBuffer, onA + * main.c (srch_nxtprv): ditto + * proto.h (isrchfor): added + * proto.h (isrchbak): ditto + * proto.h (inputLineHistSearch): renamed + * doc/keymap.default (C-r): ISEARCH_BACK + * doc/keymap.default (C-s): ISEARCH + * doc/README.func (ISEARCH): added + * doc/README.func (ISEARCH_BACK): ditto + * doc-jp/README.func (ISEARCH): added + * doc-jp/README.func (ISEARCH_BACK): ditto + 2001-12-25 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp> * [w3m-dev 02723] cleanup resizing @@ -1500,4 +1531,4 @@ * release-0-2-1 * import w3m-0.2.1 -$Id: ChangeLog,v 1.169 2001/12/25 12:41:08 ukai Exp $ +$Id: ChangeLog,v 1.170 2001/12/25 13:43:51 ukai Exp $ @@ -1,5 +1,6 @@ w3m 0.2.4? 0.3? +* incremental search (C-s, C-r) * linux/ia64 support (?) ---------------------------------------------------------------- diff --git a/doc-jp/README.func b/doc-jp/README.func index 6e334cb..5f832ff 100644 --- a/doc-jp/README.func +++ b/doc-jp/README.func @@ -28,6 +28,8 @@ HISTORY URL履歴を表示します INFO 現在の文書に関する情報を表示します INIT_MAILCAP mailcap を再読み込みします(主に local-CGI 用) INTERRUPT 文書の読み込みを中断します +ISEARCH ファイルの末尾にむかってインクリメンタルサーチします +ISEARCH_BACK ファイルの銭湯にむかってインクリメンタルサーチします LEFT 画面全体を1文字左にずらします LINE_BEGIN 行頭に移動します LINE_END 行末に移動します diff --git a/doc/README.func b/doc/README.func index 8e2650c..b992308 100644 --- a/doc/README.func +++ b/doc/README.func @@ -28,6 +28,8 @@ HISTORY View history of URL INFO View info of current document INTERRUPT Stop loading document INIT_MAILCAP Reread mailcap (mainly for local-CGI) +ISEARCH Incremental search forward +ISEARCH_BACK Incremental search backward LEFT Shift screen one column LINE_BEGIN Go to the beginning of line LINE_END Go to the end of line diff --git a/doc/keymap.default b/doc/keymap.default index e692340..2dad146 100644 --- a/doc/keymap.default +++ b/doc/keymap.default @@ -24,8 +24,8 @@ keymap C-l REDRAW keymap C-m GOTO_LINK keymap C-n MOVE_DOWN keymap C-p MOVE_UP -keymap C-r SEARCH_BACK -keymap C-s SEARCH +keymap C-r ISEARCH_BACK +keymap C-s ISEARCH keymap C-u PREV_LINK keymap C-v NEXT_PAGE keymap C-w WRAP_TOGGLE @@ -1,4 +1,4 @@ -/* $Id: fm.h,v 1.30 2001/12/23 14:44:00 ukai Exp $ */ +/* $Id: fm.h,v 1.31 2001/12/25 13:43:51 ukai Exp $ */ /* * w3m: WWW wo Miru utility * @@ -229,6 +229,7 @@ extern int REV_LB[]; * Macros. */ +#define inputLineHist(p,d,f,h) inputLineHistSearch(p,d,f,h,NULL) #define inputLine(p,d,f) inputLineHist(p,d,f,NULL) #define inputStr(p,d) inputLine(p,d,IN_STRING) #define inputStrHist(p,d,h) inputLineHist(p,d,IN_STRING,h) @@ -378,6 +379,19 @@ typedef struct _Buffer { #endif } Buffer; + +#define COPY_BUFPOSITION(dstbuf, srcbuf) {\ + (dstbuf)->topLine = (srcbuf)->topLine; \ + (dstbuf)->currentLine = (srcbuf)->currentLine; \ + (dstbuf)->pos = (srcbuf)->pos; \ + (dstbuf)->cursorX = (srcbuf)->cursorX; \ + (dstbuf)->cursorY = (srcbuf)->cursorY; \ + (dstbuf)->visualpos = (srcbuf)->visualpos; \ + (dstbuf)->currentColumn = (srcbuf)->currentColumn; \ +} +#define SAVE_BUFPOSITION(sbufp) COPY_BUFPOSITION(sbufp, Currentbuf) +#define RESTORE_BUFPOSITION(sbufp) COPY_BUFPOSITION(Currentbuf, sbufp) + #define NO_BUFFER ((Buffer*)1) #define RB_STACK_SIZE 10 diff --git a/funcname.tab b/funcname.tab index a49c2dd..8478572 100644 --- a/funcname.tab +++ b/funcname.tab @@ -1,4 +1,4 @@ -# $Id: funcname.tab,v 1.4 2001/11/20 17:49:23 ukai Exp $ +# $Id: funcname.tab,v 1.5 2001/12/25 13:43:51 ukai Exp $ # macro name function name #---------------------------- @@@ nulcmd @@ -34,6 +34,8 @@ HISTORY ldHist INFO pginfo INIT_MAILCAP initMailcap INTERRUPT susp +ISEARCH isrchfor +ISEARCH_BACK isrchbak LEFT col1L LINE_BEGIN linbeg LINE_END linend @@ -1,4 +1,4 @@ -/* $Id: keybind.c,v 1.4 2001/11/24 02:01:26 ukai Exp $ */ +/* $Id: keybind.c,v 1.5 2001/12/25 13:43:51 ukai Exp $ */ #include "funcname2.h" char GlobalKeymap[128] = { @@ -11,7 +11,7 @@ char GlobalKeymap[128] = { /* C-h C-i C-j C-k C-l C-m C-n C-o */ ldHist, nextA, followA, cooLst, rdrwSc, followA, movD, nulcmd, /* C-p C-q C-r C-s C-t C-u C-v C-w */ - movU, nulcmd, srchbak, srchfor, nulcmd, prevA, pgFore, wrapToggle, + movU, nulcmd, isrchbak, isrchfor, nulcmd, prevA, pgFore, wrapToggle, /* C-x C-y C-z C-[ C-\ C-] C-^ C-_ */ nulcmd, nulcmd, susp, escmap, nulcmd, nulcmd, nulcmd, nulcmd, /* SPC ! " # $ % & ' */ @@ -1,4 +1,4 @@ -/* $Id: linein.c,v 1.17 2001/12/12 17:04:21 ukai Exp $ */ +/* $Id: linein.c,v 1.18 2001/12/25 13:43:51 ukai Exp $ */ #include "fm.h" #include "local.h" #include "myctype.h" @@ -81,12 +81,15 @@ static void ins_kanji(Str tmp); #endif char * -inputLineHist(char *prompt, char *def_str, int flag, Hist *hist) +inputLineHistSearch(char *prompt, char *def_str, int flag, Hist *hist, + int (*incrfunc) (int ch, Str str, short *x, short *y)) { int opos, x, y, lpos, rpos, epos; unsigned char c; char *p; Lineprop mode; + short cursorX = -1; + short cursorY = -1; #ifdef JP_CHARSET Str tmp = Strnew(); #endif /* JP_CHARSET */ @@ -167,7 +170,10 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist) else addStr(strBuf->ptr, strProp, CLen, offset, COLS - opos); clrtoeolx(); - move(LASTLINE, opos + x - offset); + if (cursorX >= 0 && cursorY >= 0) + move(cursorY, cursorX); + else + move(LASTLINE, opos + x - offset); refresh(); next_char: @@ -190,6 +196,8 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist) (DisplayCode == CODE_SJIS ? CODE_SJIS : CODE_EUC), InnerCode); ins_kanji(tmp); + if (incrfunc) + incrfunc(-1, strBuf, &cursorX, &cursorY); } else #endif @@ -226,7 +234,11 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist) cm_disp_next = -1; } else if (!i_quote && c < 0x20) { /* Control code */ - (*InputKeymap[(int)c]) (c); + if (incrfunc == NULL + || (c = incrfunc((int)c, strBuf, &cursorX, &cursorY)) < 0x20) + (*InputKeymap[(int)c]) (c); + if (incrfunc) + incrfunc(-1, strBuf, &cursorX, &cursorY); if (cm_clear) cm_next = FALSE; if (cm_disp_clear) @@ -242,6 +254,8 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist) Strcat_char(tmp, c); tmp = conv_str(tmp, DisplayCode, InnerCode); ins_kanji(tmp); + if (incrfunc) + incrfunc(-1, strBuf, &cursorX, &cursorY); } else if ((c & 0x80) || in_kanji) { /* Kanji 1 */ i_quote = FALSE; @@ -269,6 +283,8 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist) strProp[CPos] = PC_ASCII; CPos++; mode = PC_ASCII; + if (incrfunc) + incrfunc(-1, strBuf, &cursorX, &cursorY); } if (CLen && (flag & IN_CHAR)) break; @@ -279,6 +295,7 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist) if (i_broken) return NULL; + move(LASTLINE, 0); refresh(); p = strBuf->ptr; @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.46 2001/12/25 12:41:08 ukai Exp $ */ +/* $Id: main.c,v 1.47 2001/12/25 13:43:51 ukai Exp $ */ #define MAINPROGRAM #include "fm.h" #include <signal.h> @@ -1341,8 +1341,6 @@ srchcore(char *str, int (*func) (Buffer *, char *)) result = func(Currentbuf, SearchString); signal(SIGINT, prevtrap); term_raw(); - displayBuffer(Currentbuf, B_NORMAL); - onA(); return result; } @@ -1359,6 +1357,90 @@ disp_srchresult(int result, char *prompt, char *str) disp_message(Sprintf("%s%s", prompt, str)->ptr, FALSE); } +static int +dispincsrch(int ch, Str buf, short *x, short *y) +{ + static Buffer sbuf; + static Line *currentLine; + static short pos; + char *str; + int do_next_search = FALSE; + + if (ch == 0 && buf == NULL) { + SAVE_BUFPOSITION(&sbuf); /* search starting point */ + currentLine = sbuf.currentLine; + pos = sbuf.pos; + return -1; + } + + str = buf->ptr; + switch (ch) { + case 022: /* C-r */ + searchRoutine = backwardSearch; + do_next_search = TRUE; + break; + case 023: /* C-s */ + searchRoutine = forwardSearch; + do_next_search = TRUE; + break; + default: + if (ch >= 0) + return ch; /* use InputKeymap */ + } + + if (do_next_search) { + if (*str) { + SAVE_BUFPOSITION(&sbuf); + srchcore(str, searchRoutine); + arrangeCursor(Currentbuf); + if (Currentbuf->currentLine == currentLine + && Currentbuf->pos == pos) { + SAVE_BUFPOSITION(&sbuf); + srchcore(str, searchRoutine); + arrangeCursor(Currentbuf); + } + *x = Currentbuf->cursorX; + *y = Currentbuf->cursorY; + displayBuffer(Currentbuf, B_NORMAL); + return -1; + } + else { + return 020; /* _prev completion? */ + } + } + else if (*str) { + RESTORE_BUFPOSITION(&sbuf); + arrangeCursor(Currentbuf); + srchcore(str, searchRoutine); + arrangeCursor(Currentbuf); + *x = Currentbuf->cursorX; + *y = Currentbuf->cursorY; + currentLine = Currentbuf->currentLine; + pos = Currentbuf->pos; + displayBuffer(Currentbuf, B_NORMAL); + } + else + displayBuffer(Currentbuf, B_NORMAL); + return -1; +} + +void +isrch(int (*func) (Buffer *, char *), char *prompt) +{ + char *str; + Buffer sbuf; + SAVE_BUFPOSITION(&sbuf); + dispincsrch(0, NULL, NULL, NULL); /* initialize incremental search state */ + + searchRoutine = func; + str = inputLineHistSearch(prompt, NULL, IN_STRING, TextHist, dispincsrch); + if (str == NULL) { + RESTORE_BUFPOSITION(&sbuf); + } + displayBuffer(Currentbuf, B_NORMAL); + onA(); +} + void srch(int (*func) (Buffer *, char *), char *prompt) { @@ -1371,24 +1453,40 @@ srch(int (*func) (Buffer *, char *), char *prompt) if (str == NULL) return; result = srchcore(str, func); + displayBuffer(Currentbuf, B_NORMAL); + onA(); disp_srchresult(result, prompt, str); searchRoutine = func; } /* Search regular expression forward */ + void srchfor(void) { srch(forwardSearch, "Forward: "); } +void +isrchfor(void) +{ + isrch(forwardSearch, "I-search: "); +} + /* Search regular expression backward */ + void srchbak(void) { srch(backwardSearch, "Backward: "); } +void +isrchbak(void) +{ + isrch(backwardSearch, "I-search backward: "); +} + static void srch_nxtprv(int reverse) { @@ -1408,6 +1506,8 @@ srch_nxtprv(int reverse) if (searchRoutine == backwardSearch) reverse ^= 1; result = srchcore(SearchString, routine[reverse]); + displayBuffer(Currentbuf, B_NORMAL); + onA(); disp_srchresult(result, (reverse ? "Backward: " : "Forward: "), SearchString); } @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.18 2001/12/25 12:41:08 ukai Exp $ */ +/* $Id: proto.h,v 1.19 2001/12/25 13:43:51 ukai Exp $ */ /* * This file was automatically generated by version 1.7 of cextract. * Manual editing not recommended. @@ -17,7 +17,9 @@ extern void ctrCsrV(void); extern void ctrCsrH(void); extern void rdrwSc(void); extern void srchfor(void); +extern void isrchfor(void); extern void srchbak(void); +extern void isrchbak(void); extern void srchnxt(void); extern void srchprv(void); extern void shiftl(void); @@ -252,7 +254,10 @@ extern void pcmap(void); extern void escmap(void); extern void escbmap(void); extern void escdmap(char c); -extern char *inputLineHist(char *prompt, char *def_str, int flag, Hist *hist); +extern char *inputLineHistSearch(char *prompt, char *def_str, int flag, + Hist *hist, + int (*incfunc) (int ch, Str buf, short *x, + short *y)); #ifdef USE_HISTORY extern Buffer *historyBuffer(Hist *hist); extern void loadHistory(Hist *hist); |