w3m

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

commit c1a003b15c66f43602f0c8689cb3e101017bb447
parent ad988103aab08e771aba2158e902de3eb81b7c45
Author: ukai <ukai>
Date:   Thu,  5 Sep 2002 15:43:21 +0000

[w3m-dev 03292] Re: load file at cursor
* anchor.c (reAnchorPos): added
	(reAnchorWord): added
	(reAnchorAny): rewrite to use reAnchorPos()
* funcname.tab (MARK_WORD): added
* keybind.c (;) MARK_WORD
* main.c (getCurWord): added
	(chkWORD): added
	(is_wordchar): added
	(getCurWord): added
	(GetWord): rewrite to use getCurWord()
* proto.h (chkWORD): added
	(reAnchorWord): added
* doc/README.func: add MARK_WORD
* doc/keymap.default: add MARK_WORD
* doc-jp/README.func: add MARK_WORD
* doc-jp/keymap.default: add MARK_WORD
* NEWS: add MARK_WORD
From: Fumitoshi UKAI  <ukai@debian.or.jp>

Diffstat:
MChangeLog | 21+++++++++++++++++++++
MNEWS | 1+
Manchor.c | 48+++++++++++++++++++++++++++++++-----------------
Mdoc-jp/README.func | 1+
Mdoc-jp/keymap.default | 1+
Mdoc/README.func | 1+
Mdoc/keymap.default | 1+
Mfuncname.tab | 1+
Mkeybind.c | 2+-
Mmain.c | 56+++++++++++++++++++++++++++++++++++++++++++++++---------
Mproto.h | 2++
11 files changed, 108 insertions(+), 27 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,24 @@ +2002-09-06 Fumitoshi UKAI <ukai@debian.or.jp> + + * [w3m-dev 03292] Re: load file at cursor + * anchor.c (reAnchorPos): added + (reAnchorWord): added + (reAnchorAny): rewrite to use reAnchorPos() + * funcname.tab (MARK_WORD): added + * keybind.c (;) MARK_WORD + * main.c (getCurWord): added + (chkWORD): added + (is_wordchar): added + (getCurWord): added + (GetWord): rewrite to use getCurWord() + * proto.h (chkWORD): added + (reAnchorWord): added + * doc/README.func: add MARK_WORD + * doc/keymap.default: add MARK_WORD + * doc-jp/README.func: add MARK_WORD + * doc-jp/keymap.default: add MARK_WORD + * NEWS: add MARK_WORD + 2002-08-28 Kiyokazu SUTO <suto@ks-and-ks.ne.jp> * [w3m-dev 03291] parsetagx.c:toNumber() diff --git a/NEWS b/NEWS @@ -1,5 +1,6 @@ w3m 0.4? +* func: MARK_WORD * rc: imgsize: obsoleted * w3m-img for framebuffer merged diff --git a/anchor.c b/anchor.c @@ -277,6 +277,36 @@ reseq_anchor(Buffer *buf) reseq_anchor0(buf->formitem, seqmap); } +static char * +reAnchorPos(Buffer *buf, Line *l, char *p1, char *p2, + Anchor *(*anchorproc) (Buffer *, char *, char *, int, int)) +{ + Anchor *a; + int spos, epos; + int i; + + spos = p1 - l->lineBuf; + epos = p2 - l->lineBuf; + for (i = spos; i < epos; i++) { + if (l->propBuf[i] & (PE_ANCHOR | PE_FORM)) + return p2; + } + a = anchorproc(buf, p1, p2, l->linenumber, p1 - l->lineBuf); + a->end.line = l->linenumber; + a->end.pos = epos; + a->hseq = -2; + for (i = a->start.pos; i < a->end.pos; i++) + l->propBuf[i] |= PE_ANCHOR; + return p2; +} + +void +reAnchorWord(Buffer *buf, Line *l, int spos, int epos) +{ + reAnchorPos(buf, l, &l->lineBuf[spos], &l->lineBuf[epos], _put_anchor_all); + reseq_anchor(buf); +} + /* search regexp and register them as anchors */ /* returns error message if any */ static char * @@ -285,9 +315,6 @@ reAnchorAny(Buffer *buf, char *re, { Line *l; char *p, *p1, *p2; - Anchor *a; - int i; - int spos, epos; if (re == NULL || *re == '\0') { return NULL; @@ -302,20 +329,7 @@ reAnchorAny(Buffer *buf, char *re, for (;;) { if (regexMatch(p, &l->lineBuf[l->len] - p, p == l->lineBuf) == 1) { matchedPosition(&p1, &p2); - spos = p1 - l->lineBuf; - epos = p2 - l->lineBuf; - for (i = spos; i < epos; i++) { - if (l->propBuf[i] & (PE_ANCHOR | PE_FORM)) - goto _next; - } - a = anchorproc(buf, p1, p2, l->linenumber, p1 - l->lineBuf); - a->end.line = l->linenumber; - a->end.pos = epos; - a->hseq = -2; - for (i = a->start.pos; i < a->end.pos; i++) - l->propBuf[i] |= PE_ANCHOR; - _next: - p = p2; + p = reAnchorPos(buf, l, p1, p2, anchorproc); } else break; diff --git a/doc-jp/README.func b/doc-jp/README.func @@ -45,6 +45,7 @@ MAIN_MENU MARK マークを設定/解除します MARK_MID Message-ID風の文字列を,news:のリンクにします MARK_URL URL風の文字列をリンクにします +MARK_WORD カーソルのある語をリンクにします MENU メニューを立ち上げます MOUSE_TOGGLE マウスの有効/無効をトグルする MOVE_DOWN カーソルを下に移動します(改ページ時には半ページスクロール) diff --git a/doc-jp/keymap.default b/doc-jp/keymap.default @@ -40,6 +40,7 @@ keymap , LEFT keymap . RIGHT keymap / SEARCH keymap : MARK_URL +keymap ; MARK_WORD keymap < SHIFT_LEFT keymap = INFO keymap > SHIFT_RIGHT diff --git a/doc/README.func b/doc/README.func @@ -45,6 +45,7 @@ MAIN_MENU Popup menu MARK Set/unset mark MARK_MID Mark Message-ID-like strings as anchors MARK_URL Mark URL-like strings as anchors +MARK_WORD Mark current word as anchor MENU Popup menu MOUSE_TOGGLE Toggle activity of mouse MOVE_DOWN Move cursor down (a half screen scroll at the end of screen) diff --git a/doc/keymap.default b/doc/keymap.default @@ -40,6 +40,7 @@ keymap , LEFT keymap . RIGHT keymap / SEARCH keymap : MARK_URL +keymap ; MARK_WORD keymap < SHIFT_LEFT keymap = INFO keymap > SHIFT_RIGHT diff --git a/funcname.tab b/funcname.tab @@ -50,6 +50,7 @@ MAIN_MENU mainMn MARK _mark MARK_MID chkNMID MARK_URL chkURL +MARK_WORD chkWORD MENU mainMn MOUSE mouse MOUSE_TOGGLE msToggle diff --git a/keybind.c b/keybind.c @@ -21,7 +21,7 @@ char GlobalKeymap[128] = { /* 0 1 2 3 4 5 6 7 */ nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, nulcmd, /* 8 9 : ; < = > ? */ - nulcmd, nulcmd, chkURL, nulcmd, shiftl, pginfo, shiftr, srchbak, + nulcmd, nulcmd, chkURL, chkWORD, shiftl, pginfo, shiftr, srchbak, /* @ A B C D E F G */ readsh, nulcmd, backBf, nulcmd, nulcmd, editBf, rFrame, goLineL, /* H I J K L M N O */ diff --git a/main.c b/main.c @@ -75,6 +75,8 @@ static void keyPressEventProc(int c); int show_params_p = 0; void show_params(FILE * fp); +static char *getCurWord(Buffer *buf, int *spos, int *epos, const char *badchars); + static int display_ok = FALSE; static void dump_source(Buffer *); static void dump_head(Buffer *); @@ -4381,6 +4383,18 @@ chkURL(void) displayBuffer(Currentbuf, B_FORCE_REDRAW); } +void +chkWORD(void) +{ + char *p; + int spos, epos; + p = getCurWord(Currentbuf, &spos, &epos, ":\"\'`<>"); + if (p == NULL) + return; + reAnchorWord(Currentbuf, Currentbuf->currentLine, spos, epos); + displayBuffer(Currentbuf, B_FORCE_REDRAW); +} + #ifdef USE_NNTP /* mark Message-ID-like patterns as NEWS anchors */ void @@ -4802,28 +4816,52 @@ wrapToggle(void) } } +static int +is_wordchar(int c, const char *badchars) +{ + if (badchars) + return !(IS_SPACE(c) || strchr(badchars, c)); + else + return IS_ALPHA(c); +} + static char * -GetWord(Buffer *buf) +getCurWord(Buffer *buf, int *spos, int *epos, const char *badchars) { + char *p; Line *l = buf->currentLine; - char *lb; int b, e; + *spos = 0; + *epos = 0; if (l == NULL) return NULL; - lb = l->lineBuf; - + p = l->lineBuf; e = buf->pos; - while (e > 0 && !IS_ALPHA(lb[e])) + while (e > 0 && !is_wordchar(p[e], badchars)) e--; - if (!IS_ALPHA(lb[e])) + if (!is_wordchar(p[e], badchars)) return NULL; b = e; - while (b > 0 && IS_ALPHA(lb[b - 1])) + while (b > 0 && is_wordchar(p[b-1], badchars)) b--; - while (e < l->len && IS_ALPHA(lb[e])) + while (e < l->len && is_wordchar(p[e], badchars)) e++; - return Strnew_charp_n(&lb[b], e - b)->ptr; + *spos = b; + *epos = e; + return &p[b]; +} + +static char * +GetWord(Buffer *buf) +{ + int b, e; + char *p; + + if ((p = getCurWord(buf, &b, &e, 0)) != NULL) { + return Strnew_charp_n(p, e - b)->ptr; + } + return NULL; } #ifdef USE_DICT diff --git a/proto.h b/proto.h @@ -92,6 +92,7 @@ extern void vwSrc(void); extern void reload(void); extern void chkURL(void); extern void chkURLBuffer(Buffer *buf); +extern void chkWORD(void); #ifdef USE_NNTP extern void chkNMID(void); extern void chkNMIDBuffer(Buffer *buf); @@ -486,6 +487,7 @@ extern Anchor *retrieveCurrentImg(Buffer *buf); extern Anchor *retrieveCurrentForm(Buffer *buf); extern Anchor *searchAnchor(AnchorList *al, char *str); extern Anchor *searchURLLabel(Buffer *buf, char *url); +extern void reAnchorWord(Buffer *buf, Line *l, int spos, int epos); extern char *reAnchor(Buffer *buf, char *re); #ifdef USE_NNTP extern char *reAnchorNews(Buffer *buf, char *re);