4 moveto(File *f, Range r)
6 Posn p1 = r.p1, p2 = r.p2;
12 outTsl(Hmoveto, f->tag, f->dot.r.p1);
21 if(f->dot.r.p1==f->tdot.p1 && f->dot.r.p2==f->tdot.p2)
23 outTsll(Hsetdot, f->tag, f->dot.r.p1, f->dot.r.p2);
30 outTS(Hsetpat, &lastpat);
37 lookorigin(File *f, Posn p0, Posn ls)
46 for(nl=nc=c=0; c!=-1 && nl<ls && nc<ls*CHARSHIFT; nc++)
47 if((c=filereadc(f, --p)) == '\n'){
60 outTsl(Horigin, f->tag, p0);
67 * Hard to get absolutely right. Use what we know about ASCII
68 * and assume anything above the Latin control characters is
69 * potentially an alphanumeric.
73 if(0x7F<=c && c<=0xA0)
75 if(utfrune("!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", c))
83 return c == 0 || c == ' ' || c == '\t' ||
84 c == '\n' || c == '\r' || c == '\v';
88 inmode(Rune r, int mode)
90 return (mode == 0) ? isalnum(r) : r && !isspace(r);
94 clickmatch(File *f, int cl, int cr, int dir, Posn *p)
103 c = filereadc(f, (*p)++);
107 c = filereadc(f, --(*p));
115 return cl=='\n' && nest==1;
119 strrune(Rune *s, Rune c)
136 * Stretches a selection out over current text,
137 * selecting matching range if possible.
138 * If there's no matching range, mode 0 selects
139 * a single alphanumeric region. Mode 1 selects
140 * a non-whitespace region.
143 stretchsel(File *f, Posn p1, int mode)
151 f->dot.r.p1 = f->dot.r.p2 = p1;
152 for(i=0; left[i]; i++){
160 c = filereadc(f, p - 1);
162 if(clickmatch(f, c, r[strrune(l, c)-l], 1, &p)){
164 f->dot.r.p2 = p-(c!='\n');
168 /* try right match */
175 if(clickmatch(f, c, l[strrune(r, c)-r], -1, &p)){
177 if(c!='\n' || p!=0 || filereadc(f, 0)=='\n')
179 f->dot.r.p2 = p1+(p1<f->nc && c=='\n');
184 /* try filling out word to right */
186 while(p < f->nc && inmode(filereadc(f, p++), mode))
188 /* try filling out word to left */
190 while(--p >= 0 && inmode(filereadc(f, p), mode))