/* * Implements the vi "L" command. * * Move to the last (or nth last) line in window */ int gotoeos(int f, int n) { LINE *last = DOT.l; int nn; n = need_at_least(f, n, 1); /* first get to the end */ DOT.l = curwp->w_line.l; nn = curwp->w_ntrows; while ((nn -= line_height(curwp, DOT.l)) > 0) { if (is_last_line(DOT, curbp)) break; DOT.l = lforw(DOT.l); } #ifdef WMDLINEWRAP /* adjust if we pointed to a line-fragment */ if (w_val(curwp, WMDLINEWRAP) && nn < 0 && DOT.l != curwp->w_line.l) DOT.l = lback(DOT.l); #endif /* and then go back up */ /* (we're either at eos or eof) */ while (--n != 0) { if (sameline(DOT, curwp->w_line)) break; DOT.l = lback(DOT.l); } if (DOT.l != last) curwp->w_flag |= WFMOVE; return firstnonwhite(FALSE, 1); }
/* * Move the cursor forwards by "n" characters. If "n" is less than zero call * "backchar" to actually do the move. Otherwise compute the new cursor * location, and move ".". Error if you try and move off the end of the * buffer. Set the flag if the line pointer for dot changes. */ int forwchar(int f, int n) { int rc = TRUE; n = need_a_count(f, n, 1); if (n < 0) { rc = backchar(f, -n); } else { while (n--) { /* if an explicit arg was given, allow us to land on the newline, else skip it */ if (is_at_end_of_line(DOT) || (f == FALSE && !insertmode && llength(DOT.l) && DOT.o == llength(DOT.l) - 1)) { if (is_header_line(DOT, curbp) || is_last_line(DOT, curbp)) { rc = FALSE; break; } DOT.l = lforw(DOT.l); DOT.o = w_left_margin(curwp); curwp->w_flag |= WFMOVE; } else { DOT.o += BytesAt(DOT.l, DOT.o); } } } return (rc); }
/* paint the first nlines of a buffer */ void paint_buffer_nlines(struct te_buffer *buf, int nlines) { if (buf == NULL) return; saveyx(); wmove(buffer_win, 0, 0); bstring s; int i = 0; int count = max(buf->top_char - 1, 0); for(i = 0; i < nlines; i++) { s = current_line_as_bstring(buf->contents, count); draw_line(s, i); count += blength(s); bdestroy(s); if (is_last_line(buf->contents, count) == TRUE) break; } restoreyx(); refresh(); }
/* * Implements the vi "H" command. * * Move to first (or nth) line in window */ int gotobos(int f, int n) { LINE *last = DOT.l; int nn = curwp->w_ntrows; n = need_at_least(f, n, 1); DOT.l = curwp->w_line.l; while (--n != 0) { if (is_last_line(DOT, curbp)) break; nn -= line_height(curwp, DOT.l); DOT.l = lforw(DOT.l); } if (DOT.l != last) curwp->w_flag |= WFMOVE; return firstnonwhite(FALSE, 1); }
/* * DOT points to the beginning of a region, we're given the count of characters * to put into the region. Set MK at the end. This handles counts that extend * beyond the current line, but makes assumptions about the record separator. * Data from an external filter always uses newline for a separator, otherwise * we will run into problems with lex/flex. Internally computed regions are * not the same problem. */ static void set_mark_after(int count, int rslen) { int offset = DOT.o; MK = DOT; while (count > 0) { MK.o += count; /* FIXME? */ if (is_last_line(MK, curbp)) { count = 0; } else if (MK.o > llength(MK.l)) { if (MK.o <= (llength(MK.l) + rslen)) { MK.o = llength(MK.l); break; } count -= (llength(MK.l) + rslen - offset); MK.l = lforw(MK.l); MK.o = 0; } else { break; } offset = 0; } }