16 Image *textcols[NCOL];
17 static Rune Ldot[] = { '.', 0 };
20 TABDIR = 3 /* width of tabs in directory windows */
24 textinit(Text *t, File *f, Rectangle r, Reffont *rf, Image *cols[NCOL])
29 t->scrollr.max.x = r.min.x+Scrollwid;
31 r.min.x += Scrollwid+Scrollgap;
36 memmove(t->fr.cols, cols, sizeof t->fr.cols);
37 textredraw(t, r, rf->f, screen, -1);
41 textredraw(Text *t, Rectangle r, Font *f, Image *b, int odx)
46 frinit(&t->fr, r, f, b, t->fr.cols);
48 rr.min.x -= Scrollwid+Scrollgap; /* back fill to scroll bar */
49 draw(t->fr.b, rr, t->fr.cols[BACK], nil, ZP);
50 /* use no wider than 3-space tabs in a directory */
54 maxt = min(TABDIR, maxtab);
58 t->fr.maxtab = maxt*stringwidth(f, "0");
59 if(t->what==Body && t->w->isdir && odx!=Dx(t->all)){
60 if(t->fr.maxlines > 0){
62 textcolumnate(t, t->w->dlp, t->w->ndl);
67 textsetselect(t, t->q0, t->q1);
72 textresize(Text *t, Rectangle r)
77 r.max.y -= Dy(r)%t->fr.font->height;
83 t->scrollr.max.x = r.min.x+Scrollwid;
85 r.min.x += Scrollwid+Scrollgap;
87 textredraw(t, r, t->fr.font, screen, odx);
96 filedeltext(t->file, t);
112 dircmp(const void *a, const void *b)
119 n = min(da->nr, db->nr);
120 i = memcmp(da->r, db->r, n*sizeof(Rune));
123 return da->nr - db->nr;
127 textcolumnate(Text *t, Dirlist **dlp, int ndl)
129 int i, j, w, colw, mint, maxt, ncol, nrow;
132 static Rune Lnl[] = { '\n', 0 };
133 static Rune Ltab[] = { '\t', 0 };
135 if(t->file->ntext > 1)
137 mint = stringwidth(t->fr.font, "0");
138 /* go for narrower tabs if set more than 3 wide */
139 t->fr.maxtab = min(maxtab, TABDIR)*mint;
142 for(i=0; i<ndl; i++){
145 if(maxt-w%maxt < mint || w%maxt==0)
155 ncol = max(1, Dx(t->fr.r)/colw);
156 nrow = (ndl+ncol-1)/ncol;
159 for(i=0; i<nrow; i++){
160 for(j=i; j<ndl; j+=nrow){
162 fileinsert(t->file, q1, dl->r, dl->nr);
167 if(maxt-w%maxt < mint){
168 fileinsert(t->file, q1, Ltab, 1);
173 fileinsert(t->file, q1, Ltab, 1);
178 fileinsert(t->file, q1, Lnl, 1);
184 textload(Text *t, uint q0, char *file, int setqid)
188 int fd, i, j, n, ndl, nulls;
194 if(t->ncache!=0 || t->file->b.nc || t->w==nil || t!=&t->w->body || (t->w->isdir && t->file->nname==0))
196 if(t->w->isdir && t->file->nname==0){
197 warning(nil, "empty directory name");
200 fd = open(file, OREAD);
202 warning(nil, "can't open %s: %r\n", file);
207 warning(nil, "can't fstat %s: %r\n", file);
211 if(d->qid.type & QTDIR){
212 /* this is checked in get() but it's possible the file changed underfoot */
213 if(t->file->ntext > 1){
214 warning(nil, "%s is a directory; can't read with multiple windows on it\n", file);
218 t->w->filemenu = FALSE;
219 if(t->file->name[t->file->nname-1] != '/'){
220 rp = runemalloc(t->file->nname+1);
221 runemove(rp, t->file->name, t->file->nname);
222 rp[t->file->nname] = '/';
223 winsetname(t->w, rp, t->file->nname+1);
229 while((n=dirread(fd, &dbuf)) > 0){
231 dl = emalloc(sizeof(Dirlist));
232 j = strlen(dbuf[i].name);
233 tmp = emalloc(j+1+1);
234 memmove(tmp, dbuf[i].name, j);
235 if(dbuf[i].qid.type & QTDIR)
238 dl->r = bytetorune(tmp, &dl->nr);
239 dl->wid = stringwidth(t->fr.font, tmp);
242 dlp = realloc(dlp, ndl*sizeof(Dirlist*));
247 qsort(dlp, ndl, sizeof(Dirlist*), dircmp);
250 textcolumnate(t, dlp, ndl);
254 t->w->filemenu = TRUE;
255 q1 = q0 + fileload(t->file, q0, fd, &nulls);
258 t->file->dev = d->dev;
259 t->file->mtime = d->mtime;
260 t->file->qidpath = d->qid.path;
264 for(q=q0; q<q1; q+=n){
268 bufread(&t->file->b, q, rp, n);
271 else if(q <= t->org+t->fr.nchars)
272 frinsert(&t->fr, rp, rp+n, q-t->org);
273 if(t->fr.lastlinefull)
277 for(i=0; i<t->file->ntext; i++){
278 u = t->file->text[i];
280 if(u->org > u->file->b.nc) /* will be 0 because of reset(), but safety first */
282 textresize(u, u->all);
283 textbacknl(u, u->org, 0); /* go to beginning of line */
285 textsetselect(u, q0, q0);
288 warning(nil, "%s: NUL bytes elided\n", file);
298 textbsinsert(Text *t, uint q0, Rune *r, uint n, int tofile, int *nrp)
303 if(t->what == Tag){ /* can't happen but safety first: mustn't backspace over file name */
305 textinsert(t, q0, r, n, tofile);
331 textdelete(t, q0, q0+initial, tofile);
334 textinsert(t, q0, tp, n, tofile);
343 textinsert(Text *t, uint q0, Rune *r, uint n, int tofile)
348 if(tofile && t->ncache != 0)
349 error("text.insert");
353 fileinsert(t->file, q0, r, n);
356 t->w->utflastqid = -1;
358 if(t->file->ntext > 1)
359 for(i=0; i<t->file->ntext; i++){
360 u = t->file->text[i];
362 u->w->dirty = TRUE; /* always a body */
363 textinsert(u, q0, r, n, FALSE);
364 textsetselect(u, u->q0, u->q1);
376 else if(q0 <= t->org+t->fr.nchars)
377 frinsert(&t->fr, r, r+n, q0-t->org);
383 winevent(t->w, "%c%d %d 0 %d %.*S\n", c, q0, q0+n, n, n, r);
385 winevent(t->w, "%c%d %d 0 0 \n", c, q0, q0+n, n);
396 if(t->fr.lastlinefull || t->nofill)
406 n = t->file->b.nc-(t->org+t->fr.nchars);
409 if(n > 2000) /* educated guess at reasonable amount */
411 bufread(&t->file->b, t->org+t->fr.nchars, rp, n);
413 * it's expensive to frinsert more than we need, so
416 nl = t->fr.maxlines-t->fr.nlines;
425 frinsert(&t->fr, rp, rp+i, t->fr.nchars);
426 }while(t->fr.lastlinefull == FALSE);
431 textdelete(Text *t, uint q0, uint q1, int tofile)
437 if(tofile && t->ncache != 0)
438 error("text.delete");
443 filedelete(t->file, q0, q1);
446 t->w->utflastqid = -1;
448 if(t->file->ntext > 1)
449 for(i=0; i<t->file->ntext; i++){
450 u = t->file->text[i];
452 u->w->dirty = TRUE; /* always a body */
453 textdelete(u, q0, q1, FALSE);
454 textsetselect(u, u->q0, u->q1);
460 t->q0 -= min(n, t->q0-q0);
462 t->q1 -= min(n, t->q1-q0);
465 else if(q0 < t->org+t->fr.nchars){
467 if(p1 > t->fr.nchars)
474 frdelete(&t->fr, p0, p1);
481 winevent(t->w, "%c%d %d 0 0 \n", c, q0, q1);
486 textconstrain(Text *t, uint q0, uint q1, uint *p0, uint *p1)
488 *p0 = min(q0, t->file->b.nc);
489 *p1 = min(q1, t->file->b.nc);
493 textreadc(Text *t, uint q)
497 if(t->cq0<=q && q<t->cq0+t->ncache)
498 r = t->cache[q-t->cq0];
500 bufread(&t->file->b, q, &r, 1);
505 textbswidth(Text *t, Rune c)
511 /* there is known to be at least one character to erase */
512 if(c == 0x08) /* ^H: erase character */
517 r = textreadc(t, q-1);
518 if(r == '\n'){ /* eat at most one more character */
519 if(q == t->q0) /* eat the newline */
525 if(eq && skipping) /* found one; stop skipping */
527 else if(!eq && !skipping)
536 textfilewidth(Text *t, uint q0, int oneelement)
543 r = textreadc(t, q-1);
546 if(oneelement && r=='/')
554 textcomplete(Text *t)
565 /* control-f: filename completion; works back to white space or / */
566 if(t->q0<t->file->b.nc && textreadc(t, t->q0)>' ') /* must be at end of word */
568 nstr = textfilewidth(t, t->q0, TRUE);
569 str = runemalloc(nstr);
570 npath = textfilewidth(t, t->q0-nstr, FALSE);
571 path = runemalloc(npath);
578 for(i=0; i<nstr; i++)
579 str[i] = textreadc(t, q++);
580 q = t->q0-nstr-npath;
581 for(i=0; i<npath; i++)
582 path[i] = textreadc(t, q++);
583 /* is path rooted? if not, we need to make it relative to window path */
584 if(npath>0 && path[0]=='/')
585 dir = runestr(path, npath);
587 dir = dirname(t, nil, 0);
588 if(dir.nr + 1 + npath > nelem(tmp)){
594 dir.r = runestrdup(Ldot);
596 runemove(tmp, dir.r, dir.nr);
598 runemove(tmp+dir.nr+1, path, npath);
602 dir = cleanrname(dir);
605 s = smprint("%.*S", nstr, str);
606 dirs = smprint("%.*S", dir.nr, dir.r);
607 c = complete(dirs, s);
610 warning(nil, "error attempting completion: %r\n");
615 warning(nil, "%.*S%s%.*S*%s\n",
617 dir.nr>0 && dir.r[dir.nr-1]!='/' ? "/" : "",
619 c->nmatch ? "" : ": no matches in:");
620 for(i=0; i<c->nfile; i++)
621 warning(nil, " %s\n", c->filename[i]);
625 rp = runesmprint("%s", c->string);
637 texttype(Text *t, Rune r)
645 if(t->what!=Body && r=='\n')
656 textshow(t, t->q0-1, t->q0-1, TRUE);
660 if(t->q1 < t->file->b.nc){
662 textshow(t, t->q1+1, t->q1+1, TRUE);
666 n = t->fr.maxlines/3;
669 n = mousescrollsize(t->fr.maxlines);
674 n = 2*t->fr.maxlines/3;
676 q0 = t->org+frcharofpt(&t->fr, Pt(t->fr.r.min.x, t->fr.r.min.y+n*t->fr.font->height));
677 textsetorigin(t, q0, TRUE);
680 n = t->fr.maxlines/3;
683 n = mousescrollsize(t->fr.maxlines);
686 n = 2*t->fr.maxlines/3;
688 q0 = textbacknl(t, t->org, n);
689 textsetorigin(t, q0, TRUE);
692 textshow(t, 0, 0, FALSE);
699 textshow(t, t->file->b.nc, t->file->b.nc, FALSE);
709 cut(t, t, nil, TRUE, TRUE, nil, 0);
712 textshow(t, t->q0, t->q0, 1);
714 case 0x06: /* ^F: complete */
716 rp = textcomplete(t);
720 break; /* fall through to normal insertion case */
723 textsetselect(t, t->eq0, t->q0);
731 case 0x08: /* ^H: erase character */
732 case 0x15: /* ^U: erase line */
733 case 0x17: /* ^W: erase word */
734 if(t->q0 == 0) /* nothing to erase */
736 nnb = textbswidth(t, r);
739 /* if selection is at beginning of window, avoid deleting invisible text */
746 for(i=0; i<t->file->ntext; i++){
747 u = t->file->text[i];
753 error("text.type backspace");
757 textdelete(u, q1-n, q1, FALSE);
760 if(u->eq0==q1 || u->eq0==~0)
763 textdelete(u, q0, q0+nb, TRUE);
765 textsetselect(u, u->q0, u->q1);
767 textsetselect(t, q0, q0);
770 for(i=0; i<t->file->ntext; i++)
771 textfill(t->file->text[i]);
774 if(t->w->autoindent){
775 /* find beginning of previous line using backspace code */
776 nnb = textbswidth(t, 0x15); /* ^U case */
777 rp = runemalloc(nnb + 1);
780 for(i=0; i<nnb; i++){
781 r = textreadc(t, t->q0-nnb+i);
782 if(r != ' ' && r != '\t')
787 break; /* fall through to normal code */
789 /* otherwise ordinary character; just insert, typically in caches of all texts */
790 for(i=0; i<t->file->ntext; i++){
791 u = t->file->text[i];
796 else if(t->q0 != u->cq0+u->ncache)
797 error("text.type cq1");
798 textinsert(u, t->q0, rp, nr, FALSE);
800 textsetselect(u, u->q0, u->q1);
801 if(u->ncache+nr > u->ncachealloc){
802 u->ncachealloc += 10 + nr;
803 u->cache = runerealloc(u->cache, u->ncachealloc);
805 runemove(u->cache+u->ncache, rp, nr);
810 textsetselect(t, t->q0+nr, t->q0+nr);
811 if(r=='\n' && t->w!=nil)
816 textcommit(Text *t, int tofile)
821 fileinsert(t->file, t->cq0, t->cache, t->ncache);
824 t->w->utflastqid = -1;
829 static Text *clicktext;
830 static uint clickmsec;
831 static Text *selecttext;
835 * called from frame library
838 framescroll(Frame *f, int dl)
840 if(f != &selecttext->fr)
841 error("frameselect not right frame");
842 textframescroll(selecttext, dl);
846 textframescroll(Text *t, int dl)
855 q0 = textbacknl(t, t->org, -dl);
856 if(selectq > t->org+t->fr.p0)
857 textsetselect(t, t->org+t->fr.p0, selectq);
859 textsetselect(t, selectq, t->org+t->fr.p0);
861 if(t->org+t->fr.nchars == t->file->b.nc)
863 q0 = t->org+frcharofpt(&t->fr, Pt(t->fr.r.min.x, t->fr.r.min.y+dl*t->fr.font->height));
864 if(selectq > t->org+t->fr.p1)
865 textsetselect(t, t->org+t->fr.p1, selectq);
867 textsetselect(t, selectq, t->org+t->fr.p1);
869 textsetorigin(t, q0, TRUE);
882 * To have double-clicking and chording, we double-click
883 * immediately if it might make sense.
888 selectq = t->org+frcharofpt(&t->fr, mouse->xy);
889 if(clicktext==t && mouse->msec-clickmsec<500)
890 if(q0==q1 && selectq==q0){
891 textdoubleclick(t, &q0, &q1);
892 textsetselect(t, q0, q1);
893 flushimage(display, 1);
896 /* stay here until something interesting happens */
899 while(mouse->buttons==b && abs(mouse->xy.x-x)<3 && abs(mouse->xy.y-y)<3);
900 mouse->xy.x = x; /* in case we're calling frselect */
902 q0 = t->q0; /* may have changed */
906 if(mouse->buttons == b){
907 t->fr.scroll = framescroll;
908 frselect(&t->fr, mousectl);
909 /* horrible botch: while asleep, may have lost selection altogether */
910 if(selectq > t->file->b.nc)
911 selectq = t->org + t->fr.p0;
916 q0 = t->org + t->fr.p0;
917 if(selectq > t->org+t->fr.nchars)
920 q1 = t->org+t->fr.p1;
923 if(q0==t->q0 && clicktext==t && mouse->msec-clickmsec<500){
924 textdoubleclick(t, &q0, &q1);
928 clickmsec = mouse->msec;
932 textsetselect(t, q0, q1);
933 flushimage(display, 1);
934 state = op = 0; /* undo when possible; +1 for cut, -1 for paste */
935 while(mouse->buttons){
939 if(state==0 && op==0 && t->what==Body){
941 filemark(t->w->body.file);
944 if(state==-1 && t->what==Body){
946 textsetselect(t, q0, t->q0);
948 }else if(state != 1 && op != -1){
949 cut(t, t, nil, TRUE, TRUE, nil, 0);
953 if(state==1 && t->what==Body){
955 textsetselect(t, q0, t->q1);
957 }else if(state != -1 && op != 1){
958 paste(t, t, nil, TRUE, FALSE, nil, 0);
965 flushimage(display, 1);
966 while(mouse->buttons == b)
973 textshow(Text *t, uint q0, uint q1, int doselect)
981 textsetselect(t, q0, q1);
984 if(t->w!=nil && t->fr.maxlines==0)
985 colgrow(t->col, t->w, 1);
987 textsetselect(t, q0, q1);
988 qe = t->org+t->fr.nchars;
989 if(t->org<=q0 && (q0<qe || (q0==qe && qe==t->file->b.nc+t->ncache)))
992 if(t->w->nopen[QWevent] > 0)
993 nl = 3*t->fr.maxlines/4;
995 nl = t->fr.maxlines/4;
996 q = textbacknl(t, q0, nl);
997 /* avoid going backwards if trying to go forwards - long lines! */
998 if(!(q0>t->org && q<t->org))
999 textsetorigin(t, q, TRUE);
1000 while(q0 > t->org+t->fr.nchars)
1001 textsetorigin(t, t->org+1, FALSE);
1007 region(int a, int b)
1017 selrestore(Frame *f, Point pt0, uint p0, uint p1)
1019 if(p1<=f->p0 || p0>=f->p1){
1021 frdrawsel0(f, pt0, p0, p1, f->cols[BACK], f->cols[TEXT]);
1024 if(p0>=f->p0 && p1<=f->p1){
1025 /* entirely inside */
1026 frdrawsel0(f, pt0, p0, p1, f->cols[HIGH], f->cols[HTEXT]);
1030 /* they now are known to overlap */
1032 /* before selection */
1034 frdrawsel0(f, pt0, p0, f->p0, f->cols[BACK], f->cols[TEXT]);
1036 pt0 = frptofchar(f, p0);
1038 /* after selection */
1040 frdrawsel0(f, frptofchar(f, f->p1), f->p1, p1, f->cols[BACK], f->cols[TEXT]);
1043 /* inside selection */
1044 frdrawsel0(f, pt0, p0, p1, f->cols[HIGH], f->cols[HTEXT]);
1048 textsetselect(Text *t, uint q0, uint q1)
1052 /* t->fr.p0 and t->fr.p1 are always right; t->q0 and t->q1 may be off */
1055 /* compute desired p0,p1 from q0,q1 */
1062 if(p0 > t->fr.nchars)
1064 if(p1 > t->fr.nchars)
1066 if(p0==t->fr.p0 && p1==t->fr.p1)
1068 /* screen disagrees with desired selection */
1069 if(t->fr.p1<=p0 || p1<=t->fr.p0 || p0==p1 || t->fr.p1==t->fr.p0){
1070 /* no overlap or too easy to bother trying */
1071 frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p0), t->fr.p0, t->fr.p1, 0);
1072 frdrawsel(&t->fr, frptofchar(&t->fr, p0), p0, p1, 1);
1075 /* overlap; avoid unnecessary painting */
1077 /* extend selection backwards */
1078 frdrawsel(&t->fr, frptofchar(&t->fr, p0), p0, t->fr.p0, 1);
1079 }else if(p0 > t->fr.p0){
1080 /* trim first part of selection */
1081 frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p0), t->fr.p0, p0, 0);
1084 /* extend selection forwards */
1085 frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p1), t->fr.p1, p1, 1);
1086 }else if(p1 < t->fr.p1){
1087 /* trim last part of selection */
1088 frdrawsel(&t->fr, frptofchar(&t->fr, p1), p1, t->fr.p1, 0);
1097 * Release the button in less than DELAY ms and it's considered a null selection
1098 * if the mouse hardly moved, regardless of whether it crossed a char boundary.
1106 xselect(Frame *f, Mousectl *mc, Image *col, uint *p1p) /* when called, button is down */
1108 uint p0, p1, q, tmp;
1110 Point mp, pt0, pt1, qt;
1119 frtick(f, frptofchar(f, f->p0), 0);
1120 p0 = p1 = frcharofpt(f, mp);
1121 pt0 = frptofchar(f, p0);
1122 pt1 = frptofchar(f, p1);
1126 q = frcharofpt(f, mc->m.xy);
1130 if(reg != region(q, p0)){ /* crossed starting point; reset */
1132 selrestore(f, pt0, p0, p1);
1134 selrestore(f, pt1, p1, p0);
1137 reg = region(q, p0);
1139 frdrawsel0(f, pt0, p0, p1, col, display->white);
1141 qt = frptofchar(f, q);
1144 frdrawsel0(f, pt1, p1, q, col, display->white);
1147 selrestore(f, qt, q, p1);
1150 selrestore(f, pt1, p1, q);
1152 frdrawsel0(f, qt, q, p1, col, display->white);
1159 flushimage(f->display, 1);
1161 }while(mc->m.buttons == b);
1162 if(mc->m.msec-msec < DELAY && p0!=p1
1163 && abs(mp.x-mc->m.xy.x)<MINMOVE
1164 && abs(mp.y-mc->m.xy.y)<MINMOVE) {
1166 selrestore(f, pt0, p0, p1);
1168 selrestore(f, pt1, p1, p0);
1176 pt0 = frptofchar(f, p0);
1179 selrestore(f, pt0, p0, p1);
1182 frtick(f, frptofchar(f, f->p0), 1);
1183 flushimage(f->display, 1);
1189 textselect23(Text *t, uint *q0, uint *q1, Image *high, int mask)
1194 p0 = xselect(&t->fr, mousectl, high, &p1);
1195 buts = mousectl->m.buttons;
1196 if((buts & mask) == 0){
1201 while(mousectl->m.buttons)
1202 readmouse(mousectl);
1207 textselect2(Text *t, uint *q0, uint *q1, Text **tp)
1212 buts = textselect23(t, q0, q1, but2col, 4);
1215 if(buts & 1){ /* pick up argument */
1223 textselect3(Text *t, uint *q0, uint *q1)
1227 h = (textselect23(t, q0, q1, but3col, 1|2) == 0);
1231 static Rune left1[] = { '{', '[', '(', '<', 0xab, 0 };
1232 static Rune right1[] = { '}', ']', ')', '>', 0xbb, 0 };
1233 static Rune left2[] = { '\n', 0 };
1234 static Rune left3[] = { '\'', '"', '`', 0 };
1252 textdoubleclick(Text *t, uint *q0, uint *q1)
1258 for(i=0; left[i]!=nil; i++){
1262 /* try matching character to left, looking right */
1266 c = textreadc(t, q-1);
1267 p = runestrchr(l, c);
1269 if(textclickmatch(t, c, r[p-l], 1, &q))
1273 /* try matching character to right, looking left */
1274 if(q == t->file->b.nc)
1277 c = textreadc(t, q);
1278 p = runestrchr(r, c);
1280 if(textclickmatch(t, c, l[p-r], -1, &q)){
1281 *q1 = *q0+(*q0<t->file->b.nc && c=='\n');
1283 if(c!='\n' || q!=0 || textreadc(t, 0)=='\n')
1289 /* try filling out word to right */
1290 while(*q1<t->file->b.nc && isalnum(textreadc(t, *q1)))
1292 /* try filling out word to left */
1293 while(*q0>0 && isalnum(textreadc(t, *q0-1)))
1298 textclickmatch(Text *t, int cl, int cr, int dir, uint *q)
1306 if(*q == t->file->b.nc)
1308 c = textreadc(t, *q);
1314 c = textreadc(t, *q);
1322 return cl=='\n' && nest==1;
1326 textbacknl(Text *t, uint p, uint n)
1330 /* look for start of this line if n==0 */
1331 if(n==0 && p>0 && textreadc(t, p-1)!='\n')
1334 while(i-->0 && p>0){
1335 --p; /* it's at a newline now; back over it */
1338 /* at 128 chars, call it a line anyway */
1339 for(j=128; --j>0 && p>0; p--)
1340 if(textreadc(t, p-1)=='\n')
1347 textsetorigin(Text *t, uint org, int exact)
1353 if(org>0 && !exact){
1354 /* org is an estimate of the char posn; find a newline */
1355 /* don't try harder than 256 chars */
1356 for(i=0; i<256 && org<t->file->b.nc; i++){
1357 if(textreadc(t, org) == '\n'){
1366 if(a>=0 && a<t->fr.nchars){
1367 frdelete(&t->fr, 0, a);
1368 fixup = 1; /* frdelete can leave end of last line in wrong selection mode; it doesn't know what follows */
1370 else if(a<0 && -a<t->fr.nchars){
1373 bufread(&t->file->b, org, r, n);
1374 frinsert(&t->fr, r, r+n, 0);
1377 frdelete(&t->fr, 0, t->fr.nchars);
1381 textsetselect(t, t->q0, t->q1);
1382 if(fixup && t->fr.p1 > t->fr.p0)
1383 frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p1-1), t->fr.p1-1, t->fr.p1, 1);
1391 /* do t->delete(0, t->nc, TRUE) without building backup stuff */
1392 textsetselect(t, t->org, t->org);
1393 frdelete(&t->fr, 0, t->fr.nchars);
1398 bufreset(&t->file->b);