* [PATCH] acme: add log file in acme root directory
@ 2020-06-05 3:28 Fazlul Shahriar
2020-06-05 17:48 ` [9front] " ori
0 siblings, 1 reply; 6+ messages in thread
From: Fazlul Shahriar @ 2020-06-05 3:28 UTC (permalink / raw)
To: 9front
Hi,
This patch is copied from plan9port acme, with minor fixes. This
should allow greater compatibility with acme clients in the
wild. The changes are from the following commits:
https://github.com/9fans/plan9port/commit/4a3fb87264f8bc03fc62f00ef335056f30d18023
https://github.com/9fans/plan9port/commit/45f8ba54143323f08a21343633764caa59aa3ea3
https://github.com/9fans/plan9port/commit/fdf6ef333705c844bcf3ccf2f93b2773f1a6aa41
diff -r ff6b294d07a9 sys/man/4/acme
--- a/sys/man/4/acme Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/man/4/acme Thu Jun 04 23:17:01 2020 -0400
@@ -89,7 +89,7 @@
The window is created if necessary, but not until text is actually written.
.TP
.B consctl
-Is an empty unwritable file present only for compatibility; there is no way
+is an empty unwritable file present only for compatibility; there is no way
to turn off `echo', for example, under
.IR acme .
.TP
@@ -111,8 +111,33 @@
is an empty file, writable without effect, present only for compatibility with
.BR rio .
.TP
+.B log
+reports a log of window operations since the opening of the
+.B log
+file.
+Each line describes a single operation using three fields separated by single spaces:
+the decimal window ID, the operation, and the window name.
+Reading from
+.B log
+blocks until there is an operation to report, so reading the file
+can be used to monitor editor activity and react to changes.
+The reported operations are
+.L new
+(window creation),
+.L zerox
+(window creation via zerox),
+.LR get ,
+.LR put ,
+.L del
+(window deletion), and
+.L focus
+(window focus change).
+The window name can be the empty string; in particular it is empty in
+.L new
+log entries corresponding to windows created by external programs.
+.TP
.B new
-A directory analogous to the numbered directories
+is a directory analogous to the numbered directories
.RI ( q.v. ).
Accessing any
file in
diff -r ff6b294d07a9 sys/src/cmd/acme/acme.c
--- a/sys/src/cmd/acme/acme.c Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/acme.c Thu Jun 04 23:17:01 2020 -0400
@@ -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);
}
}
diff -r ff6b294d07a9 sys/src/cmd/acme/dat.h
--- a/sys/src/cmd/acme/dat.h Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/dat.h Thu Jun 04 23:17:01 2020 -0400
@@ -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
{
diff -r ff6b294d07a9 sys/src/cmd/acme/exec.c
--- a/sys/src/cmd/acme/exec.c Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/exec.c Thu Jun 04 23:17:01 2020 -0400
@@ -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);
}
diff -r ff6b294d07a9 sys/src/cmd/acme/fsys.c
--- a/sys/src/cmd/acme/fsys.c Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/fsys.c Thu Jun 04 23:17:01 2020 -0400
@@ -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, }
};
diff -r ff6b294d07a9 sys/src/cmd/acme/logf.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/src/cmd/acme/logf.c Thu Jun 04 23:17:01 2020 -0400
@@ -0,0 +1,202 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <thread.h>
+#include <cursor.h>
+#include <mouse.h>
+#include <keyboard.h>
+#include <frame.h>
+#include <fcall.h>
+#include <plumb.h>
+#include <libsec.h>
+#include "dat.h"
+#include "fns.h"
+
+// State for global log file.
+typedef struct Log Log;
+struct Log
+{
+ QLock lk;
+ Rendez r;
+
+ vlong start; // msg[0] corresponds to 'start' in the global sequence of events
+
+ // queued events (nev=entries in ev, mev=capacity of p)
+ char **ev;
+ int nev;
+ int mev;
+
+ // open acme/put files that need to read events
+ Fid **f;
+ int nf;
+ int mf;
+
+ // active (blocked) reads waiting for events
+ Xfid **read;
+ int nread;
+ int mread;
+};
+
+static Log eventlog;
+
+void
+xfidlogopen(Xfid *x)
+{
+ qlock(&eventlog.lk);
+ if(eventlog.nf >= eventlog.mf) {
+ eventlog.mf = eventlog.mf*2;
+ if(eventlog.mf == 0)
+ eventlog.mf = 8;
+ eventlog.f = erealloc(eventlog.f, eventlog.mf*sizeof eventlog.f[0]);
+ }
+ eventlog.f[eventlog.nf++] = x->f;
+ x->f->logoff = eventlog.start + eventlog.nev;
+
+ qunlock(&eventlog.lk);
+}
+
+void
+xfidlogclose(Xfid *x)
+{
+ int i;
+
+ qlock(&eventlog.lk);
+ for(i=0; i<eventlog.nf; i++) {
+ if(eventlog.f[i] == x->f) {
+ eventlog.f[i] = eventlog.f[--eventlog.nf];
+ break;
+ }
+ }
+ qunlock(&eventlog.lk);
+}
+
+void
+xfidlogread(Xfid *x)
+{
+ char *p;
+ int i;
+ Fcall fc;
+
+ qlock(&eventlog.lk);
+ if(eventlog.nread >= eventlog.mread) {
+ eventlog.mread = eventlog.mread*2;
+ if(eventlog.mread == 0)
+ eventlog.mread = 8;
+ eventlog.read = erealloc(eventlog.read, eventlog.mread*sizeof eventlog.read[0]);
+ }
+ eventlog.read[eventlog.nread++] = x;
+
+ if(eventlog.r.l == nil)
+ eventlog.r.l = &eventlog.lk;
+ x->flushed = FALSE;
+ while(x->f->logoff >= eventlog.start+eventlog.nev && !x->flushed)
+ rsleep(&eventlog.r);
+
+ for(i=0; i<eventlog.nread; i++) {
+ if(eventlog.read[i] == x) {
+ eventlog.read[i] = eventlog.read[--eventlog.nread];
+ break;
+ }
+ }
+
+ if(x->flushed) {
+ qunlock(&eventlog.lk);
+ return;
+ }
+
+ i = x->f->logoff - eventlog.start;
+ p = estrdup(eventlog.ev[i]);
+ x->f->logoff++;
+ qunlock(&eventlog.lk);
+
+ fc.data = p;
+ fc.count = strlen(p);
+ respond(x, &fc, nil);
+ free(p);
+}
+
+void
+xfidlogflush(Xfid *x)
+{
+ int i;
+ Xfid *rx;
+
+ qlock(&eventlog.lk);
+ for(i=0; i<eventlog.nread; i++) {
+ rx = eventlog.read[i];
+ if(rx->tag == x->oldtag) {
+ rx->flushed = TRUE;
+ rwakeupall(&eventlog.r);
+ }
+ }
+ qunlock(&eventlog.lk);
+}
+
+/*
+ * add a log entry for op on w.
+ * expected calls:
+ *
+ * op == "new" for each new window
+ * - caller of coladd or makenewwindow responsible for calling
+ * xfidlog after setting window name
+ * - exception: zerox
+ *
+ * op == "zerox" for new window created via zerox
+ * - called from zeroxx
+ *
+ * op == "get" for Get executed on window
+ * - called from get
+ *
+ * op == "put" for Put executed on window
+ * - called from put
+ *
+ * op == "del" for deleted window
+ * - called from winclose
+ *
+ * op == "focus" for window focus change
+ * - called from mousethread
+ */
+void
+xfidlog(Window *w, char *op)
+{
+ int i, n;
+ vlong min;
+ File *f;
+ char *name;
+
+ qlock(&eventlog.lk);
+ if(eventlog.nev >= eventlog.mev) {
+ // Remove and free any entries that all readers have read.
+ min = eventlog.start + eventlog.nev;
+ for(i=0; i<eventlog.nf; i++) {
+ if(min > eventlog.f[i]->logoff)
+ min = eventlog.f[i]->logoff;
+ }
+ if(min > eventlog.start) {
+ n = min - eventlog.start;
+ for(i=0; i<n; i++)
+ free(eventlog.ev[i]);
+ eventlog.nev -= n;
+ eventlog.start += n;
+ memmove(eventlog.ev, eventlog.ev+n, eventlog.nev*sizeof eventlog.ev[0]);
+ }
+
+ // Otherwise grow.
+ if(eventlog.nev >= eventlog.mev) {
+ eventlog.mev = eventlog.mev*2;
+ if(eventlog.mev == 0)
+ eventlog.mev = 8;
+ eventlog.ev = erealloc(eventlog.ev, eventlog.mev*sizeof eventlog.ev[0]);
+ }
+ }
+ f = w->body.file;
+ name = runetobyte(f->name, f->nname);
+ if(name == nil)
+ name = estrdup("");
+ eventlog.ev[eventlog.nev++] = smprint("%d %s %s\n", w->id, op, name);
+ free(name);
+ if(eventlog.r.l == nil)
+ eventlog.r.l = &eventlog.lk;
+ rwakeupall(&eventlog.r);
+ qunlock(&eventlog.lk);
+}
diff -r ff6b294d07a9 sys/src/cmd/acme/look.c
--- a/sys/src/cmd/acme/look.c Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/look.c Thu Jun 04 23:17:01 2020 -0400
@@ -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;
diff -r ff6b294d07a9 sys/src/cmd/acme/mkfile
--- a/sys/src/cmd/acme/mkfile Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/mkfile Thu Jun 04 23:17:01 2020 -0400
@@ -15,6 +15,7 @@
exec.$O\
file.$O\
fsys.$O\
+ logf.$O\
look.$O\
regx.$O\
rows.$O\
diff -r ff6b294d07a9 sys/src/cmd/acme/rows.c
--- a/sys/src/cmd/acme/rows.c Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/rows.c Thu Jun 04 23:17:01 2020 -0400
@@ -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);
diff -r ff6b294d07a9 sys/src/cmd/acme/util.c
--- a/sys/src/cmd/acme/util.c Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/util.c Thu Jun 04 23:17:01 2020 -0400
@@ -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; ){
diff -r ff6b294d07a9 sys/src/cmd/acme/wind.c
--- a/sys/src/cmd/acme/wind.c Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/wind.c Thu Jun 04 23:17:01 2020 -0400
@@ -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;
diff -r ff6b294d07a9 sys/src/cmd/acme/xfid.c
--- a/sys/src/cmd/acme/xfid.c Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/src/cmd/acme/xfid.c Thu Jun 04 23:17:01 2020 -0400
@@ -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;
@@ -274,6 +283,9 @@
case Qindex:
xfidindexread(x);
return;
+ case Qlog:
+ xfidlogread(x);
+ return;
default:
warning(nil, "unknown qid %d\n", q);
break;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9front] [PATCH] acme: add log file in acme root directory
2020-06-05 3:28 [PATCH] acme: add log file in acme root directory Fazlul Shahriar
@ 2020-06-05 17:48 ` ori
2020-06-05 19:19 ` Fazlul Shahriar
0 siblings, 1 reply; 6+ messages in thread
From: ori @ 2020-06-05 17:48 UTC (permalink / raw)
To: fshahriar, 9front
> This patch is copied from plan9port acme, with minor fixes. This
> should allow greater compatibility with acme clients in the
> wild. The changes are from the following commits:
What acme clients in the wild are we talking about?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9front] [PATCH] acme: add log file in acme root directory
2020-06-05 17:48 ` [9front] " ori
@ 2020-06-05 19:19 ` Fazlul Shahriar
2020-06-05 21:23 ` ori
0 siblings, 1 reply; 6+ messages in thread
From: Fazlul Shahriar @ 2020-06-05 19:19 UTC (permalink / raw)
To: ori; +Cc: 9front
On Fri, Jun 05, 2020 at 10:48:20AM -0700, ori@eigenstate.org wrote:
> > This patch is copied from plan9port acme, with minor fixes. This
> > should allow greater compatibility with acme clients in the
> > wild. The changes are from the following commits:
>
> What acme clients in the wild are we talking about?
>
There is the one written by Russ:
https://godoc.org/9fans.net/go/acme/acmego
The language server client I'm working on:
https://github.com/fhs/acme-lsp
Also found these but there are probably others:
https://git.sr.ht/~mkhl/cmd/tree/master/acme/autoacme/main.go
https://github.com/ilanpillemer/acmecrystal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9front] [PATCH] acme: add log file in acme root directory
2020-06-05 19:19 ` Fazlul Shahriar
@ 2020-06-05 21:23 ` ori
2020-06-05 23:58 ` kvik
0 siblings, 1 reply; 6+ messages in thread
From: ori @ 2020-06-05 21:23 UTC (permalink / raw)
To: fshahriar, ori; +Cc: 9front
> There is the one written by Russ:
> https://godoc.org/9fans.net/go/acme/acmego
>
> The language server client I'm working on:
> https://github.com/fhs/acme-lsp
>
> Also found these but there are probably others:
> https://git.sr.ht/~mkhl/cmd/tree/master/acme/autoacme/main.go
> https://github.com/ilanpillemer/acmecrystal
Ah. It really feels like it should be merged with the event file,
but it's probably too late for that.
Oh well. It's probably worth keeping in sync with plan9port acme.
I don't personally have objectons; anyone else?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9front] [PATCH] acme: add log file in acme root directory
2020-06-05 21:23 ` ori
@ 2020-06-05 23:58 ` kvik
2020-06-06 0:03 ` hiro
0 siblings, 1 reply; 6+ messages in thread
From: kvik @ 2020-06-05 23:58 UTC (permalink / raw)
To: 9front
Not a big fan of the particular interface either,
but it is what it is; I'm alright with it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9front] [PATCH] acme: add log file in acme root directory
2020-06-05 23:58 ` kvik
@ 2020-06-06 0:03 ` hiro
0 siblings, 0 replies; 6+ messages in thread
From: hiro @ 2020-06-06 0:03 UTC (permalink / raw)
To: 9front
this is the only piece of software still maintained by old bell-labs dudes.
we're downstream here and that's no big deal, if their patches are too
much of a mess it will create the sufficient pressure to write yet
another editor (one that is better integrated into rio)
On 6/5/20, kvik@a-b.xyz <kvik@a-b.xyz> wrote:
> Not a big fan of the particular interface either,
> but it is what it is; I'm alright with it.
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-06-06 0:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-05 3:28 [PATCH] acme: add log file in acme root directory Fazlul Shahriar
2020-06-05 17:48 ` [9front] " ori
2020-06-05 19:19 ` Fazlul Shahriar
2020-06-05 21:23 ` ori
2020-06-05 23:58 ` kvik
2020-06-06 0:03 ` hiro
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).