acme: correct modified message after initial load; more detail in

message

http://codereview.appspot.com/123051
This commit is contained in:
Russ Cox 2009-09-25 01:43:54 -04:00
parent 1961ee8223
commit daea2c7d50
5 changed files with 29 additions and 14 deletions

View file

@ -19,7 +19,8 @@ void keyboardthread(void*);
void waitthread(void*);
void xfidallocthread(void*);
void newwindowthread(void*);
void plumbproc(void*);
void plumbproc(void*);
int timefmt(Fmt*);
Reffont **fontcache;
int nfontcache;
@ -127,6 +128,8 @@ threadmain(int argc, char *argv[])
fontnames[1] = estrdup(fontnames[1]);
quotefmtinstall();
fmtinstall('t', timefmt);
cputype = getenv("cputype");
objtype = getenv("objtype");
home = getenv("HOME");
@ -1067,3 +1070,14 @@ ismtpt(char *file)
n = strlen(mtpt);
return strncmp(file, mtpt, n) == 0 && ((n > 0 && mtpt[n-1] == '/') || file[n] == '/' || file[n] == 0);
}
int
timefmt(Fmt *f)
{
Tm *tm;
tm = localtime(va_arg(f->args, ulong));
return fmtprint(f, "%04d/%02d/%02d %02d:%02d:%02d",
tm->year+1900, tm->mon+1, tm->mday, tm->hour, tm->min, tm->sec);
}

View file

@ -134,7 +134,7 @@ struct File
Rune *name; /* name of associated file */
int nname; /* size of name */
uvlong qidpath; /* of file when read */
uint mtime; /* of file when read */
ulong mtime; /* of file when read */
int dev; /* of file when read */
int unread; /* file has not been read from disk */
int editclean; /* mark clean after edit command */
@ -210,7 +210,7 @@ void textfill(Text*);
void textframescroll(Text*, int);
void textinit(Text*, File*, Rectangle, Reffont*, Image**);
void textinsert(Text*, uint, Rune*, uint, int);
uint textload(Text*, uint, char*, int);
int textload(Text*, uint, char*, int);
Rune textreadc(Text*, uint);
void textredraw(Text*, Rectangle, Font*, Image*, int);
void textreset(Text*);

View file

@ -644,14 +644,14 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname)
d = dirstat(name);
if(d!=nil && runeeq(namer, nname, f->name, f->nname)){
/* f->mtime+1 because when talking over NFS it's often off by a second */
if(f->dev!=d->dev || f->qidpath!=d->qid.path || f->mtime+1<d->mtime){
f->dev = d->dev;
f->qidpath = d->qid.path;
f->mtime = d->mtime;
if(f->dev!=d->dev || f->qidpath!=d->qid.path || abs(f->mtime-d->mtime) > 1){
if(f->unread)
warning(nil, "%s not written; file already exists\n", name);
else
warning(nil, "%s modified%s%s since last read\n", name, d->muid[0]?" by ":"", d->muid);
warning(nil, "%s modified%s%s since last read\n\twas %t; now %t\n", name, d->muid[0]?" by ":"", d->muid, f->mtime, d->mtime);
f->dev = d->dev;
f->qidpath = d->qid.path;
f->mtime = d->mtime;
goto Rescue1;
}
}

View file

@ -754,7 +754,8 @@ openfile(Text *t, Expand *e)
w = makenewwindow(t);
t = &w->body;
winsetname(w, e->name, e->nname);
textload(t, 0, e->bname, 1);
if(textload(t, 0, e->bname, 1) >= 0)
t->file->unread = FALSE;
t->file->mod = FALSE;
t->w->dirty = FALSE;
winsettag(t->w);

View file

@ -188,7 +188,7 @@ textcolumnate(Text *t, Dirlist **dlp, int ndl)
}
}
uint
int
textload(Text *t, uint q0, char *file, int setqid)
{
Rune *rp;
@ -203,16 +203,16 @@ textload(Text *t, uint q0, char *file, int setqid)
error("text.load");
if(t->w->isdir && t->file->nname==0){
warning(nil, "empty directory name");
return 0;
return -1;
}
if(ismtpt(file)){
warning(nil, "will not open self mount point %s\n", file);
return 0;
return -1;
}
fd = open(file, OREAD);
if(fd < 0){
warning(nil, "can't open %s: %r\n", file);
return 0;
return -1;
}
d = dirfstat(fd);
if(d == nil){
@ -303,7 +303,7 @@ textload(Text *t, uint q0, char *file, int setqid)
Rescue:
close(fd);
return 0;
return -1;
}
uint