mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
acme: use Edit for <, |, > and to trim spaces during Put
Programs reading the event file now notice effects on the body from <, |, and Put.
This commit is contained in:
parent
ffbdd1aa20
commit
79106d7635
1 changed files with 13 additions and 40 deletions
|
@ -243,6 +243,16 @@ execute(Text *t, uint aq0, uint aq1, int external, Text *argt)
|
|||
free(r);
|
||||
return;
|
||||
}
|
||||
/* Prefer Edit's <, |, > */
|
||||
s = skipbl(r, q1-q0, &n);
|
||||
if(n != 0){
|
||||
c = s[0];
|
||||
if(c=='<' || c=='|' || c=='>'){
|
||||
edit(t, nil, argt, XXX, XXX, s, n);
|
||||
free(r);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
b = runetobyte(r, q1-q0);
|
||||
free(r);
|
||||
|
@ -837,16 +847,11 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname)
|
|||
static void
|
||||
trimspaces(Text *et)
|
||||
{
|
||||
File *f;
|
||||
Rune *r;
|
||||
static Rune cmd[] = { ',', 'x', '/', '[', ' ', '\t', ']', '+', '$', '/', 'd' };
|
||||
Text *t;
|
||||
uint q0, n, delstart;
|
||||
int c, i, marked;
|
||||
int c;
|
||||
|
||||
t = &et->w->body;
|
||||
f = t->file;
|
||||
marked = 0;
|
||||
|
||||
if(t->w!=nil && et->w!=t->w){
|
||||
/* can this happen when t == &et->w->body? */
|
||||
c = 'M';
|
||||
|
@ -855,39 +860,7 @@ trimspaces(Text *et)
|
|||
winlock(t->w, c);
|
||||
}
|
||||
|
||||
r = fbufalloc();
|
||||
q0 = f->b.nc;
|
||||
delstart = q0; /* end of current space run, or 0 if no active run; = q0 to delete spaces before EOF */
|
||||
while(q0 > 0) {
|
||||
n = RBUFSIZE;
|
||||
if(n > q0)
|
||||
n = q0;
|
||||
q0 -= n;
|
||||
bufread(&f->b, q0, r, n);
|
||||
for(i=n; ; i--) {
|
||||
if(i == 0 || (r[i-1] != ' ' && r[i-1] != '\t')) {
|
||||
// Found non-space or start of buffer. Delete active space run.
|
||||
if(q0+i < delstart) {
|
||||
if(!marked) {
|
||||
marked = 1;
|
||||
seq++;
|
||||
filemark(f);
|
||||
}
|
||||
textdelete(t, q0+i, delstart, TRUE);
|
||||
}
|
||||
if(i == 0) {
|
||||
/* keep run active into tail of next buffer */
|
||||
if(delstart > 0)
|
||||
delstart = q0;
|
||||
break;
|
||||
}
|
||||
delstart = 0;
|
||||
if(r[i-1] == '\n')
|
||||
delstart = q0+i-1; /* delete spaces before this newline */
|
||||
}
|
||||
}
|
||||
}
|
||||
fbuffree(r);
|
||||
edit(t, nil, nil, XXX, XXX, cmd, nelem(cmd));
|
||||
|
||||
if(t->w!=nil && et->w!=t->w)
|
||||
winunlock(t->w);
|
||||
|
|
Loading…
Reference in a new issue