shithub: Nail

Download patch

ref: 121863be9cb7553a35fc70d7b4472adc17910eed
parent: 8a141b2e876cae0532bcd09a8d439d61e3c8a2a7
author: Ori Bernstein <[email protected]>
date: Tue Nov 24 00:54:31 EST 2020

mbox: only redraw messages on changes

When the flags haven't changed, rerdawing just leads
to a jumping cursor. Don't do that.

--- a/mail.h
+++ b/mail.h
@@ -167,7 +167,6 @@
 void	winsetsel(Win*, int, int);
 
 /* messages */
-Mesg	*mblookupid(char*);
 Mesg	*mesglookup(char*, char*);
 Mesg	*mesgload(char*);
 Mesg	*mesgopen(char*, char*);
@@ -177,6 +176,7 @@
 void	mesgpath2name(char*, int, char*);
 int	mesgflagparse(char*, int*);
 Biobuf*	mesgopenbody(Mesg*);
+
 /* mailbox */
 void	mbredraw(Mesg*, int, int);
 
--- a/mbox.c
+++ b/mbox.c
@@ -311,15 +311,17 @@
 }
 
 static Mesg*
-change(char *name, char *digest)
+change(char *name, char *digest, int *cf)
 {
 	Mesg *m;
 	char *f;
+	int old;
 
 	if((m = mesglookup(name, digest)) == nil)
 		return nil;
 	if((f = rslurp(m, "flags", nil)) == nil)
 		return nil;
+	old = m->flags;
 	free(m->mflags);
 	m->mflags = f;
 	m->flags = 0;
@@ -326,6 +328,7 @@
 	if(strchr(m->mflags, 'd')) m->flags |= Fdel;
 	if(strchr(m->mflags, 's')) m->flags |= Fseen;
 	if(strchr(m->mflags, 'a')) m->flags |= Fresp;
+	*cf = (old != m->flags);
 	return m;
 }
 
@@ -791,7 +794,7 @@
 {
 	char *digest, *action;
 	Mesg *m, *r;
-	int ln, nr;
+	int ln, nr, cf;
 
 	digest = plumblookup(pm->attr, "digest");
 	action = plumblookup(pm->attr, "mailtype");
@@ -832,7 +835,7 @@
 		if((m = delete(pm->data, digest)) != nil)
 			mbredraw(m, 0, 0);
 	}else if(strcmp(action, "modify") == 0){
-		if((m = change(pm->data, digest)) != nil)
+		if((m = change(pm->data, digest, &cf)) != nil && cf)
 			mbredraw(m, 0, 0);
 	}
 }