[w3m-dev 02726] incremental search

From: Fumitoshi UKAI  <ukai@debian.or.jp>
This commit is contained in:
Fumitoshi UKAI
2001-12-25 13:43:51 +00:00
parent bc13c3bffe
commit 3bf20cf505
11 changed files with 190 additions and 16 deletions
+32 -1
View File
@@ -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> 2001-12-25 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 02723] cleanup resizing * [w3m-dev 02723] cleanup resizing
@@ -1500,4 +1531,4 @@
* release-0-2-1 * release-0-2-1
* import w3m-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
View File
@@ -1,5 +1,6 @@
w3m 0.2.4? 0.3? w3m 0.2.4? 0.3?
* incremental search (C-s, C-r)
* linux/ia64 support (?) * linux/ia64 support (?)
---------------------------------------------------------------- ----------------------------------------------------------------
+2
View File
@@ -28,6 +28,8 @@ HISTORY URL
INFO 現在の文書に関する情報を表示します INFO 現在の文書に関する情報を表示します
INIT_MAILCAP mailcap を再読み込みします(主に local-CGI 用) INIT_MAILCAP mailcap を再読み込みします(主に local-CGI 用)
INTERRUPT 文書の読み込みを中断します INTERRUPT 文書の読み込みを中断します
ISEARCH ファイルの末尾にむかってインクリメンタルサーチします
ISEARCH_BACK ファイルの銭湯にむかってインクリメンタルサーチします
LEFT 画面全体を1文字左にずらします LEFT 画面全体を1文字左にずらします
LINE_BEGIN 行頭に移動します LINE_BEGIN 行頭に移動します
LINE_END 行末に移動します LINE_END 行末に移動します
+2
View File
@@ -28,6 +28,8 @@ HISTORY View history of URL
INFO View info of current document INFO View info of current document
INTERRUPT Stop loading document INTERRUPT Stop loading document
INIT_MAILCAP Reread mailcap (mainly for local-CGI) INIT_MAILCAP Reread mailcap (mainly for local-CGI)
ISEARCH Incremental search forward
ISEARCH_BACK Incremental search backward
LEFT Shift screen one column LEFT Shift screen one column
LINE_BEGIN Go to the beginning of line LINE_BEGIN Go to the beginning of line
LINE_END Go to the end of line LINE_END Go to the end of line
+2 -2
View File
@@ -24,8 +24,8 @@ keymap C-l REDRAW
keymap C-m GOTO_LINK keymap C-m GOTO_LINK
keymap C-n MOVE_DOWN keymap C-n MOVE_DOWN
keymap C-p MOVE_UP keymap C-p MOVE_UP
keymap C-r SEARCH_BACK keymap C-r ISEARCH_BACK
keymap C-s SEARCH keymap C-s ISEARCH
keymap C-u PREV_LINK keymap C-u PREV_LINK
keymap C-v NEXT_PAGE keymap C-v NEXT_PAGE
keymap C-w WRAP_TOGGLE keymap C-w WRAP_TOGGLE
+15 -1
View File
@@ -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 * w3m: WWW wo Miru utility
* *
@@ -229,6 +229,7 @@ extern int REV_LB[];
* Macros. * Macros.
*/ */
#define inputLineHist(p,d,f,h) inputLineHistSearch(p,d,f,h,NULL)
#define inputLine(p,d,f) inputLineHist(p,d,f,NULL) #define inputLine(p,d,f) inputLineHist(p,d,f,NULL)
#define inputStr(p,d) inputLine(p,d,IN_STRING) #define inputStr(p,d) inputLine(p,d,IN_STRING)
#define inputStrHist(p,d,h) inputLineHist(p,d,IN_STRING,h) #define inputStrHist(p,d,h) inputLineHist(p,d,IN_STRING,h)
@@ -378,6 +379,19 @@ typedef struct _Buffer {
#endif #endif
} Buffer; } 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 NO_BUFFER ((Buffer*)1)
#define RB_STACK_SIZE 10 #define RB_STACK_SIZE 10
+3 -1
View File
@@ -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 # macro name function name
#---------------------------- #----------------------------
@@@ nulcmd @@@ nulcmd
@@ -34,6 +34,8 @@ HISTORY ldHist
INFO pginfo INFO pginfo
INIT_MAILCAP initMailcap INIT_MAILCAP initMailcap
INTERRUPT susp INTERRUPT susp
ISEARCH isrchfor
ISEARCH_BACK isrchbak
LEFT col1L LEFT col1L
LINE_BEGIN linbeg LINE_BEGIN linbeg
LINE_END linend LINE_END linend
+2 -2
View File
@@ -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" #include "funcname2.h"
char GlobalKeymap[128] = { 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 */ /* C-h C-i C-j C-k C-l C-m C-n C-o */
ldHist, nextA, followA, cooLst, rdrwSc, followA, movD, nulcmd, ldHist, nextA, followA, cooLst, rdrwSc, followA, movD, nulcmd,
/* C-p C-q C-r C-s C-t C-u C-v C-w */ /* 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-_ */ /* C-x C-y C-z C-[ C-\ C-] C-^ C-_ */
nulcmd, nulcmd, susp, escmap, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, susp, escmap, nulcmd, nulcmd, nulcmd, nulcmd,
/* SPC ! " # $ % & ' */ /* SPC ! " # $ % & ' */
+21 -4
View File
@@ -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 "fm.h"
#include "local.h" #include "local.h"
#include "myctype.h" #include "myctype.h"
@@ -81,12 +81,15 @@ static void ins_kanji(Str tmp);
#endif #endif
char * 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; int opos, x, y, lpos, rpos, epos;
unsigned char c; unsigned char c;
char *p; char *p;
Lineprop mode; Lineprop mode;
short cursorX = -1;
short cursorY = -1;
#ifdef JP_CHARSET #ifdef JP_CHARSET
Str tmp = Strnew(); Str tmp = Strnew();
#endif /* JP_CHARSET */ #endif /* JP_CHARSET */
@@ -167,7 +170,10 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist)
else else
addStr(strBuf->ptr, strProp, CLen, offset, COLS - opos); addStr(strBuf->ptr, strProp, CLen, offset, COLS - opos);
clrtoeolx(); clrtoeolx();
move(LASTLINE, opos + x - offset); if (cursorX >= 0 && cursorY >= 0)
move(cursorY, cursorX);
else
move(LASTLINE, opos + x - offset);
refresh(); refresh();
next_char: next_char:
@@ -190,6 +196,8 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist)
(DisplayCode == CODE_SJIS ? CODE_SJIS : CODE_EUC), (DisplayCode == CODE_SJIS ? CODE_SJIS : CODE_EUC),
InnerCode); InnerCode);
ins_kanji(tmp); ins_kanji(tmp);
if (incrfunc)
incrfunc(-1, strBuf, &cursorX, &cursorY);
} }
else else
#endif #endif
@@ -226,7 +234,11 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist)
cm_disp_next = -1; cm_disp_next = -1;
} }
else if (!i_quote && c < 0x20) { /* Control code */ 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) if (cm_clear)
cm_next = FALSE; cm_next = FALSE;
if (cm_disp_clear) if (cm_disp_clear)
@@ -242,6 +254,8 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist)
Strcat_char(tmp, c); Strcat_char(tmp, c);
tmp = conv_str(tmp, DisplayCode, InnerCode); tmp = conv_str(tmp, DisplayCode, InnerCode);
ins_kanji(tmp); ins_kanji(tmp);
if (incrfunc)
incrfunc(-1, strBuf, &cursorX, &cursorY);
} }
else if ((c & 0x80) || in_kanji) { /* Kanji 1 */ else if ((c & 0x80) || in_kanji) { /* Kanji 1 */
i_quote = FALSE; i_quote = FALSE;
@@ -269,6 +283,8 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist)
strProp[CPos] = PC_ASCII; strProp[CPos] = PC_ASCII;
CPos++; CPos++;
mode = PC_ASCII; mode = PC_ASCII;
if (incrfunc)
incrfunc(-1, strBuf, &cursorX, &cursorY);
} }
if (CLen && (flag & IN_CHAR)) if (CLen && (flag & IN_CHAR))
break; break;
@@ -279,6 +295,7 @@ inputLineHist(char *prompt, char *def_str, int flag, Hist *hist)
if (i_broken) if (i_broken)
return NULL; return NULL;
move(LASTLINE, 0); move(LASTLINE, 0);
refresh(); refresh();
p = strBuf->ptr; p = strBuf->ptr;
+103 -3
View File
@@ -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 #define MAINPROGRAM
#include "fm.h" #include "fm.h"
#include <signal.h> #include <signal.h>
@@ -1341,8 +1341,6 @@ srchcore(char *str, int (*func) (Buffer *, char *))
result = func(Currentbuf, SearchString); result = func(Currentbuf, SearchString);
signal(SIGINT, prevtrap); signal(SIGINT, prevtrap);
term_raw(); term_raw();
displayBuffer(Currentbuf, B_NORMAL);
onA();
return result; return result;
} }
@@ -1359,6 +1357,90 @@ disp_srchresult(int result, char *prompt, char *str)
disp_message(Sprintf("%s%s", prompt, str)->ptr, FALSE); 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 void
srch(int (*func) (Buffer *, char *), char *prompt) srch(int (*func) (Buffer *, char *), char *prompt)
{ {
@@ -1371,24 +1453,40 @@ srch(int (*func) (Buffer *, char *), char *prompt)
if (str == NULL) if (str == NULL)
return; return;
result = srchcore(str, func); result = srchcore(str, func);
displayBuffer(Currentbuf, B_NORMAL);
onA();
disp_srchresult(result, prompt, str); disp_srchresult(result, prompt, str);
searchRoutine = func; searchRoutine = func;
} }
/* Search regular expression forward */ /* Search regular expression forward */
void void
srchfor(void) srchfor(void)
{ {
srch(forwardSearch, "Forward: "); srch(forwardSearch, "Forward: ");
} }
void
isrchfor(void)
{
isrch(forwardSearch, "I-search: ");
}
/* Search regular expression backward */ /* Search regular expression backward */
void void
srchbak(void) srchbak(void)
{ {
srch(backwardSearch, "Backward: "); srch(backwardSearch, "Backward: ");
} }
void
isrchbak(void)
{
isrch(backwardSearch, "I-search backward: ");
}
static void static void
srch_nxtprv(int reverse) srch_nxtprv(int reverse)
{ {
@@ -1408,6 +1506,8 @@ srch_nxtprv(int reverse)
if (searchRoutine == backwardSearch) if (searchRoutine == backwardSearch)
reverse ^= 1; reverse ^= 1;
result = srchcore(SearchString, routine[reverse]); result = srchcore(SearchString, routine[reverse]);
displayBuffer(Currentbuf, B_NORMAL);
onA();
disp_srchresult(result, (reverse ? "Backward: " : "Forward: "), disp_srchresult(result, (reverse ? "Backward: " : "Forward: "),
SearchString); SearchString);
} }
+7 -2
View File
@@ -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. * This file was automatically generated by version 1.7 of cextract.
* Manual editing not recommended. * Manual editing not recommended.
@@ -17,7 +17,9 @@ extern void ctrCsrV(void);
extern void ctrCsrH(void); extern void ctrCsrH(void);
extern void rdrwSc(void); extern void rdrwSc(void);
extern void srchfor(void); extern void srchfor(void);
extern void isrchfor(void);
extern void srchbak(void); extern void srchbak(void);
extern void isrchbak(void);
extern void srchnxt(void); extern void srchnxt(void);
extern void srchprv(void); extern void srchprv(void);
extern void shiftl(void); extern void shiftl(void);
@@ -252,7 +254,10 @@ extern void pcmap(void);
extern void escmap(void); extern void escmap(void);
extern void escbmap(void); extern void escbmap(void);
extern void escdmap(char c); 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 #ifdef USE_HISTORY
extern Buffer *historyBuffer(Hist *hist); extern Buffer *historyBuffer(Hist *hist);
extern void loadHistory(Hist *hist); extern void loadHistory(Hist *hist);