Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acme: use Edit for <, |, > and to trim spaces during Put #593

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 13 additions & 40 deletions src/cmd/acme/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ execute(Text *t, uint aq0, uint aq1, int external, Text *argt)
free(r);
return;
}
/* Prefer Edit's <, |, > */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has an unintended side-effect.

With the original code, clicking with button 2 on something like |ind would set the selection to the output of the command. This version sets the selection to the empty string before that output.

I'll sort it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the side effect on dot in acme's Edit |cmd does not happen in sam. I'm inclined to regard acme's behavior as wrong and fix it, leaving this interpretation of |cmd alone.

(The new Put code should likely preserve dot.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @rsc in case you have strong opinions.

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);
Expand Down Expand Up @@ -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';
Expand All @@ -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);
Expand Down