#include "ded.h" #include "char.h" #include "ter.h" /************************************************************************ * * * copyright Richard Bornat 1981 * * * ************************************************************************/ /************************************************************************ * * * a procedure to insert a line-break in THE CURRENT line. It * * finds the most convenient place (to the left of scol * * if possible) * ************************************************************************/ line_break(scol, ctype) register int scol; int ctype; { register int col; int r_break, l_break; int make_br = !txin; /* insert a line-break marker when not text mode */ int lcol = lastcol(virt_c.row); /* convenience dictates that spaces and tabs force a break * just where they are typed. Also, a character typed to the right of * the last non-space character forces a break where it is typed. */ if ((ctype==SPACE || ctype==TAB || scol>lcol+1) && scol>leftcol && scol<=rightcol) r_break = l_break = scol; else { r_break = b_right(scol); l_break = b_left(scol); } /* prefer r_break if it is in a reasonable place */ if ((r_break==scol && r_break<=rightcol) || r_breakleftcol) col = l_break; else if (r_break=rightcol ? rightcol-1 : scol); make_br=true; } if (col>scol && col>lcol) { col = scol; make_br = true; } r_break = col; split_row(&virt_c.row, &r_break); /* insert a line-break character if necessary */ if (make_br) redisplay(virt_c.row-1, col, c_CONTROL); /* move the cursor to the correct position */ if (virt_c.col==col && make_br && col*2=col) { virt_c.col = virt_c.col-col+r_break; make_br = true; } else virt_c.row--; if (make_br) complain(); return(true); } int b_ok(rp) register char *rp; { return(*rp!=c_SPACE && *--rp==c_SPACE); } /* find next suitable word boundary under cursor or to right */ int b_right(scol) register int scol; { register char *rp = rowmap[virt_c.row]; if (scol>rightcol) scol=rightcol+1; else { if (scol<=leftcol) scol=leftcol; else scol--; do scol=r_word(rp, scol, leftcol, rightcol); while (scol<=rightcol && !b_ok(rp+scol)); } return(scol); } /* find next suitable boundary under cursor or to left */ int b_left(scol) register int scol; { register char *rp = rowmap[virt_c.row]; if (scol<=leftcol) scol=leftcol; else { if (scol>=rightcol) scol=rightcol; else scol++; do scol=l_word(rp, scol, leftcol, rightcol); while (scol>leftcol && !b_ok(rp+scol)); } return(scol); }