9front - general discussion about 9front
 help / color / mirror / Atom feed
* Re: [9front] [PATCH] vdiff: assorted changes to share
@ 2021-08-02 17:22 nicolagi
  2021-08-06 16:37 ` phil9
  0 siblings, 1 reply; 6+ messages in thread
From: nicolagi @ 2021-08-02 17:22 UTC (permalink / raw)
  To: 9front; +Cc: telephil9

Quoting unobe@cpan.org:
> Is phil9 open to taking all, or at least some, of your patches?  Have
> you reached out to him?

I haven't; I assumed he and anyone who may have any interest in the
changes would be on this list. Since I made more adjustments since the
initial post I forked the repository and published my commits¹ and I'm
copying in phil9 explicitly in this message, in case he has any interest
in applying some or all of those changes.

¹ https://github.com/nicolagi/vdiff/commits/main


^ permalink raw reply	[flat|nested] 6+ messages in thread
* [9front] [PATCH] vdiff: assorted changes to share
@ 2021-07-25 11:37 nicolagi
  2021-07-27 23:12 ` nicolagi
  0 siblings, 1 reply; 6+ messages in thread
From: nicolagi @ 2021-07-25 11:37 UTC (permalink / raw)
  To: 9front

Hi,

yesterday I discovered telephil9's vdiff program on shithub and love it.
I made a few changes which may perhaps be useful to others:

* Add scroll via scrollbar (acme/sam like behavior).

* Quit by pressing 'q' besides ESC.  (I usually keep left hand on
keyboard, right hand on mouse, so it's handy.)

* Make it compile and work in plan9port too (I will most often use
vdiff on Linux...)

* Make it detect the file name to plumb when the diff is in Linux git
form (a/file b/file) (the heuristic can certainly be improved...  but
I doubt there are many repos with a "b" subdirectory).

* Scrollwheel scroll by 1 instead of 10 -- personal preference here I
guess.  But I finally found out why I can't use the scrollwheel on
9front haha, I just have to change the scroll step in the programs I
use.  :-)

Thanks to telephil9 for vdiff.  Before finding it, I used a small
program of mine to add plumbable addresses next to each diff hunk so
e.g.

	@@ -36,7 +45,7 @@

becomes

	@@ -36,7 +45,7 @@ dp.go:45

but vdiff is much better!

Cheers,

Nicola

---
diff d7a39b5d1ab703d248085130253db071f610795f 231f8ac5b833a88d4b25b8584ad940cfb28abb21
--- a/vdiff.c	Tue Feb  9 08:16:49 2021
+++ b/vdiff.c	Sun Jul 25 12:19:50 2021
@@ -47,7 +47,7 @@
 Line **lines;
 int lsize;
 int lcount;
-const char ellipsis[] = "...";
+char ellipsis[] = "...";
 
 void
 drawline(Rectangle r, Line *l)
@@ -226,9 +226,10 @@
 		if(s==nil)
 			break;
 		l = parseline(f, n, s);
-		if(l->t == Lfile && l->s[0] == '+')
+		if(l->t == Lfile && l->s[0] == '+'){
 			f = l->s+4;
-		else if(l->t == Lsep)
+			if(strncmp(f, "b/", 2)==0) f += 2;
+		}else if(l->t == Lsep)
 			n = lineno(l->s);
 		else if(l->t == Ladd || l->t == Lnone)
 			++n;
@@ -245,7 +246,29 @@
 void
 plumb(char *f, int l)
 {
-	USED(l);
+#ifdef unix
+	/*
+	In plan9port libplumb depends on lib9pclient which depends on libthread.
+	Just invoke plumb(1) on plan9port instead of migrating vdiff to libthread.
+	*/
+	pid_t pid = fork();
+	if(pid==-1)
+		fprint(2, "fork failed");
+	else if(pid>0)
+		free(wait());
+	else{
+		char addr[300]={0};
+		char *argv[7];
+		int i = 0;
+		snprint(addr, sizeof addr, "%s:%d", f, l);
+		argv[i++] = "plumb";
+		argv[i++] = "-s"; argv[i++] = "vdiff";
+		argv[i++] = "-d"; argv[i++] = "edit";
+		argv[i++] = addr;
+		argv[i++] = nil;
+		exec("plumb", argv);
+	}
+#else
 	int fd;
 	char wd[256], addr[300]={0};
 
@@ -256,6 +279,7 @@
 	snprint(addr, sizeof addr, "%s:%d", f, l);
 	plumbsendtext(fd, "vdiff", "edit", wd, addr);
 	close(fd);
+#endif
 }
 
 void
@@ -274,17 +298,39 @@
 		e = event(&ev);
 		switch(e){
 		case Emouse:
+			if(ev.mouse.buttons&4 && ptinrect(ev.mouse.xy, scrollr)){
+				n = (ev.mouse.xy.y - scrollr.min.y) / lineh;
+				if(n<lcount-offset){
+					scroll(n);
+				} else {
+					scroll(lcount-offset);
+				}
+				break;
+			}
+			if(ev.mouse.buttons&1 && ptinrect(ev.mouse.xy, scrollr)){
+				n = (ev.mouse.xy.y - scrollr.min.y) / lineh;
+				if(-n<lcount-offset){
+					scroll(-n);
+				} else {
+					scroll(-lcount+offset);
+				}
+				break;
+			}
+
 			if(ev.mouse.buttons&4){
 				n = indexat(ev.mouse.xy);
 				if(n>=0 && lines[n+offset]->f != nil)
 					plumb(lines[n+offset]->f, lines[n+offset]->l);
 			}else if(ev.mouse.buttons&8)
-				scroll(-10);
+				scroll(-1);
 			else if(ev.mouse.buttons&16)
-				scroll(10);
+				scroll(1);
 			break;
 		case Ekeyboard:
 			switch(ev.kbdc){
+			case 'q':
+				goto End;
+				break;
 			case Kdel:
 				goto End;
 				break;


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-10  9:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 17:22 [9front] [PATCH] vdiff: assorted changes to share nicolagi
2021-08-06 16:37 ` phil9
2021-08-09 20:44   ` Nicola Girardi
  -- strict thread matches above, loose matches on Subject: below --
2021-07-25 11:37 nicolagi
2021-07-27 23:12 ` nicolagi
2021-07-30 21:22   ` unobe

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).