9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Chords, ^, _, ^B and scroll with mouse wheel in p9p sam
@ 2016-05-27 17:11 trebol55555
  2016-05-27 17:46 ` Mark Lee Smith
  0 siblings, 1 reply; 13+ messages in thread
From: trebol55555 @ 2016-05-27 17:11 UTC (permalink / raw)
  To: 9fans

flselect() must be changed in samterm/flayer.c to get the double click
selection working ok.


Anyone has hacked sam to use both the plumber and the pipe?

trebol.


diff -rpuN src/cmd/sam/cmd.c sam/cmd.c
--- src/cmd/sam/cmd.c	2016-04-18 19:07:22.000000000 +0100
+++ sam/cmd.c	2016-05-25 23:56:34.040909362 +0100
@@ -35,6 +35,8 @@ struct cmdtab cmdtab[]={
 	'>',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
 	'<',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
 	'|',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
+	'^',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
+	'_',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
 	'=',	0,	0,	0,	0,	aDot,	0,	linex,	eq_cmd,
 	'c'|0x100,0,	0,	0,	0,	aNo,	0,	wordx,	cd_cmd,
 	0,	0,	0,	0,	0,	0,	0,	0
@@ -76,7 +78,13 @@ inputc(void)

     Again:
 	nbuf = 0;
-	if(downloaded){
+	if(cmdbufpos > cmdbuf.nc && cmdbuf.nc > 0){
+		cmdbufpos = 0;
+		bufreset(&cmdbuf);
+	}
+	if(cmdbufpos < cmdbuf.nc && cmdbuf.nc > 0)
+		bufread(&cmdbuf, cmdbufpos++, &r, 1);
+	else if(downloaded){
 		while(termoutp == terminp){
 			cmdupdate();
 			if(patset)
diff -rpuN src/cmd/sam/sam.h sam/sam.h
--- src/cmd/sam/sam.h	2016-04-18 19:07:22.000000000 +0100
+++ sam/sam.h	2016-05-25 23:45:05.652931784 +0100
@@ -369,6 +369,8 @@ extern int	quitok;
 extern Address	addr;
 extern Buffer	snarfbuf;
 extern Buffer	plan9buf;
+extern Buffer	cmdbuf;
+extern int	cmdbufpos;
 extern List	file;
 extern List	tempfile;
 extern File	*cmd;
diff -rpuN src/cmd/sam/shell.c sam/shell.c
--- src/cmd/sam/shell.c	2016-04-18 19:07:22.000000000 +0100
+++ sam/shell.c	2016-05-25 23:46:25.262692361 +0100
@@ -6,6 +6,8 @@ extern	jmp_buf	mainloop;
 char	errfile[64];
 String	plan9cmd;	/* null terminated */
 Buffer	plan9buf;
+Buffer	cmdbuf;
+int	cmdbufpos;
 void	checkerrs(void);

 void
@@ -40,7 +42,7 @@ plan9(File *f, int type, String *s, int
 	}
 	if(type!='!' && pipe(pipe1)==-1)
 		error(Epipe);
-	if(type=='|')
+	if(type=='|' || type=='_')
 		snarf(f, addr.r.p1, addr.r.p2, &plan9buf, 1);
 	if((pid=fork()) == 0){
 		setname(f);
@@ -61,14 +63,14 @@ plan9(File *f, int type, String *s, int
 			}
 		}
 		if(type != '!') {
-			if(type=='<' || type=='|')
-				dup(pipe1[1], 1);
-			else if(type == '>')
+			if(type == '>')
 				dup(pipe1[0], 0);
+			else
+				dup(pipe1[1], 1);
 			close(pipe1[0]);
 			close(pipe1[1]);
 		}
-		if(type == '|'){
+		if(type == '|' || type == '_'){
 			if(pipe(pipe2) == -1)
 				exits("pipe");
 			if((pid = fork())==0){
@@ -100,7 +102,7 @@ plan9(File *f, int type, String *s, int
 			close(pipe2[0]);
 			close(pipe2[1]);
 		}
-		if(type=='<'){
+		if(type=='<' || type=='^'){
 			close(0);	/* so it won't read from terminal */
 			open("/dev/null", 0);
 		}
@@ -128,9 +130,14 @@ plan9(File *f, int type, String *s, int
 		writeio(f);
 		bpipeok = 0;
 		closeio((Posn)-1);
+	}else if(type == '^' || type == '_'){
+		int nulls;
+		close(pipe1[1]);
+		bufload(&cmdbuf, cmdbufpos, pipe1[0], &nulls);
+		close(pipe1[0]);
 	}
 	retcode = waitfor(pid);
-	if(type=='|' || type=='<')
+	if(type=='|' || type=='<' || type=='_' || type=='^')
 		if(retcode!=0)
 			warn(Wbadstatus);
 	if(downloaded)
diff -rpuN src/cmd/samterm/main.c samterm/main.c
--- src/cmd/samterm/main.c	2016-04-18 19:07:22.000000000 +0100
+++ samterm/main.c	2016-05-26 16:12:12.452556184 +0100
@@ -23,11 +23,8 @@ long	modified = 0;		/* strange lookahead
 char	hostlock = 1;
 char	hasunlocked = 0;
 int	maxtab = 8;
-int	chord;
 int	autoindent;

-#define chording 0	/* code here for reference but it causes deadlocks */
-
 void
 notifyf(void *a, char *msg)
 {
@@ -39,7 +36,7 @@ notifyf(void *a, char *msg)
 void
 threadmain(int argc, char *argv[])
 {
-	int i, got, scr, w;
+	int i, got, scr, chord, w;
 	Text *t;
 	Rectangle r;
 	Flayer *nwhich;
@@ -85,6 +82,7 @@ threadmain(int argc, char *argv[])

 	got = 0;
 	if(protodebug) print("loop\n");
+	chord = 0;
 	for(;;got = waitforio()){
 		if(hasunlocked && RESIZED())
 			resize();
@@ -108,19 +106,32 @@ threadmain(int argc, char *argv[])
 				continue;
 			}
 			nwhich = flwhich(mousep->xy);
-			scr = which && ptinrect(mousep->xy, which->scroll);
+			scr = which && (ptinrect(mousep->xy, which->scroll) ||
+				mousep->buttons&(8|16));
 			if(mousep->buttons)
 				flushtyping(1);
-			if(chording && chord==1 && !mousep->buttons)
+			if((mousep->buttons&1)==0)
 				chord = 0;
-			if(chording && chord)
+			if(chord && which && which==nwhich){
 				chord |= mousep->buttons;
-			else if(mousep->buttons&1){
+				t = (Text *)which->user1;
+				if(!t->lock){
+					w = which-t->l;
+					if(chord&2){
+						cut(t, w, 1, 1);
+						chord &= ~2;
+					}
+					if(chord&4){
+						paste(t, w);
+						chord &= ~4;
+					}
+				}
+			}else if(mousep->buttons&(1|8)){
 				if(nwhich){
 					if(nwhich!=which)
 						current(nwhich);
 					else if(scr)
-						scroll(which, 1);
+						scroll(which, (mousep->buttons&8) ? 4 : 1);
 					else{
 						t=(Text *)which->user1;
 						if(flselect(which)){
@@ -137,27 +148,14 @@ threadmain(int argc, char *argv[])
 					scroll(which, 2);
 				else
 					menu2hit();
-			}else if((mousep->buttons&4)){
+			}else if(mousep->buttons&(4|16)){
 				if(scr)
-					scroll(which, 3);
+					scroll(which, (mousep->buttons&16) ? 5 : 3);
 				else
 					menu3hit();
 			}
 			mouseunblock();
 		}
-		if(chording && chord){
-			t = (Text*)which->user1;
-			if(!t->lock && !hostlock){
-				w = which-t->l;
-				if(chord&2){
-					cut(t, w, 1, 1);
-					chord &= ~2;
-				}else if(chord&4){
-					paste(t, w);
-					chord &= ~4;
-				}
-			}
-		}
 	}
 }

@@ -497,6 +495,7 @@ flushtyping(int clearesc)
 #define	CUT	(Kcmd+'x')
 #define	COPY	(Kcmd+'c')
 #define	PASTE	(Kcmd+'v')
+#define	Kstx	0x02

 int
 nontypingkey(int c)
@@ -512,6 +511,7 @@ nontypingkey(int c)
 	case PAGEUP:
 	case RIGHTARROW:
 	case SCROLLKEY:
+	case Kstx:
 		return 1;
 	}
 	if(c >= Kcmd)
@@ -669,6 +669,15 @@ type(Flayer *l, int res)	/* what a blood
 				}
 			}
 		}
+	}else if(c == Kstx){
+		t = &cmd;
+		for(l=t->l; l->textfn==0; l++)
+			;
+		current(l);
+		flushtyping(0);
+		a = t->rasp.nrunes;
+		flsetselect(l, a, a);
+		center(l, a);
 	}else{
 		if(c==ESC && typeesc>=0){
 			l->p0 = typeesc;
diff -rpuN src/cmd/samterm/scroll.c samterm/scroll.c
--- src/cmd/samterm/scroll.c	2016-04-18 19:07:22.000000000 +0100
+++ samterm/scroll.c	2016-05-26 02:07:31.922977720 +0100
@@ -115,7 +115,7 @@ scroll(Flayer *l, int but)
 	draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
 	do{
 		oin = in;
-		in = abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2;
+		in = (but > 3) || (but == 2) || abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2;
 		if(oin && !in)
 			scrunmark(l, r);
 		if(in){
@@ -126,9 +126,7 @@ scroll(Flayer *l, int but)
 				my = s.min.y;
 			if(my >= s.max.y)
 				my = s.max.y;
-			if(!eqpt(mousep->xy, Pt(x, my)))
-				moveto(mousectl, Pt(x, my));
-			if(but == 1){
+			if(but == 1 || but == 4){
 				p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my));
 				rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
 				y = rt.min.y;
@@ -136,7 +134,7 @@ scroll(Flayer *l, int but)
 				y = my;
 				if(y > s.max.y-2)
 					y = s.max.y-2;
-			}else if(but == 3){
+			}else if(but == 3 || but == 5){
 				p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my));
 				rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
 				y = rt.min.y;
@@ -147,19 +145,21 @@ scroll(Flayer *l, int but)
 				scrmark(l, r);
 			}
 		}
-	}while(button(but));
+	}while(but <= 3 && button(but));
 	if(in){
 		h = s.max.y-s.min.y;
 		scrunmark(l, r);
 		p0 = 0;
-		if(but == 1)
+		if(but == 1 || but == 4){
+			but = 1;
 			p0 = (long)(my-s.min.y)/l->f.font->height+1;
-		else if(but == 2){
+		}else if(but == 2){
 			if(tot > 1024L*1024L)
 				p0 = ((tot>>10)*(y-s.min.y)/h)<<10;
 			else
 				p0 = tot*(y-s.min.y)/h;
-		}else if(but == 3){
+		}else if(but == 3 || but == 5){
+			but = 3;
 			p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my));
 			if(p0 > tot)
 				p0 = tot;
diff -rpuN src/cmd/samterm/flayer.c samterm/flayer.c
--- src/cmd/samterm/flayer.c	2016-05-27 17:46:30.431425669 +0100
+++ samterm/flayer.c	2016-04-18 19:07:22.000000000 +0100
@@ -254,21 +254,18 @@ fldelete(Flayer *l, long p0, long p1)
 int
 flselect(Flayer *l)
 {
-	int ret;
 	if(l->visible!=All)
 		flupfront(l);
-	frselect(&l->f, mousectl);
-	ret = 0;
-	if(l->f.p0==l->f.p1){
-		if(mousep->msec-l->click<Clicktime && l->f.p0+l->origin==l->p0){
-			ret = 1;
+	if(l->f.p0==l->f.p1)
+		if(mousep->msec-l->click<Clicktime && l->f.p0+l->origin==l->p0 &&
+			l->f.p0==frcharofpt(&l->f, mousep->xy)){
 			l->click = 0;
-		}else
-			l->click = mousep->msec;
-	}else
-		l->click = 0;
+			return 1;
+		}
+	l->click = mousep->msec;
+	frselect(&l->f, mousectl);
 	l->p0 = l->f.p0+l->origin, l->p1 = l->f.p1+l->origin;
-	return ret;
+	return 0;
 }

 void




^ permalink raw reply	[flat|nested] 13+ messages in thread
* [9fans] Chords, ^, _, ^B and scroll with mouse wheel in p9p sam
@ 2016-05-31  1:34 trebol55555
  0 siblings, 0 replies; 13+ messages in thread
From: trebol55555 @ 2016-05-31  1:34 UTC (permalink / raw)
  To: 9fans

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 2942 bytes --]

I posted wrong code for Plan 9 by error.

The E script:
-----------------
#!/bin/rc

files=()
dest=()

if(~ $#* 0){
	echo usage: E file ... >[1=2]
	exit usage
}

for(i)
	switch($i){
	case /*
		files = ( $files $i )
	case *
		files = ( $files `{cleanname `{pwd}^/$i} )
	}

if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user
if not if(test -f /srv/sam.$user) dest = /srv/sam.$user
if not {
	switch($files){
	case *:*
		for(i in $files){
			fi = `{echo $i | sed 's/(.*):[^:]*/\1/'}
			ad = `{echo $i | sed 's/.*:([^:]*)/\1/'}
			plumb -d edit -a 'addr='$"ad'' $fi
		}
	case *
		plumb -d edit $files
	}
	exit
}

switch($files){
case *:*
	for(i in $files)
		echo $i | sed 's/^/B /;s/:(.*)$/\n\1/g' >> $dest
case *
	echo B $files >> $dest
}
-----------------

The plumb rules:

-----------------
# existing files, possibly tagged by line number, go to editor
type is text
data matches '([.a-zA-Z¡-￿0-9_/+\-]*[a-zA-Z¡-￿0-9_/+\-])('$addr')?'
arg isfile	$1
plumb start E $file:$3

## man index entries are synthesized
type is text
data matches '([a-zA-ZÀ-ʨ¡-￿0-9_-./+\-]+)\(([1-8])\)'
plumb start rc -c 'if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user; if not if(test -f /srv/sam.$user) dest = /srv/sam.$user; if not {man '$2' '$1' >[2=1] | plumb -i -d edit -a ''action=showdata filename=/man/'$1'('$2')''; exit}; {echo ''{}''; echo ''B ~~'$1'('$2')~~''; echo ''<man '$2' '$1' >[2=1]''} >>$dest'

# poor man's sam file browser
type is text
data matches '([.a-zA-Z¡-￿0-9_/\-;&$,'']+)'
arg isdir $0
plumb start rc -c 'if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user; if not if(test -f /srv/sam.$user) dest = /srv/sam.$user; if not {plumb -d edit '$dir'; exit}; cd '$dir'; DIR = `{pwd}; {echo ''{}''; echo B $DIR/~~samdir~~; echo '',<echo ~~''$DIR''~~; echo; echo ../;ls -pF ''$DIR''''; echo 0} >>/srv/sam.$user'

## poor man's sam exec in current file's cwd
type is text
data matches '(¤)([a-zA-ZÀ-ʨ¡-￿0-9_\-./\+^,()$:|#%<>*&'' ]+)'
plumb start rc -c 'if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user; if not if(test -f /srv/sam.$user) dest = /srv/sam.$user; if not {echo can''''t find sam server file >[1=2]; exit open}; {cd '$wdir'; {echo '$wdir' ¤'''$2'''; echo; {'$2'}; echo} >/tmp/sam_ecfcwd_$pid >[2=1]; {echo ''{}''; echo B '$wdir'^/~~cmd~~; echo ''$''; echo ''<cat /tmp/sam_ecfcwd_''$pid; echo ''!rm /tmp/sam_ecfcwd_''$pid} >>$dest}'
-----------------

I've tested it in 9front, and all works good. Of course you can delete
all the acme part if you don't use it.

Remember that you have to edit samterm/io.c to create always the pipe

	[...]
		hoststart();
		plumbstart();
		extstart();
	}

And in P9P you need to set the shell to rc in sam/unix.c
	#define SHNAME "rc"
	#define SHPATHNAME "/usr/local/plan9/bin/rc"
	
Or adapt the rules for sh...

trebol.




^ permalink raw reply	[flat|nested] 13+ messages in thread
* [9fans] Chords, ^, _, ^B and scroll with mouse wheel in p9p sam
@ 2016-05-30 16:35 trebol55555
  0 siblings, 0 replies; 13+ messages in thread
From: trebol55555 @ 2016-05-30 16:35 UTC (permalink / raw)
  To: 9fans

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 7892 bytes --]

> What would you think about moving the named pipe from samterm into sam?

Sorry for the delay, but I have had to put all this together...

I haven't studied the source so much, but it seams that sam communicates
with samterm (if not -d), and samterm flows the IO to and from it. The
pipe looks more like a "Plan B" in case the plumber is not available in
the machine where samterm is running. The programmer (R. Pike) didn't
implement a directory tree served like that of acme, because -I think-
he just did it in acme, acme is for him -III think- the new version
of the Plan 9 editor. He uses sam only for long distance connections
-IIIII think. The funny thing is that some people do not see this new
version of the editor as an improvement, but as a mess. But this is
always the same with editors, it's a matter of taste, until you can
write the perfect one (for you, only for you) you have to use some
editor, the less annoying to you, written by a good programmer to be
sure (or practically sure) that hours of your work are not going to the
trash can. The reason because I'm posting all these things about sam is
because it is becoming my "some good programmer's editor I'm going to
use by now", and other people can use my experience (or laugh at the
silliness of it), but I'm not expending much more time altering it. I
don't really like sam. I don't really like acme. I can't say I'll be
able to write something half as useful or well written as any of them,
but all that time is going to be employed in trying to do it.

Aaaany way, the pipe is very useful, combined with the plumber. For example:

-----------------------------
# poor man's sam file browser
type is text
data matches '([.a-zA-Z¡-￿0-9_/\-;&$,'']+)'
arg isdir $0
plumb start rc -c 'if(pgrep sam >/dev/null){cd '$dir'; DIR = `{pwd}; {echo ''{}''; echo B $DIR/~~samdir~~; echo '',<echo ~~''$DIR''~~; echo; echo ../; 9 ls -pF ''$DIR''''; echo 0}> /tmp/.sam.$USER^*}; if not plumb -d edit '$dir''
-----------------------------

I put several echo so it is more easy to copy to Plan 9.

If you are going to use it in the command window, be aware that you
are going to send other text to it, its good to put same thing like ,,,
before the directory path so it will give an harmless error.

I've found a funny bug in sam playing with this, when you start the
editor to open a file, if before drawing the file in a window you make
an error in the command window, the copy of the file will be blanked.
The file itself is ok, close it and reopen it (tested in Plan 9, 9front and P9P).

-----------------------------
# poor man's sam exec in current file's cwd
type is text
data matches '(¤)([a-zA-ZÀ-ʨ¡-￿0-9_\-./\+^,()$:|#%<>&'' ]+)'
plumb start rc -c 'if(pgrep sam >/dev/null){cd '$wdir'; {echo '$wdir' ¤'''$2'''; echo; {'$2'}; echo}> /tmp/sam_ecfcwd_$pid >[2=1]; {echo ''{}''; echo B '$wdir'^/~~cmd~~; echo ''$''; echo; echo ''<cat /tmp/sam_ecfcwd_''$pid; echo ''!rm /tmp/sam_ecfcwd_''$pid}>> /tmp/.sam.$USER^*}'
-----------------------------

I have to make sam itself delete the temporal file because the file was
actually read after been deleted.

Try it plumbing

	¤hget 'http://plan9.bell-labs.com/wiki/plan9/Tip_o%27_the_day/index.html' | htmlfmt

The {} is the less dangerous string I've found to ensure a new line before sending the commands.

This version is more secure, because sam waits until the command finishes,
but annoying if the command execution time is large. I've change the shell
in sam/unix.c to use rc in p9p (I don't understand why the use of sh):

-----------------------------
# poor man's sam exec in current file's cwd, version 2
#type is text
#data matches '(¤)([a-zA-ZÀ-ʨ¡-￿0-9_\-./\+^,()$:|#%<>&'' ]+)'
#plumb start rc -c 'if(pgrep sam >/dev/null){cd '$wdir'; {echo ''{}''; echo B '$wdir'^/~~cmd~~; echo ''$''; echo ''<echo '''''$wdir' ¤'$2'''''; echo; {'$2'} >[2=1]; echo''}> /tmp/.sam.$USER^*}'
-----------------------------

And it's good to get man pages in named windows rapidly, specially in
referencies to other man pages when I'm reading one:

-----------------------------
## man index entries are synthesized
type is text
data matches '([a-zA-ZÀ-ʨ¡-￿0-9_-./+\-]+)\(([1-8])\)'
plumb start rc -c 'if(pgrep sam >/dev/null){{echo ''{}''; echo ''B ~~'$1'('$2')~~''; echo ''<man '$2' '$1' >[2=1] | nobs''}> /tmp/.sam.$USER^*}; if not {man '$2' '$1' >[2=1] | nobs | plumb -i -d edit -a ''action=showdata filename=/man/'$1'('$2')''}'
-----------------------------

As you can see all these crappy rules work with acme in the usual way
if sam is not running.

In Plan 9, I've problems with sam reading from the plumb port when the pipe is created, so I've slightly modified B, and renamed E:
-----------------------------
#!/bin/rc

files=()
dest=()

if(~ $#* 0){
	echo usage: E file ... >[1=2]
	exit usage
}

for(i)
	switch($i){
	case /*
		files = ( $files $i )
	case *
		files = ( $files `{cleanname `{pwd}^/$i} )
	}

# using sam srv file

if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user
if not if(test -f /srv/sam.$user) dest = /srv/sam.$user
if not {
	echo E: can''''t find sam server file >[1=2]
	exit open
}

switch($files){
case *:*
	for(i in $files)
		echo $i | sed 's/^/B /;s/:(.*)$/\n\1/g' >> $dest
case *
	echo B $files >> $dest
}
-----------------------------

And added these plumb rules:

-----------------------------
# existing files, possibly tagged by line number, go to editor
type is text
data matches '([.a-zA-Z¡-￿0-9_/+\-]*[a-zA-Z¡-￿0-9_/+\-])('$addr')?'
arg isfile	$1
plumb start E $file:$3

## man index entries are synthesized
type is text
data matches '([a-zA-ZÀ-ʨ¡-￿0-9_-./+\-]+)\(([1-8])\)'
plumb start rc -c 'if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user; if not if(test -f /srv/sam.$user) dest = /srv/sam.$user; if not {man '$2' '$1' >[2=1] | plumb -i -d edit -a ''action=showdata filename=/man/'$1'('$2')''; exit}; {echo ''{}''; echo ''B ~~'$1'('$2')~~''; echo ''<man '$2' '$1' >[2=1]''} >>$dest'

# poor man's sam file browser
type is text
data matches '([.a-zA-Z¡-￿0-9_/\-;&$,'']+)'
arg isdir $0
plumb start rc -c 'if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user; if not if(test -f /srv/sam.$user) dest = /srv/sam.$user; if not plumb -d edit '$dir'; {cd '$dir'; DIR = `{pwd}; {echo ''{}''; echo B $DIR/~~samdir~~; echo '',<echo ~~''$DIR''~~; echo; echo ../;ls -pF ''$DIR''''; echo 0} >>/srv/sam.$user}'

## poor man's sam exec in current file's cwd
type is text
data matches '(¤)([a-zA-ZÀ-ʨ¡-￿0-9_\-./\+^,()$:|#%<>*&'' ]+)'
plumb start rc -c 'if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user; if not if(test -f /srv/sam.$user) dest = /srv/sam.$user; if not {echo can''''t find sam server file >[1=2]; exit open}; {cd '$wdir'; {echo '$wdir' ¤'''$2'''; echo; {'$2'}; echo} >/tmp/sam_ecfcwd_$pid >[2=1]; {echo ''{}''; echo B '$wdir'^/~~cmd~~; echo ''$''; echo ''<cat /tmp/sam_ecfcwd_''$pid; echo ''!rm /tmp/sam_ecfcwd_''$pid} >>$dest}'
-----------------------------

if the window where you are plumbing doesn't have a name,
the cwd will be ../ from the cwd of the command window. Don't ask me why.

In Plan 9, if sam  is killed and the pipe survive, delete it, or you'll
have problems at the next execution.

In acme I use files with bookmarks and commands to organize my work. This
let me do the same in sam, but in a "not so nice" way. A good improvement
would be B3 to plumb, merge the menus in B2 and put away cut, paste and
plumb, add an exec menu entry, add completion... Well as I've said before,
I don't think I'll do any of this... And I'm sure some sam users are already
sharping theirs knives while reading all this.

Sorry guys, too much coffe!

trebol.




^ permalink raw reply	[flat|nested] 13+ messages in thread
* [9fans] Chords, ^, _, ^B and scroll with mouse wheel in p9p sam
@ 2016-05-26 22:03 trebol55555
  2016-05-27 20:57 ` Mark Lee Smith
  0 siblings, 1 reply; 13+ messages in thread
From: trebol55555 @ 2016-05-26 22:03 UTC (permalink / raw)
  To: 9fans

The 9front sam in

	https://bitbucket.org/kremlin_/front9port
	https://bitbucket.org/iru/sam9f-unix

doesn't exchange the snarf buffer with X, and the pipe in /srv doesn't
work.

This diff will makes the minimal changes to have those features of 9front
sam in the last p9p. The code fell off from the front.

trebol.


diff -rpuN src/cmd/sam/cmd.c sam/cmd.c
--- src/cmd/sam/cmd.c	2016-04-18 19:07:22.000000000 +0100
+++ sam/cmd.c	2016-05-25 23:56:34.040909362 +0100
@@ -35,6 +35,8 @@ struct cmdtab cmdtab[]={
 	'>',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
 	'<',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
 	'|',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
+	'^',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
+	'_',	0,	0,	0,	0,	aDot,	0,	linex,	plan9_cmd,
 	'=',	0,	0,	0,	0,	aDot,	0,	linex,	eq_cmd,
 	'c'|0x100,0,	0,	0,	0,	aNo,	0,	wordx,	cd_cmd,
 	0,	0,	0,	0,	0,	0,	0,	0
@@ -76,7 +78,13 @@ inputc(void)

     Again:
 	nbuf = 0;
-	if(downloaded){
+	if(cmdbufpos > cmdbuf.nc && cmdbuf.nc > 0){
+		cmdbufpos = 0;
+		bufreset(&cmdbuf);
+	}
+	if(cmdbufpos < cmdbuf.nc && cmdbuf.nc > 0)
+		bufread(&cmdbuf, cmdbufpos++, &r, 1);
+	else if(downloaded){
 		while(termoutp == terminp){
 			cmdupdate();
 			if(patset)
diff -rpuN src/cmd/sam/sam.h sam/sam.h
--- src/cmd/sam/sam.h	2016-04-18 19:07:22.000000000 +0100
+++ sam/sam.h	2016-05-25 23:45:05.652931784 +0100
@@ -369,6 +369,8 @@ extern int	quitok;
 extern Address	addr;
 extern Buffer	snarfbuf;
 extern Buffer	plan9buf;
+extern Buffer	cmdbuf;
+extern int	cmdbufpos;
 extern List	file;
 extern List	tempfile;
 extern File	*cmd;
diff -rpuN src/cmd/sam/shell.c sam/shell.c
--- src/cmd/sam/shell.c	2016-04-18 19:07:22.000000000 +0100
+++ sam/shell.c	2016-05-25 23:46:25.262692361 +0100
@@ -6,6 +6,8 @@ extern	jmp_buf	mainloop;
 char	errfile[64];
 String	plan9cmd;	/* null terminated */
 Buffer	plan9buf;
+Buffer	cmdbuf;
+int	cmdbufpos;
 void	checkerrs(void);

 void
@@ -40,7 +42,7 @@ plan9(File *f, int type, String *s, int
 	}
 	if(type!='!' && pipe(pipe1)==-1)
 		error(Epipe);
-	if(type=='|')
+	if(type=='|' || type=='_')
 		snarf(f, addr.r.p1, addr.r.p2, &plan9buf, 1);
 	if((pid=fork()) == 0){
 		setname(f);
@@ -61,14 +63,14 @@ plan9(File *f, int type, String *s, int
 			}
 		}
 		if(type != '!') {
-			if(type=='<' || type=='|')
-				dup(pipe1[1], 1);
-			else if(type == '>')
+			if(type == '>')
 				dup(pipe1[0], 0);
+			else
+				dup(pipe1[1], 1);
 			close(pipe1[0]);
 			close(pipe1[1]);
 		}
-		if(type == '|'){
+		if(type == '|' || type == '_'){
 			if(pipe(pipe2) == -1)
 				exits("pipe");
 			if((pid = fork())==0){
@@ -100,7 +102,7 @@ plan9(File *f, int type, String *s, int
 			close(pipe2[0]);
 			close(pipe2[1]);
 		}
-		if(type=='<'){
+		if(type=='<' || type=='^'){
 			close(0);	/* so it won't read from terminal */
 			open("/dev/null", 0);
 		}
@@ -128,9 +130,14 @@ plan9(File *f, int type, String *s, int
 		writeio(f);
 		bpipeok = 0;
 		closeio((Posn)-1);
+	}else if(type == '^' || type == '_'){
+		int nulls;
+		close(pipe1[1]);
+		bufload(&cmdbuf, cmdbufpos, pipe1[0], &nulls);
+		close(pipe1[0]);
 	}
 	retcode = waitfor(pid);
-	if(type=='|' || type=='<')
+	if(type=='|' || type=='<' || type=='_' || type=='^')
 		if(retcode!=0)
 			warn(Wbadstatus);
 	if(downloaded)
diff -rpuN src/cmd/samterm/main.c samterm/main.c
--- src/cmd/samterm/main.c	2016-04-18 19:07:22.000000000 +0100
+++ samterm/main.c	2016-05-26 16:12:12.452556184 +0100
@@ -23,11 +23,8 @@ long	modified = 0;		/* strange lookahead
 char	hostlock = 1;
 char	hasunlocked = 0;
 int	maxtab = 8;
-int	chord;
 int	autoindent;

-#define chording 0	/* code here for reference but it causes deadlocks */
-
 void
 notifyf(void *a, char *msg)
 {
@@ -39,7 +36,7 @@ notifyf(void *a, char *msg)
 void
 threadmain(int argc, char *argv[])
 {
-	int i, got, scr, w;
+	int i, got, scr, chord, w;
 	Text *t;
 	Rectangle r;
 	Flayer *nwhich;
@@ -85,6 +82,7 @@ threadmain(int argc, char *argv[])

 	got = 0;
 	if(protodebug) print("loop\n");
+	chord = 0;
 	for(;;got = waitforio()){
 		if(hasunlocked && RESIZED())
 			resize();
@@ -108,19 +106,32 @@ threadmain(int argc, char *argv[])
 				continue;
 			}
 			nwhich = flwhich(mousep->xy);
-			scr = which && ptinrect(mousep->xy, which->scroll);
+			scr = which && (ptinrect(mousep->xy, which->scroll) ||
+				mousep->buttons&(8|16));
 			if(mousep->buttons)
 				flushtyping(1);
-			if(chording && chord==1 && !mousep->buttons)
+			if((mousep->buttons&1)==0)
 				chord = 0;
-			if(chording && chord)
+			if(chord && which && which==nwhich){
 				chord |= mousep->buttons;
-			else if(mousep->buttons&1){
+				t = (Text *)which->user1;
+				if(!t->lock){
+					w = which-t->l;
+					if(chord&2){
+						cut(t, w, 1, 1);
+						chord &= ~2;
+					}
+					if(chord&4){
+						paste(t, w);
+						chord &= ~4;
+					}
+				}
+			}else if(mousep->buttons&(1|8)){
 				if(nwhich){
 					if(nwhich!=which)
 						current(nwhich);
 					else if(scr)
-						scroll(which, 1);
+						scroll(which, (mousep->buttons&8) ? 4 : 1);
 					else{
 						t=(Text *)which->user1;
 						if(flselect(which)){
@@ -137,27 +148,14 @@ threadmain(int argc, char *argv[])
 					scroll(which, 2);
 				else
 					menu2hit();
-			}else if((mousep->buttons&4)){
+			}else if(mousep->buttons&(4|16)){
 				if(scr)
-					scroll(which, 3);
+					scroll(which, (mousep->buttons&16) ? 5 : 3);
 				else
 					menu3hit();
 			}
 			mouseunblock();
 		}
-		if(chording && chord){
-			t = (Text*)which->user1;
-			if(!t->lock && !hostlock){
-				w = which-t->l;
-				if(chord&2){
-					cut(t, w, 1, 1);
-					chord &= ~2;
-				}else if(chord&4){
-					paste(t, w);
-					chord &= ~4;
-				}
-			}
-		}
 	}
 }

@@ -497,6 +495,7 @@ flushtyping(int clearesc)
 #define	CUT	(Kcmd+'x')
 #define	COPY	(Kcmd+'c')
 #define	PASTE	(Kcmd+'v')
+#define	Kstx	0x02

 int
 nontypingkey(int c)
@@ -512,6 +511,7 @@ nontypingkey(int c)
 	case PAGEUP:
 	case RIGHTARROW:
 	case SCROLLKEY:
+	case Kstx:
 		return 1;
 	}
 	if(c >= Kcmd)
@@ -669,6 +669,15 @@ type(Flayer *l, int res)	/* what a blood
 				}
 			}
 		}
+	}else if(c == Kstx){
+		t = &cmd;
+		for(l=t->l; l->textfn==0; l++)
+			;
+		current(l);
+		flushtyping(0);
+		a = t->rasp.nrunes;
+		flsetselect(l, a, a);
+		center(l, a);
 	}else{
 		if(c==ESC && typeesc>=0){
 			l->p0 = typeesc;
diff -rpuN src/cmd/samterm/scroll.c samterm/scroll.c
--- src/cmd/samterm/scroll.c	2016-04-18 19:07:22.000000000 +0100
+++ samterm/scroll.c	2016-05-26 02:07:31.922977720 +0100
@@ -115,7 +115,7 @@ scroll(Flayer *l, int but)
 	draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
 	do{
 		oin = in;
-		in = abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2;
+		in = (but > 3) || (but == 2) || abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2;
 		if(oin && !in)
 			scrunmark(l, r);
 		if(in){
@@ -126,9 +126,7 @@ scroll(Flayer *l, int but)
 				my = s.min.y;
 			if(my >= s.max.y)
 				my = s.max.y;
-			if(!eqpt(mousep->xy, Pt(x, my)))
-				moveto(mousectl, Pt(x, my));
-			if(but == 1){
+			if(but == 1 || but == 4){
 				p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my));
 				rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
 				y = rt.min.y;
@@ -136,7 +134,7 @@ scroll(Flayer *l, int but)
 				y = my;
 				if(y > s.max.y-2)
 					y = s.max.y-2;
-			}else if(but == 3){
+			}else if(but == 3 || but == 5){
 				p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my));
 				rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
 				y = rt.min.y;
@@ -147,19 +145,21 @@ scroll(Flayer *l, int but)
 				scrmark(l, r);
 			}
 		}
-	}while(button(but));
+	}while(but <= 3 && button(but));
 	if(in){
 		h = s.max.y-s.min.y;
 		scrunmark(l, r);
 		p0 = 0;
-		if(but == 1)
+		if(but == 1 || but == 4){
+			but = 1;
 			p0 = (long)(my-s.min.y)/l->f.font->height+1;
-		else if(but == 2){
+		}else if(but == 2){
 			if(tot > 1024L*1024L)
 				p0 = ((tot>>10)*(y-s.min.y)/h)<<10;
 			else
 				p0 = tot*(y-s.min.y)/h;
-		}else if(but == 3){
+		}else if(but == 3 || but == 5){
+			but = 3;
 			p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my));
 			if(p0 > tot)
 				p0 = tot;




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

end of thread, other threads:[~2016-05-31  1:34 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-27 17:11 [9fans] Chords, ^, _, ^B and scroll with mouse wheel in p9p sam trebol55555
2016-05-27 17:46 ` Mark Lee Smith
2016-05-27 18:04   ` trebol55555
2016-05-28 10:04     ` Mark Lee Smith
  -- strict thread matches above, loose matches on Subject: below --
2016-05-31  1:34 trebol55555
2016-05-30 16:35 trebol55555
2016-05-26 22:03 trebol55555
2016-05-27 20:57 ` Mark Lee Smith
2016-05-27 21:42   ` Tobias Kreisel
2016-05-27 22:16   ` Ethan Grammatikidis
2016-05-27 22:37     ` stanley lieber
2016-05-28 15:25       ` Ethan Grammatikidis
2016-05-27 23:09     ` Kurt H Maier

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