* acme patches from semi-recent changes in plan9port
@ 2020-09-17 22:19 Xiao-Yong Jin
2020-09-20 5:25 ` [9front] " ori
0 siblings, 1 reply; 3+ messages in thread
From: Xiao-Yong Jin @ 2020-09-17 22:19 UTC (permalink / raw)
To: 9front
List of git commit from plan9port,
4650064a acme: scale window bodies on resize, not including tag space
d28913a9 acme: save/restore multiline tags in Dump/Load
d2df5d6c acme: fix crash in X |cat with multiple windows
3d6e5cb5 acme: preserve window position and selection during Get
diff -r d8b6a8706f51 sys/src/cmd/acme/addr.c
--- a/sys/src/cmd/acme/addr.c Mon Sep 07 19:32:50 2020 -0700
+++ b/sys/src/cmd/acme/addr.c Thu Sep 17 17:12:35 2020 -0500
@@ -48,6 +48,27 @@
return FALSE;
}
+// nlcounttopos starts at q0 and advances nl lines,
+// being careful not to walk past the end of the text,
+// and then nr chars, being careful not to walk past
+// the end of the current line.
+// It returns the final position.
+long
+nlcounttopos(Text *t, long q0, long nl, long nr)
+{
+ while(nl > 0 && q0 < t->file->nc) {
+ if(textreadc(t, q0++) == '\n')
+ nl--;
+ }
+ if(nl > 0)
+ return q0;
+ while(nr > 0 && q0 < t->file->nc && textreadc(t, q0) != '\n') {
+ q0++;
+ nr--;
+ }
+ return q0;
+}
+
Range
number(Mntdir *md, Text *t, Range r, int line, int dir, int size, int *evalp)
{
diff -r d8b6a8706f51 sys/src/cmd/acme/cols.c
--- a/sys/src/cmd/acme/cols.c Mon Sep 07 19:32:50 2020 -0700
+++ b/sys/src/cmd/acme/cols.c Thu Sep 17 17:12:35 2020 -0500
@@ -186,7 +186,7 @@
void
colresize(Column *c, Rectangle r)
{
- int i;
+ int i, old, new;
Rectangle r1, r2;
Window *w;
@@ -199,6 +199,8 @@
r1.max.y += Border;
draw(screen, r1, display->black, nil, ZP);
r1.max.y = r.max.y;
+ new = Dy(r) - c->nw*(Border + font->height);
+ old = Dy(c->r) - c->nw*(Border + font->height);
for(i=0; i<c->nw; i++){
w = c->w[i];
w->maxlines = 0;
@@ -206,8 +208,8 @@
r1.max.y = r.max.y;
else {
r1.max.y = r1.min.y;
- if(Dy(c->r) != 0)
- r1.max.y += (Dy(w->r)+Border)*Dy(r)/Dy(c->r);
+ if(new > 0 && old > 0 && Dy(w->r) > Border+font->height)
+ r1.max.y += (Dy(w->r)-Border-font->height)*new/old + Border + font->height;
}
r2 = r1;
r2.max.y = r2.min.y+Border;
diff -r d8b6a8706f51 sys/src/cmd/acme/ecmd.c
--- a/sys/src/cmd/acme/ecmd.c Mon Sep 07 19:32:50 2020 -0700
+++ b/sys/src/cmd/acme/ecmd.c Thu Sep 17 17:12:35 2020 -0500
@@ -27,7 +27,7 @@
int pdisplay(File*);
void pfilename(File*);
void looper(File*, Cmd*, int);
-void filelooper(Cmd*, int);
+void filelooper(Text*, Cmd*, int);
void linelooper(File*, Cmd*);
Address lineaddr(long, Address, int);
int filematch(File*, String*);
@@ -575,9 +575,9 @@
}
int
-X_cmd(Text*, Cmd *cp)
+X_cmd(Text *t, Cmd *cp)
{
- filelooper(cp, cp->cmdc=='X');
+ filelooper(t, cp, cp->cmdc=='X');
return TRUE;
}
@@ -636,15 +636,16 @@
}
long
-nlcount(Text *t, long q0, long q1)
+nlcount(Text *t, long q0, long q1, long *pnr)
{
- long nl;
+ long nl, start;
Rune *buf;
int i, nbuf;
buf = fbufalloc();
nbuf = 0;
i = nl = 0;
+ start = q0;
while(q0 < q1){
if(i == nbuf){
nbuf = q1-q0;
@@ -653,24 +654,42 @@
bufread(t->file, q0, buf, nbuf);
i = 0;
}
- if(buf[i++] == '\n')
+ if(buf[i++] == '\n'){
+ start = q0+1;
nl++;
+ }
q0++;
}
fbuffree(buf);
+ if(pnr != nil)
+ *pnr = q0 - start;
return nl;
}
+enum {
+ PosnLine = 0,
+ PosnChars = 1,
+ PosnLineChars = 2,
+};
+
void
-printposn(Text *t, int charsonly)
+printposn(Text *t, int mode)
{
- long l1, l2;
+ long l1, l2, r1, r2;
if (t != nil && t->file != nil && t->file->name != nil)
warning(nil, "%.*S:", t->file->nname, t->file->name);
- if(!charsonly){
- l1 = 1+nlcount(t, 0, addr.r.q0);
- l2 = l1+nlcount(t, addr.r.q0, addr.r.q1);
+ switch(mode) {
+ case PosnChars:
+ warning(nil, "#%d", addr.r.q0);
+ if(addr.r.q1 != addr.r.q0)
+ warning(nil, ",#%d", addr.r.q1);
+ warning(nil, "\n");
+ return;
+ default:
+ case PosnLine:
+ l1 = 1+nlcount(t, 0, addr.r.q0, nil);
+ l2 = l1+nlcount(t, addr.r.q0, addr.r.q1, nil);
/* check if addr ends with '\n' */
if(addr.r.q1>0 && addr.r.q1>addr.r.q0 && textreadc(t, addr.r.q1-1)=='\n')
--l2;
@@ -679,32 +698,42 @@
warning(nil, ",%lud", l2);
warning(nil, "\n");
return;
+ case PosnLineChars:
+ l1 = 1+nlcount(t, 0, addr.r.q0, &r1);
+ l2 = l1+nlcount(t, addr.r.q0, addr.r.q1, &r2);
+ if(l2 == l1)
+ r2 += r1;
+ warning(nil, "%lud+#%lud", l1, r1);
+ if(l2 != l1)
+ warning(nil, ",%lud+#%lud", l2, r2);
+ warning(nil, "\n");
+ return;
}
- warning(nil, "#%d", addr.r.q0);
- if(addr.r.q1 != addr.r.q0)
- warning(nil, ",#%d", addr.r.q1);
- warning(nil, "\n");
}
int
eq_cmd(Text *t, Cmd *cp)
{
- int charsonly;
+ int mode;
switch(cp->text->n){
case 0:
- charsonly = FALSE;
+ mode = PosnLine;
break;
case 1:
if(cp->text->r[0] == '#'){
- charsonly = TRUE;
+ mode = PosnChars;
+ break;
+ }
+ if(cp->text->r[0] == '+'){
+ mode = PosnLineChars;
break;
}
default:
- SET(charsonly);
+ SET(mode);
editerror("newline expected");
}
- printposn(t, charsonly);
+ printposn(t, mode);
return TRUE;
}
@@ -921,9 +950,10 @@
}
void
-filelooper(Cmd *cp, int XY)
+filelooper(Text *t, Cmd *cp, int XY)
{
int i;
+ Text *targ;
if(Glooping++)
editerror("can't nest %c command", "YX"[XY]);
@@ -944,8 +974,22 @@
*/
allwindows(alllocker, (void*)1);
globalincref = 1;
- for(i=0; i<loopstruct.nw; i++)
- cmdexec(&loopstruct.w[i]->body, cp->cmd);
+ /*
+ * Unlock the window running the X command.
+ * We'll need to lock and unlock each target window in turn.
+ */
+ if(t && t->w)
+ winunlock(t->w);
+ for(i=0; i<loopstruct.nw; i++){
+ targ = &loopstruct.w[i]->body;
+ if(targ && targ->w)
+ winlock(targ->w, cp->cmdc);
+ cmdexec(targ, cp->cmd);
+ if(targ && targ->w)
+ winunlock(targ->w);
+ }
+ if(t && t->w)
+ winlock(t->w, cp->cmdc);
allwindows(alllocker, (void*)0);
globalincref = 0;
free(loopstruct.w);
diff -r d8b6a8706f51 sys/src/cmd/acme/exec.c
--- a/sys/src/cmd/acme/exec.c Mon Sep 07 19:32:50 2020 -0700
+++ b/sys/src/cmd/acme/exec.c Thu Sep 17 17:12:35 2020 -0500
@@ -506,15 +506,27 @@
winunlock(t->w);
}
+typedef struct TextAddr TextAddr;
+struct TextAddr {
+ long lorigin; // line+rune for origin
+ long rorigin;
+ long lq0; // line+rune for q0
+ long rq0;
+ long lq1; // line+rune for q1
+ long rq1;
+};
+
void
get(Text *et, Text *t, Text *argt, int flag1, int, Rune *arg, int narg)
{
char *name;
Rune *r;
int i, n, dirty, samename, isdir;
+ TextAddr *addr, *a;
Window *w;
Text *u;
Dir *d;
+ long q0, q1;
if(flag1)
if(et==nil || et->w==nil)
@@ -537,6 +549,14 @@
return;
}
}
+ addr = emalloc((t->file->ntext)*sizeof(TextAddr));
+ for(i=0; i<t->file->ntext; i++) {
+ a = &addr[i];
+ u = t->file->text[i];
+ a->lorigin = nlcount(u, 0, u->org, &a->rorigin);
+ a->lq0 = nlcount(u, 0, u->q0, &a->rq0);
+ a->lq1 = nlcount(u, u->q0, u->q1, &a->rq1);
+ }
r = bytetorune(name, &n);
for(i=0; i<t->file->ntext; i++){
u = t->file->text[i];
@@ -562,8 +582,18 @@
for(i=0; i<t->file->ntext; i++){
u = t->file->text[i];
textsetselect(&u->w->tag, u->w->tag.file->nc, u->w->tag.file->nc);
+ if(samename) {
+ a = &addr[i];
+ // warning(nil, "%d %d %d %d %d %d\n", a->lorigin, a->rorigin, a->lq0, a->rq0, a->lq1, a->rq1);
+ q0 = nlcounttopos(u, 0, a->lq0, a->rq0);
+ q1 = nlcounttopos(u, q0, a->lq1, a->rq1);
+ textsetselect(u, q0, q1);
+ q0 = nlcounttopos(u, 0, a->lorigin, a->rorigin);
+ textsetorigin(u, q0, FALSE);
+ }
textscrdraw(u);
}
+ free(addr);
xfidlog(w, "get");
}
diff -r d8b6a8706f51 sys/src/cmd/acme/fns.h
--- a/sys/src/cmd/acme/fns.h Mon Sep 07 19:32:50 2020 -0700
+++ b/sys/src/cmd/acme/fns.h Thu Sep 17 17:12:35 2020 -0500
@@ -88,6 +88,8 @@
Rune* findbl(Rune*, int, int*);
char* edittext(Window*, int, Rune*, int);
void flushwarnings(void);
+long nlcount(Text*, long, long, long*);
+long nlcounttopos(Text*, long, long, long);
#define runemalloc(a) (Rune*)emalloc((a)*sizeof(Rune))
#define runerealloc(a, b) (Rune*)erealloc((a), (b)*sizeof(Rune))
diff -r d8b6a8706f51 sys/src/cmd/acme/rows.c
--- a/sys/src/cmd/acme/rows.c Mon Sep 07 19:32:50 2020 -0700
+++ b/sys/src/cmd/acme/rows.c Thu Sep 17 17:12:35 2020 -0500
@@ -293,7 +293,7 @@
void
rowdump(Row *row, char *file)
{
- int i, j, fd, m, n, dumped;
+ int i, j, fd, m, n, start, dumped;
uint q0, q1;
Biobuf *b;
char *buf, *a, *fontname;
@@ -396,10 +396,17 @@
m = min(RBUFSIZE, w->tag.file->nc);
bufread(w->tag.file, 0, r, m);
n = 0;
- while(n<m && r[n]!='\n')
- n++;
- r[n++] = '\n';
- Bprint(b, "%.*S", n, r);
+ while(n<m) {
+ start = n;
+ while(n<m && r[n]!='\n')
+ n++;
+ Bprint(b, "%.*S", n-start, r+start);
+ if(n<m) {
+ Bputc(b, 0xff); // \n in tag becomes 0xff byte (invalid UTF)
+ n++;
+ }
+ }
+ Bprint(b, "\n");
if(dumped){
q0 = 0;
q1 = t->file->nc;
@@ -639,6 +646,10 @@
if(l == nil)
goto Rescue2;
l[Blinelen(b)-1] = 0;
+ /* convert 0xff in multiline tag back to \n */
+ for(i=0; l[i]!=0; i++)
+ if((uchar)l[i] == 0xff)
+ l[i] = '\n';
r = bytetorune(l+5*12, &nr);
ns = -1;
for(n=0; n<nr; n++){
diff -r d8b6a8706f51 sys/src/cmd/acme/text.c
--- a/sys/src/cmd/acme/text.c Mon Sep 07 19:32:50 2020 -0700
+++ b/sys/src/cmd/acme/text.c Thu Sep 17 17:12:35 2020 -0500
@@ -1411,7 +1411,7 @@
Rune *r;
uint n;
- if(org>0 && !exact){
+ if(org>0 && !exact && textreadc(t, org-1) != '\n'){
/* org is an estimate of the char posn; find a newline */
/* don't try harder than 256 chars */
for(i=0; i<256 && org<t->file->nc; i++){
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] acme patches from semi-recent changes in plan9port
2020-09-17 22:19 acme patches from semi-recent changes in plan9port Xiao-Yong Jin
@ 2020-09-20 5:25 ` ori
2020-09-29 5:48 ` Xiao-Yong Jin
0 siblings, 1 reply; 3+ messages in thread
From: ori @ 2020-09-20 5:25 UTC (permalink / raw)
To: 9front
> List of git commit from plan9port,
>
> 4650064a acme: scale window bodies on resize, not including tag space
> d28913a9 acme: save/restore multiline tags in Dump/Load
> d2df5d6c acme: fix crash in X |cat with multiple windows
> 3d6e5cb5 acme: preserve window position and selection during Get
>
Looks good to me, will test tomorrow and commit.
For next time, I think it'd be easier to review
if the diff was split into the original patches.
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] acme patches from semi-recent changes in plan9port
2020-09-20 5:25 ` [9front] " ori
@ 2020-09-29 5:48 ` Xiao-Yong Jin
0 siblings, 0 replies; 3+ messages in thread
From: Xiao-Yong Jin @ 2020-09-29 5:48 UTC (permalink / raw)
To: 9front
Ori, the changeset 7976: cdfeb0811a87 you committed has extra changes that are not part of what I sent. Those for the scrolling were reverted by cinap with changeset 7902: a43c3e5624da.
> On Sep 20, 2020, at 12:25 AM, ori@eigenstate.org wrote:
>
>> List of git commit from plan9port,
>>
>> 4650064a acme: scale window bodies on resize, not including tag space
>> d28913a9 acme: save/restore multiline tags in Dump/Load
>> d2df5d6c acme: fix crash in X |cat with multiple windows
>> 3d6e5cb5 acme: preserve window position and selection during Get
>>
>
> Looks good to me, will test tomorrow and commit.
>
> For next time, I think it'd be easier to review
> if the diff was split into the original patches.
>
> Thanks!
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-29 5:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 22:19 acme patches from semi-recent changes in plan9port Xiao-Yong Jin
2020-09-20 5:25 ` [9front] " ori
2020-09-29 5:48 ` Xiao-Yong Jin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).