9front - general discussion about 9front
 help / color / mirror / Atom feed
* [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

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

Quoth nicolagi@sdf.org:
> * 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.  :-)

Actually mousescrollsize() seems the way to go here; I've updated my
copy of vdiff to use it.  That helper is used in acme, but not in sam
nor in rio (unless shift is down when using the scrollwheel).  AFAICT
from plan9-4e sources, mousescrollsize() is honored in rio there.


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

* Re: [9front] [PATCH] vdiff: assorted changes to share
  2021-07-27 23:12 ` nicolagi
@ 2021-07-30 21:22   ` unobe
  0 siblings, 0 replies; 6+ messages in thread
From: unobe @ 2021-07-30 21:22 UTC (permalink / raw)
  To: 9front

Quoth nicolagi@sdf.org:
> Quoth nicolagi@sdf.org:
> > * 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.  :-)
> 
> Actually mousescrollsize() seems the way to go here; I've updated my
> copy of vdiff to use it.  That helper is used in acme, but not in sam
> nor in rio (unless shift is down when using the scrollwheel).  AFAICT
> from plan9-4e sources, mousescrollsize() is honored in rio there.
> 

Is phil9 open to taking all, or at least some, of your patches?  Have
you reached out to him?


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

* Re: [9front] [PATCH] vdiff: assorted changes to share
  2021-08-06 16:37 ` phil9
@ 2021-08-09 20:44   ` Nicola Girardi
  0 siblings, 0 replies; 6+ messages in thread
From: Nicola Girardi @ 2021-08-09 20:44 UTC (permalink / raw)
  To: phil9; +Cc: 9front

Hello,

On Fri, Aug 06, 2021 at 06:37:10PM +0200, phil9 wrote:
> hi,
> 
> Thanks for the patches.
> Sorry for the late reply I was first on vacation and then had no more
> internet...

np at all!

> Anyway, I had applied (or reimplemented) most of the patches except
> for the p9p stuff that i cannot test and do not want to support (also,

Yep, no problem. Kudos to you for switching to 9front full time! IIRC
you have a redditfs in your GitHub, p9p based, so I think you used to be
a p9p user...

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

* Re: [9front] [PATCH] vdiff: assorted changes to share
  2021-08-02 17:22 nicolagi
@ 2021-08-06 16:37 ` phil9
  2021-08-09 20:44   ` Nicola Girardi
  0 siblings, 1 reply; 6+ messages in thread
From: phil9 @ 2021-08-06 16:37 UTC (permalink / raw)
  To: nicolagi; +Cc: nedmail,

hi,

Thanks for the patches.
Sorry for the late reply I was first on vacation and then had no more
internet...
Anyway, I had applied (or reimplemented) most of the patches except
for the p9p stuff that i cannot test and do not want to support (also,
I remember coordinates being 0,0 based in p9p, so you'll have to ifdef
that part too).
I'll also add the new ones (empty diff and mousescrollsize()) once my
internet is back.

cheers
--phil


On Mon, Aug 2, 2021 at 7:22 PM <nicolagi@sdf.org> wrote:
>
> 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

* 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

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-07-25 11:37 [9front] [PATCH] vdiff: assorted changes to share nicolagi
2021-07-27 23:12 ` nicolagi
2021-07-30 21:22   ` unobe
2021-08-02 17:22 nicolagi
2021-08-06 16:37 ` phil9
2021-08-09 20:44   ` Nicola Girardi

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