9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: trebol55555@yandex.ru
To: 9fans@9fans.net
Subject: [9fans] Chords, ^, _, ^B and scroll with mouse wheel in p9p sam
Date: Mon, 30 May 2016 17:35:50 +0100	[thread overview]
Message-ID: <b2b20515f72ec720ad966419910bab63@debpi> (raw)

[-- 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:


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

	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

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!


             reply	other threads:[~2016-05-30 16:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-30 16:35 trebol55555 [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-05-31  1:34 trebol55555
2016-05-27 17:11 trebol55555
2016-05-27 17:46 ` Mark Lee Smith
2016-05-27 18:04   ` trebol55555
2016-05-28 10:04     ` Mark Lee Smith
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

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b2b20515f72ec720ad966419910bab63@debpi \
    --to=trebol55555@yandex.ru \
    --cc=9fans@9fans.net \


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