shithub: riscv

Download patch

ref: d2be4787c6e78df1a0fec1f6fdc75a616ecc1e1e
parent: e46000f076b3b5389b60f4497c8b40c203202d84
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jun 6 15:05:00 EDT 2020

acme: import event log from plan9port (thanks fshahriar)

Based off the following 3 commits:

	4a3fb87264f8bc03fc62f00ef335056f30d18023
	45f8ba54143323f08a21343633764caa59aa3ea3
	fdf6ef333705c844bcf3ccf2f93b2773f1a6aa41

Reading /mnt/acme/log reports a log of window create,
put, focus, and delete events, as they happen. It blocks
until the next event is available.

Example log output:

	8 new /Users/rsc/foo.go
	8 put /Users/rsc/foo.go
	8 del /Users/rsc/foo.go

This lets acme-aware programs react to file writes, for example
compiling code, running a test, or updating an import block.

--- a/sys/src/cmd/acme/acme.c
+++ b/sys/src/cmd/acme/acme.c
@@ -258,6 +258,7 @@
 	winsettag(w);
 	textscrdraw(&w->body);
 	textsetselect(&w->tag, w->tag.file->nc, w->tag.file->nc);
+	xfidlog(w, "new");
 }
 
 char *oknotes[] ={
@@ -487,6 +488,12 @@
 			m = mousectl->Mouse;
 			qlock(&row);
 			t = rowwhich(&row, m.xy);
+
+			if((t!=mousetext && t!=nil && t->w!=nil) &&
+				(mousetext==nil || mousetext->w==nil || t->w->id!=mousetext->w->id)) {
+				xfidlog(t->w, "focus");
+			}
+
 			if(t!=mousetext && mousetext!=nil && mousetext->w!=nil){
 				winlock(mousetext->w, 'M');
 				mousetext->eq0 = ~0;
@@ -773,6 +780,7 @@
 		recvp(cnewwindow);
 		w = makenewwindow(nil);
 		winsettag(w);
+		xfidlog(w, "new");
 		sendp(cnewwindow, w);
 	}
 }
--- a/sys/src/cmd/acme/dat.h
+++ b/sys/src/cmd/acme/dat.h
@@ -8,6 +8,7 @@
 	Qeditout,
 	Qindex,
 	Qlabel,
+	Qlog,
 	Qnew,
 
 	QWaddr,
@@ -396,6 +397,7 @@
 	Mntdir	*mntdir;
 	int		nrpart;
 	uchar	rpart[UTFmax];
+	vlong	logoff;	// for putlog
 };
 
 
@@ -408,7 +410,6 @@
 	Fid	*f;
 	uchar	*buf;
 	int	flushed;
-
 };
 
 void		xfidctl(void *);
@@ -423,6 +424,10 @@
 void		xfidindexread(Xfid*);
 void		xfidutfread(Xfid*, Text*, uint, int);
 int		xfidruneread(Xfid*, Text*, uint, uint);
+void		xfidlogopen(Xfid*);
+void		xfidlogread(Xfid*);
+void		xfidlogflush(Xfid*);
+void		xfidlog(Window*, char*);
 
 struct Reffont
 {
--- a/sys/src/cmd/acme/exec.c
+++ b/sys/src/cmd/acme/exec.c
@@ -297,10 +297,14 @@
 newcol(Text *et, Text*, Text*, int, int, Rune*, int)
 {
 	Column *c;
+	Window *w;
 
 	c = rowadd(et->row, nil, -1);
-	if(c)
-		winsettag(coladd(c, nil, nil, -1));
+	if(c) {
+		w = coladd(c, nil, nil, -1);
+		winsettag(w);
+		xfidlog(w, "new");
+	}
 }
 
 void
@@ -496,6 +500,7 @@
 		nw = coladd(t->w->col, nil, t->w, -1);
 		/* ugly: fix locks so w->unlock works */
 		winlock1(nw, t->w->owner);
+		xfidlog(nw, "zerox");
 	}
 	if(locked)
 		winunlock(t->w);
@@ -559,6 +564,7 @@
 		textsetselect(&u->w->tag, u->w->tag.file->nc, u->w->tag.file->nc);
 		textscrdraw(u);
 	}
+	xfidlog(w, "get");
 }
 
 void
@@ -695,6 +701,7 @@
 	}
 	namer = bytetorune(name, &nname);
 	putfile(f, 0, f->nc, namer, nname);
+	xfidlog(w, "put");
 	free(name);
 }
 
--- a/sys/src/cmd/acme/fsys.c
+++ b/sys/src/cmd/acme/fsys.c
@@ -69,6 +69,7 @@
 	{ "editout",	QTFILE,	Qeditout,	0200 },
 	{ "index",		QTFILE,	Qindex,	0400 },
 	{ "label",		QTFILE,	Qlabel,	0600 },
+	{ "log",		QTFILE,	Qlog,	0400 },
 	{ "new",		QTDIR,	Qnew,	0500|DMDIR },
 	{ nil, }
 };
--- a/sys/src/cmd/acme/look.c
+++ b/sys/src/cmd/acme/look.c
@@ -233,6 +233,7 @@
 	winsettag(w);
 	textscrdraw(&w->body);
 	textsetselect(&w->tag, w->tag.file->nc, w->tag.file->nc);
+	xfidlog(w, "new");
 }
 
 int
@@ -668,6 +669,7 @@
 		}else
 			for(i=0; i < NINDENT; i++)
 				w->indent[i] = globalindent[i];
+		xfidlog(w, "new");
 	}
 	if(e->a1 == e->a0)
 		eval = FALSE;
@@ -697,6 +699,7 @@
 	int na, nf;
 	Expand e;
 	Runestr rs;
+	Window *w;
 
 	getarg(argt, FALSE, TRUE, &a, &na);
 	if(a){
@@ -708,8 +711,11 @@
 	for(ndone=0; ; ndone++){
 		a = findbl(arg, narg, &na);
 		if(a == arg){
-			if(ndone==0 && et->col!=nil)
-				winsettag(coladd(et->col, nil, nil, -1));
+			if(ndone==0 && et->col!=nil) {
+				w = coladd(et->col, nil, nil, -1);
+				winsettag(w);
+				xfidlog(w, "new");
+			}
 			break;
 		}
 		nf = narg-na;
--- a/sys/src/cmd/acme/mkfile
+++ b/sys/src/cmd/acme/mkfile
@@ -15,6 +15,7 @@
 	exec.$O\
 	file.$O\
 	fsys.$O\
+	logf.$O\
 	look.$O\
 	regx.$O\
 	rows.$O\
--- a/sys/src/cmd/acme/rows.c
+++ b/sys/src/cmd/acme/rows.c
@@ -697,6 +697,7 @@
 			q0 = q1 = 0;
 		textshow(&w->body, q0, q1, 1);
 		w->maxlines = min(w->body.nlines, max(w->maxlines, w->body.maxlines));
+		xfidlog(w, "new");
 	}
 	Bterm(b);
 	fbuffree(buf);
--- a/sys/src/cmd/acme/util.c
+++ b/sys/src/cmd/acme/util.c
@@ -77,6 +77,7 @@
 		w = coladd(row.col[row.ncol-1], nil, nil, -1);
 		w->filemenu = FALSE;
 		winsetname(w, r, n);
+		xfidlog(w, "new");
 	}
 	free(r);
 	for(i=nincl; --i>=0; ){
--- a/sys/src/cmd/acme/wind.c
+++ b/sys/src/cmd/acme/wind.c
@@ -313,6 +313,7 @@
 	int i;
 
 	if(decref(w) == 0){
+		xfidlog(w, "del");
 		windirfree(w);
 		textclose(&w->tag);
 		textclose(&w->body);
@@ -633,7 +634,7 @@
 }
 
 int
-winclean(Window *w, int conservative)	/* as it stands, conservative is always TRUE */
+winclean(Window *w, int conservative)
 {
 	if(w->isscratch || w->isdir)	/* don't whine if it's a guide file, error window, etc. */
 		return TRUE;
--- a/sys/src/cmd/acme/xfid.c
+++ b/sys/src/cmd/acme/xfid.c
@@ -63,6 +63,8 @@
 	Column *c;
 	Xfid *wx;
 
+	xfidlogflush(x);
+
 	/* search windows for matching tag */
 	qlock(&row);
 	for(j=0; j<row.ncol; j++){
@@ -98,9 +100,9 @@
 
 	w = x->f->w;
 	t = &w->body;
+	q = FILE(x->f->qid);
 	if(w){
 		winlock(w, 'E');
-		q = FILE(x->f->qid);
 		switch(q){
 		case QWaddr:
 			if(w->nopen[q]++ == 0){
@@ -179,6 +181,13 @@
 		}
 		winunlock(w);
 	}
+	else{
+		switch(q){
+		case Qlog:
+			xfidlogopen(x);
+			break;
+		}
+	}
 	fc.qid = x->f->qid;
 	fc.iounit = messagesize-IOHDRSZ;
 	x->f->open = TRUE;
@@ -273,6 +282,9 @@
 			break;
 		case Qindex:
 			xfidindexread(x);
+			return;
+		case Qlog:
+			xfidlogread(x);
 			return;
 		default:
 			warning(nil, "unknown qid %d\n", q);