From: nicolagi@sdf.org
To: 9front@9front.org
Subject: [9front] [PATCH] vdiff: assorted changes to share
Date: Sun, 25 Jul 2021 12:37:41 +0100 [thread overview]
Message-ID: <3A0D4B499E5045016D1455C2B65344F4@sdf.org> (raw)
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;
next reply other threads:[~2021-07-25 11:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-25 11:37 nicolagi [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3A0D4B499E5045016D1455C2B65344F4@sdf.org \
--to=nicolagi@sdf.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).