w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit 8a0c789ecb13b78413e9d17482bceb02830dee8c
parent 1259e03a7800a7d64dfbdd0adb4217d3fcb6db10
Author: ukai <ukai>
Date:   Tue, 25 Dec 2001 13:43:51 +0000

[w3m-dev 02726] incremental search
From: Fumitoshi UKAI  <ukai@debian.or.jp>

Diffstat:
MChangeLog | 31+++++++++++++++++++++++++++++++
MNEWS | 1+
Mdoc-jp/README.func | 2++
Mdoc/README.func | 2++
Mdoc/keymap.default | 4++--
Mfm.h | 14++++++++++++++
Mfuncname.tab | 2++
Mkeybind.c | 2+-
Mlinein.c | 23++++++++++++++++++++---
Mmain.c | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mproto.h | 7++++++-
11 files changed, 183 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -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 diff --git a/NEWS b/NEWS @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/fm.h b/fm.h @@ -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 @@ -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 diff --git a/keybind.c b/keybind.c @@ -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 ! " # $ % & ' */ diff --git a/linein.c b/linein.c @@ -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; diff --git a/main.c b/main.c @@ -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); } diff --git a/proto.h b/proto.h @@ -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);