commit b6d48210807f8b245adc9088246b913eb4e8b8f7
parent d2940728a5686db6ba0267e1aa0a7d8fdd9ebef2
Author: ukai <ukai>
Date: Wed, 26 Dec 2001 18:17:57 +0000
[w3m-dev 02748] cleanup code for restoring cursor position
From: Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
Diffstat:
M | ChangeLog | | | 29 | +++++++++++++++++++++++++++++ |
M | buffer.c | | | 29 | +++++++---------------------- |
M | display.c | | | 28 | ++++++++++++++++------------ |
M | fm.h | | | 2 | ++ |
M | main.c | | | 131 | ++++++++++++++++++++++++++++++++++++------------------------------------------- |
M | proto.h | | | 3 | +++ |
6 files changed, 117 insertions(+), 105 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,32 @@
+2001-12-27 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
+
+ * [w3m-dev 02748] cleanup code for restoring cursor position
+ * buffer.c (reshapeBuffer): delete top, linenum, cursorY, pos,
+ currentColumn, formitem
+ * buffer.c (reshapeBuffer): add sbuf and
+ use copyBuffer(), restorePosition()
+ * buffer.c (reshapeBuffer): use chkURLBuffer(), chkNMIDBuffer()
+ * display.c (in_check_url): deleted
+ * display.c (displayBuffer): ditto
+ * display.c (displayBuffer): s/Currentbuf/buf/
+ * display.c (arrangeLine): ditto
+ * display.c (restorePosition): added
+ * fm.h (TOP_LINENUMBER): added
+ * fm.h (CUR_LINENUMBER): added
+ * main.c (editBf): delete type, top, linenum, cursorY, pos,
+ currentColumn
+ * main.c (editBf): add sbuf and use copyBuffer(), restorePosition()
+ * main.c (reload): delete type, top, linenum, cursorY, pos,
+ currentColumn
+ * main.c (reload): add sbuf and use copyBuffer(), restorePosition()
+ * main.c (chkURLBuffer): added
+ * main.c (chkURL): chkRULBuffer on Currentbuf
+ * main.c (chkNMIDBuffer): added
+ * main.c (chkNMID): chkNMIDBuffer on Currentbuf
+ * proto.h (chkURLBuffer): added
+ * proto.h (chkNMIDBuffer): added
+ * proto.h (restorePosition): added
+
2001-12-27 "OMAE, jun" <jun-o@dai.meta.ne.jp>
* [w3m-dev 02735]
diff --git a/buffer.c b/buffer.c
@@ -487,8 +487,7 @@ void
reshapeBuffer(Buffer *buf)
{
URLFile f;
- int top, linenum, cursorY, pos, currentColumn;
- AnchorList *formitem;
+ Buffer sbuf;
if (buf->sourcefile == NULL)
return;
@@ -498,24 +497,13 @@ reshapeBuffer(Buffer *buf)
if (f.stream == NULL)
return;
- if (buf->firstLine == NULL) {
- top = 1;
- linenum = 1;
- }
- else {
- top = buf->topLine->linenumber;
- linenum = buf->currentLine->linenumber;
- }
- cursorY = buf->cursorY;
- pos = buf->pos;
- currentColumn = buf->currentColumn;
+ copyBuffer(&sbuf, buf);
clearBuffer(buf);
while (buf->frameset) {
deleteFrameSet(buf->frameset);
buf->frameset = popFrameTree(&(buf->frameQ));
}
- formitem = buf->formitem;
buf->href = NULL;
buf->name = NULL;
buf->img = NULL;
@@ -537,18 +525,15 @@ reshapeBuffer(Buffer *buf)
#endif
buf->height = LASTLINE + 1;
- buf->topLine = lineSkip(buf, buf->topLine, top - 1, FALSE);
- gotoLine(buf, linenum);
- buf->pos = pos;
- buf->currentColumn = currentColumn;
- arrangeCursor(buf);
+ if (buf->firstLine)
+ restorePosition(buf, &sbuf);
if (buf->check_url & CHK_URL)
- chkURL();
+ chkURLBuffer(buf);
#ifdef USE_NNTP
if (buf->check_url & CHK_NMID)
- chkNMID();
+ chkNMIDBuffer(buf);
#endif
- formResetBuffer(buf, formitem);
+ formResetBuffer(buf, sbuf.formitem);
}
/* shallow copy */
diff --git a/display.c b/display.c
@@ -188,8 +188,6 @@ static Linecolor color_mode = 0;
static Buffer *save_current_buf = NULL;
#endif
-int in_check_url = FALSE;
-
char *delayed_msg = NULL;
void
@@ -198,8 +196,6 @@ displayBuffer(Buffer *buf, int mode)
Str msg;
Anchor *aa = NULL;
- if (in_check_url)
- return;
if (buf->topLine == NULL && readBufferCache(buf) == 0) { /* clear_buffer */
mode = B_FORCE_REDRAW;
}
@@ -209,11 +205,8 @@ displayBuffer(Buffer *buf, int mode)
if (buf->height == 0)
buf->height = LASTLINE + 1;
if (buf->width != INIT_BUFFER_WIDTH && buf->type
- && !strcmp(buf->type, "text/html")) {
- in_check_url = TRUE;
+ && !strcmp(buf->type, "text/html"))
reshapeBuffer(buf);
- in_check_url = FALSE;
- }
if (showLineNum) {
if (buf->lastLine && buf->lastLine->real_linenumber > 0)
buf->rootX = (int)(log(buf->lastLine->real_linenumber + 0.1)
@@ -327,9 +320,9 @@ displayBuffer(Buffer *buf, int mode)
standend();
refresh();
#ifdef USE_BUFINFO
- if (Currentbuf != save_current_buf) {
+ if (buf != save_current_buf) {
saveBufferInfo();
- save_current_buf = Currentbuf;
+ save_current_buf = buf;
}
#endif
}
@@ -1056,10 +1049,10 @@ arrangeLine(Buffer *buf)
buf->cursorX = cpos;
buf->pos = i;
}
- else if (Currentbuf->currentLine->len > i) {
+ else if (buf->currentLine->len > i) {
int delta = 1;
#ifdef JP_CHARSET
- if (Currentbuf->currentLine->len > i + 1 &&
+ if (buf->currentLine->len > i + 1 &&
CharType(buf->currentLine->propBuf[i + 1]) == PC_KANJI2)
delta = 2;
#endif
@@ -1105,6 +1098,17 @@ cursorXY(Buffer *buf, int x, int y)
}
}
+void
+restorePosition(Buffer *buf, Buffer *orig)
+{
+ buf->topLine = lineSkip(buf, buf->firstLine, TOP_LINENUMBER(orig) - 1,
+ FALSE);
+ gotoLine(buf, CUR_LINENUMBER(orig));
+ buf->pos = orig->pos;
+ buf->currentColumn = orig->currentColumn;
+ arrangeCursor(buf);
+}
+
/* Local Variables: */
/* c-basic-offset: 4 */
/* tab-width: 8 */
diff --git a/fm.h b/fm.h
@@ -391,6 +391,8 @@ typedef struct _Buffer {
}
#define SAVE_BUFPOSITION(sbufp) COPY_BUFPOSITION(sbufp, Currentbuf)
#define RESTORE_BUFPOSITION(sbufp) COPY_BUFPOSITION(Currentbuf, sbufp)
+#define TOP_LINENUMBER(buf) ((buf)->topLine ? (buf)->topLine->linenumber : 1)
+#define CUR_LINENUMBER(buf) ((buf)->currentLine ? (buf)->currentLine->linenumber : 1)
#define NO_BUFFER ((Buffer*)1)
diff --git a/main.c b/main.c
@@ -2222,9 +2222,10 @@ void
editBf(void)
{
char *fn = Currentbuf->filename;
- char *type = Currentbuf->type;
- int top, linenum, cursorY, pos, currentColumn;
- Buffer *buf, *fbuf = NULL;
+ Buffer *buf, *fbuf = NULL, sbuf;
+#ifdef JP_CHARSET
+ char old_code;
+#endif
Str cmd;
if (fn == NULL || Currentbuf->pagerSource != NULL || /* Behaving as a pager */
@@ -2236,17 +2237,7 @@ editBf(void)
}
if (Currentbuf->frameset != NULL)
fbuf = Currentbuf->linkBuffer[LB_FRAME];
- if (Currentbuf->firstLine == NULL) {
- top = 1;
- linenum = 1;
- }
- else {
- top = Currentbuf->topLine->linenumber;
- linenum = Currentbuf->currentLine->linenumber;
- }
- cursorY = Currentbuf->cursorY;
- pos = Currentbuf->pos;
- currentColumn = Currentbuf->currentColumn;
+ copyBuffer(&sbuf, Currentbuf);
if (Currentbuf->edit) {
cmd = unquote_mailcap(Currentbuf->edit,
Currentbuf->real_type,
@@ -2255,6 +2246,7 @@ editBf(void)
}
else {
char *file = shell_quote(fn);
+ int linenum = CUR_LINENUMBER(Currentbuf);
if (strcasestr(Editor, "%s")) {
if (strcasestr(Editor, "%d"))
cmd = Sprintf(Editor, linenum, file);
@@ -2274,11 +2266,20 @@ editBf(void)
fmTerm();
system(cmd->ptr);
fmInit();
+
+#ifdef JP_CHARSET
+ old_code = DocumentCode;
+ DocumentCode = Currentbuf->document_code;
+#endif
SearchHeader = Currentbuf->search_header;
DefaultType = Currentbuf->real_type;
buf = loadGeneralFile(file_to_url(fn), NULL, NO_REFERER, 0, NULL);
+#ifdef JP_CHARSET
+ DocumentCode = old_code;
+#endif
SearchHeader = FALSE;
DefaultType = NULL;
+
if (buf == NULL) {
disp_err_message("Re-loading failed", FALSE);
buf = nullBuffer();
@@ -2286,29 +2287,21 @@ editBf(void)
else if (buf == NO_BUFFER) {
buf = nullBuffer();
}
- buf->search_header = Currentbuf->search_header;
if (fbuf != NULL)
Firstbuf = deleteBuffer(Firstbuf, fbuf);
repBuffer(Currentbuf, buf);
- if ((type != NULL) && (buf->type != NULL) &&
+ if ((buf->type != NULL) && (sbuf.type != NULL) &&
((!strcasecmp(buf->type, "text/plain") &&
- !strcasecmp(type, "text/html")) ||
+ !strcasecmp(sbuf.type, "text/html")) ||
(!strcasecmp(buf->type, "text/html") &&
- !strcasecmp(type, "text/plain")))) {
+ !strcasecmp(sbuf.type, "text/plain")))) {
vwSrc();
if (Currentbuf != buf)
Firstbuf = deleteBuffer(Firstbuf, buf);
}
- if (Currentbuf->firstLine == NULL) {
- displayBuffer(Currentbuf, B_FORCE_REDRAW);
- return;
- }
- Currentbuf->topLine =
- lineSkip(Currentbuf, Currentbuf->topLine, top - 1, FALSE);
- gotoLine(Currentbuf, linenum);
- Currentbuf->pos = pos;
- Currentbuf->currentColumn = currentColumn;
- arrangeCursor(Currentbuf);
+ Currentbuf->search_header = sbuf.search_header;
+ if (Currentbuf->firstLine)
+ restorePosition(Currentbuf, &sbuf);
displayBuffer(Currentbuf, B_FORCE_REDRAW);
}
@@ -4101,10 +4094,11 @@ vwSrc(void)
void
reload(void)
{
- Buffer *buf, *fbuf = NULL;
- char *type = Currentbuf->type;
+ Buffer *buf, *fbuf = NULL, sbuf;
+#ifdef JP_CHARSET
+ char old_code;
+#endif
Str url;
- int top, linenum, cursorY, pos, currentColumn;
FormList *request;
int multipart;
@@ -4118,17 +4112,7 @@ reload(void)
disp_err_message("Can't reload stdin", TRUE);
return;
}
- if (Currentbuf->firstLine == NULL) {
- top = 1;
- linenum = 1;
- }
- else {
- top = Currentbuf->topLine->linenumber;
- linenum = Currentbuf->currentLine->linenumber;
- }
- cursorY = Currentbuf->cursorY;
- pos = Currentbuf->pos;
- currentColumn = Currentbuf->currentColumn;
+ copyBuffer(&sbuf, Currentbuf);
if (Currentbuf->bufferprop & BP_FRAME &&
(fbuf = Currentbuf->linkBuffer[LB_N_FRAME])) {
if (fmInitialized) {
@@ -4149,14 +4133,8 @@ reload(void)
buf->linkBuffer[LB_N_FRAME] = fbuf;
pushBuffer(buf);
Currentbuf = buf;
- if (Currentbuf->firstLine == NULL) {
- displayBuffer(Currentbuf, B_FORCE_REDRAW);
- return;
- }
- gotoLine(Currentbuf, linenum);
- Currentbuf->pos = pos;
- Currentbuf->currentColumn = currentColumn;
- arrangeCursor(Currentbuf);
+ if (Currentbuf->firstLine)
+ restorePosition(Currentbuf, &sbuf);
displayBuffer(Currentbuf, B_FORCE_REDRAW);
return;
}
@@ -4181,11 +4159,20 @@ reload(void)
url = parsedURL2Str(&Currentbuf->currentURL);
message("Reloading...", 0, 0);
refresh();
+
+#ifdef JP_CHARSET
+ old_code = DocumentCode;
+ DocumentCode = Currentbuf->document_code;
+#endif
SearchHeader = Currentbuf->search_header;
DefaultType = Currentbuf->real_type;
buf = loadGeneralFile(url->ptr, NULL, NO_REFERER, RG_NOCACHE, request);
+#ifdef JP_CHARSET
+ DocumentCode = old_code;
+#endif
SearchHeader = FALSE;
DefaultType = NULL;
+
if (multipart)
unlink(request->body);
if (buf == NULL) {
@@ -4195,36 +4182,28 @@ reload(void)
else if (buf == NO_BUFFER) {
return;
}
- buf->search_header = Currentbuf->search_header;
- buf->form_submit = Currentbuf->form_submit;
if (fbuf != NULL)
Firstbuf = deleteBuffer(Firstbuf, fbuf);
repBuffer(Currentbuf, buf);
- if ((type != NULL) && (buf->type != NULL) &&
+ if ((buf->type != NULL) && (sbuf.type != NULL) &&
((!strcasecmp(buf->type, "text/plain") &&
- !strcasecmp(type, "text/html")) ||
+ !strcasecmp(sbuf.type, "text/html")) ||
(!strcasecmp(buf->type, "text/html") &&
- !strcasecmp(type, "text/plain")))) {
+ !strcasecmp(sbuf.type, "text/plain")))) {
vwSrc();
if (Currentbuf != buf)
Firstbuf = deleteBuffer(Firstbuf, buf);
}
- if (Currentbuf->firstLine == NULL) {
- displayBuffer(Currentbuf, B_FORCE_REDRAW);
- return;
- }
- Currentbuf->topLine =
- lineSkip(Currentbuf, Currentbuf->firstLine, top - 1, FALSE);
- gotoLine(Currentbuf, linenum);
- Currentbuf->pos = pos;
- Currentbuf->currentColumn = currentColumn;
- arrangeCursor(Currentbuf);
+ Currentbuf->search_header = sbuf.search_header;
+ Currentbuf->form_submit = sbuf.form_submit;
+ if (Currentbuf->firstLine)
+ restorePosition(Currentbuf, &sbuf);
displayBuffer(Currentbuf, B_FORCE_REDRAW);
}
/* mark URL-like patterns as anchors */
void
-chkURL(void)
+chkURLBuffer(Buffer *buf)
{
static char *url_like_pat[] = {
"http://[a-zA-Z0-9][a-zA-Z0-9:%\\-\\./?=~_\\&+@#,\\$]*[a-zA-Z0-9_/=]",
@@ -4251,17 +4230,22 @@ chkURL(void)
};
int i;
for (i = 0; url_like_pat[i]; i++) {
- reAnchor(Currentbuf, url_like_pat[i]);
+ reAnchor(buf, url_like_pat[i]);
}
- Currentbuf->check_url |= CHK_URL;
+ buf->check_url |= CHK_URL;
+}
+void
+chkURL(void)
+{
+ chkURLBuffer(Currentbuf);
displayBuffer(Currentbuf, B_FORCE_REDRAW);
}
#ifdef USE_NNTP
/* mark Message-ID-like patterns as NEWS anchors */
void
-chkNMID(void)
+chkNMIDBuffer(Buffer *buf)
{
static char *url_like_pat[] = {
"<[^<> ][^<> ]*@[A-z0-9\\.\\-_][A-z0-9\\.\\-_]*>",
@@ -4269,10 +4253,15 @@ chkNMID(void)
};
int i;
for (i = 0; url_like_pat[i]; i++) {
- reAnchorNews(Currentbuf, url_like_pat[i]);
+ reAnchorNews(buf, url_like_pat[i]);
}
- Currentbuf->check_url |= CHK_NMID;
+ buf->check_url |= CHK_NMID;
+}
+void
+chkNMID(void)
+{
+ chkNMIDBuffer(Currentbuf);
displayBuffer(Currentbuf, B_FORCE_REDRAW);
}
#endif /* USE_NNTP */
diff --git a/proto.h b/proto.h
@@ -90,8 +90,10 @@ extern void curURL(void);
extern void vwSrc(void);
extern void reload(void);
extern void chkURL(void);
+extern void chkURLBuffer(Buffer *buf);
#ifdef USE_NNTP
extern void chkNMID(void);
+extern void chkNMIDBuffer(Buffer *buf);
#else
#define chkNMID nulcmd
#endif
@@ -230,6 +232,7 @@ extern void cursorHome(Buffer *buf);
extern void arrangeCursor(Buffer *buf);
extern void arrangeLine(Buffer *buf);
extern void cursorXY(Buffer *buf, int x, int y);
+extern void restorePosition(Buffer *buf, Buffer *orig);
extern int columnSkip(Buffer *buf, int offset);
extern int columnPos(Line *line, int column);
extern Line *lineSkip(Buffer *buf, Line *line, int offset, int last);