Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[9fans] acme: send dot to the stdin of a more complicated command

320 views
Skip to first unread message

Rudolf Sykora

unread,
Jun 8, 2009, 8:51:46 AM6/8/09
to
Hello everyone,

when I want to process a dot's contents in acme I can use the '>' syntax, e.g.

have

> awk '{print}'

in a window, select it, and then 2-1 click on Edit in the window with
my dot. That works.
But what shall I do when the awk script is more complicated, in the
simplest case like

> awk '
{print}
'

When I select it all and do the same as before, it doesn't work
(probably because of the new lines?)...

Thanks
Ruda

Lyndon Nerenberg

unread,
Jun 8, 2009, 12:07:27 PM6/8/09
to
> But what shall I do when the awk script is more complicated, in the
> simplest case

Put the awk code into a file and execute '> awk -f foo' in acme.

Rudolf Sykora

unread,
Jun 8, 2009, 12:36:59 PM6/8/09
to
> Put the awk code into a file and execute '> awk -f foo' in acme.

well, I hoped this would be the last way... It makes me create files I
don't actually need.
Is it the newlines that causes troubles?

Thanks
Ruda

andrey mirtchovski

unread,
Jun 8, 2009, 1:01:10 PM6/8/09
to
> well, I hoped this would be the last way... It makes me create files I
> don't actually need.

remember, this is plan9 and everything is a file. chances are your
"script" is already available in some filesystem and you don't need to
write it out:: create a new window inside acme, type your awk script
and then issue ">awk -f /mnt/wsys/X/body" where X is the ID of your
window.

you'll need to figure out what the new window's ID is, but that's not
too difficult, simply middle-click something like this after you've
created the script window:

grep -l foo /mnt/wsys/[0-9]*/body

where 'foo' is some unique part of your script.

Rudolf Sykora

unread,
Jun 8, 2009, 1:32:43 PM6/8/09
to
> remember, this is plan9 and everything is a file. chances are your
> "script" is already available in some filesystem and you don't need to
> write it out:: create a new window inside acme, type your awk script
> and then issue ">awk -f /mnt/wsys/X/body" where X is the ID of your
> window.

well, though an inspiring idea, it doesn't sound to be much practical:
1) I usually have a special window in which I have many commands. I
then select the one needed and chord it to the appropriate window
(i.e. I don't use the whole contents of a window).
2) sometimes I have more such windows.

The very question for me now is: why it behaves how it behaves, i.e
why newlines (if it's them) are problematic.

Ruda

andrey mirtchovski

unread,
Jun 8, 2009, 1:37:51 PM6/8/09
to
> The very question for me now is: why it behaves how it behaves, i.e
> why newlines (if it's them) are problematic.

and you want somebody do look through the code and figure it out for you?

yy

unread,
Jun 8, 2009, 1:45:05 PM6/8/09
to
2009/6/8 Rudolf Sykora <rudolf...@gmail.com>:

> The very question for me now is: why it behaves how it behaves, i.e
> why newlines (if it's them) are problematic.
>
> Ruda
>

They are the only way Edit has to separate commands. You will notice
that you cannot use something like i/A/a/W/ (or i/A/;a/W/, for
example). However, you can chord something like
i/A/
a/W/
When you chord your example, acme calls rc with: rc -c 'awk '', so it
does not work. rc is who interprets those multiple-line commands. You
could use rc functions if that makes you feel better than with plain
files, just remember to prepend the function name with a semi-colon,
to force rc to interpret the command. At least that is how I remember
it, please somebody correct me if I am wrong.


--
- yiyus || JGL .

Rudolf Sykora

unread,
Jun 8, 2009, 1:47:27 PM6/8/09
to
> and you want somebody do look through the code and figure it out for you?

not really. I wanted to know whether
1) somebody thought about it (knowing the system has been around for
some time I'd expect somebody must have had the same problem)
2) there is any good reason why it behaves so.

Ruda

Russ Cox

unread,
Jun 8, 2009, 2:18:28 PM6/8/09
to
> well, though an inspiring idea, it doesn't sound to be much practical:
> 1) I usually have a special window in which I have many commands. I
> then select the one needed and chord it to the appropriate window
> (i.e. I don't use the whole contents of a window).
> 2) sometimes I have more such windows.

This is an interesting usage model. I've never seen it before.
The power of acme is that you can extend it with external
programs. The script below implements this usage; I called it Run.
You can type and select your command in one window, with a name matching
pattern, and then in the other window's tag execute >Run pattern.
Run finds the window with a title matching pattern, pulls out the
selected text, and runs it through rc.

See http://swtch.com/~rsc/acme-Run.png for an illustration.

Russ


#!/bin/rc

if(! ~ $#* 1) {
echo 'usage: Run title' >[1=2]
exit usage
}

id=`{awk -v 'pat='$1 '$6 ~ pat {print $1}' /mnt/wsys/index}
if(~ $#id 0) {
echo 'no match for pattern' >[1=2]
exit none
}
if(! ~ $#id 1) {
echo 'ambiguous pattern' >[1=2]
exit ambiguous
}
if(~ `{wc -w /mnt/wsys/$id/rdsel} 0) {
echo 'no command selected' >[1=2]
exit missing
}
exec rc /mnt/wsys/$id/rdsel

Dan Cross

unread,
Jun 8, 2009, 3:01:48 PM6/8/09
to
On Mon, Jun 8, 2009 at 2:15 PM, Russ Cox<r...@swtch.com> wrote:
> The script below implements this usage; I called it Run.
> You can type and select your command in one window, with a name matching
> pattern, and then in the other window's tag execute >Run pattern.
> Run finds the window with a title matching pattern, pulls out the
> selected text, and runs it through rc.
>
> See http://swtch.com/~rsc/acme-Run.png for an illustration.

Wow, cool. Could you copy this into /acme/bin on sources?

- Dan C.

Skip Tavakkolian

unread,
Jun 8, 2009, 3:02:44 PM6/8/09
to
> See http://swtch.com/~rsc/acme-Run.png for an illustration.

nice!


Rudolf Sykora

unread,
Jun 9, 2009, 4:33:58 AM6/9/09
to
> See http://swtch.com/~rsc/acme-Run.png for an illustration.
>
> Russ

Thank you much!
This is what I need and now I see how it can be achieved...
:)

Ruda

Rudolf Sykora

unread,
Aug 28, 2013, 4:05:14 AM8/28/13
to
Hello,

I tried to modify Russ' script below to be usable on p9p. I came up with
------------------------------------
#!/usr/local/plan9/bin/rc

if(! ~ $#* 1) {
echo 'usage: Run title' >[1=2]
exit 1
}

id=`{awk -v 'pat='$1 '$6 ~ pat {print $1}' <{9p read acme/index}}
if(~ $#id 0) {
echo 'no match for pattern' >[1=2]
exit 2
}
if(! ~ $#id 1) {
echo 'ambiguous pattern' >[1=2]
exit 3
}
if(~ `{wc -w <{9p read acme/$id/rdsel}} 0) {
echo 'no command selected' >[1=2]
exit 4
}
#exec cat <{9p read acme/$id/rdsel}
exec /usr/local/plan9/bin/rc <{9p read acme/$id/rdsel}
------------------------------------

but the last line doesn't really do what I want, yielding the error:
Run: exit 1
rc: /dev/fd/5:2: token EOF: syntax error

can anybody help me with what is wrong?
The commented-out line with cat prints correctly what I have
selected in the other window (see the description of the original
script), e.g.
>awk '{print $2}'

Thank you!
Ruda

dexen deVries

unread,
Aug 28, 2013, 8:13:49 AM8/28/13
to
On Wednesday 28 of August 2013 10:05:14 Rudolf Sykora wrote:
> Hello,
>
> I tried to modify Russ' script below to be usable on p9p. I came up with
> ------------------------------------
> #!/usr/local/plan9/bin/rc
>
> if(! ~ $#* 1) {
> echo 'usage: Run title' >[1=2]
> exit 1
> }
>
> id=`{awk -v 'pat='$1 '$6 ~ pat {print $1}' <{9p read acme/index}}
> if(~ $#id 0) {
> echo 'no match for pattern' >[1=2]
> exit 2
> }
> if(! ~ $#id 1) {
> echo 'ambiguous pattern' >[1=2]
> exit 3
> }
> if(~ `{wc -w <{9p read acme/$id/rdsel}} 0) {
> echo 'no command selected' >[1=2]
> exit 4
> }
> #exec cat <{9p read acme/$id/rdsel}
> exec /usr/local/plan9/bin/rc <{9p read acme/$id/rdsel}
> ------------------------------------
>
> but the last line doesn't really do what I want, yielding the error:
> Run: exit 1
> rc: /dev/fd/5:2: token EOF: syntax error


your selection lacks the final LF to make Rc happy ;-)

a quick and dirty hack would be to always append LF:
exec /usr/local/plan9/bin/rc <{9p read acme/$id/rdsel;echo;}

tested with:
echo foo bar
rc <{9p read acme/$winid/rdsel; echo; }

selecting bare `echo foo bar' (without LF) gives syntax error; selecting whole
line works a-OK


--
dexen deVries

[[[↓][→]]]

Take care of the luxuries and the necessities will take care of themselves.
-- L. Long

Rudolf Sykora

unread,
Aug 28, 2013, 8:53:12 AM8/28/13
to
On 28 August 2013 14:13, dexen deVries <dexen....@gmail.com> wrote:
> your selection lacks the final LF to make Rc happy ;-)
>
> a quick and dirty hack would be to always append LF:
> exec /usr/local/plan9/bin/rc <{9p read acme/$id/rdsel;echo;}
>
> tested with:
> echo foo bar
> rc <{9p read acme/$winid/rdsel; echo; }

thanks, this helped, now it works :)
Ruda


P.S.: correction: in my previous e-mail where I write
>awk '{print $2}'
I actually meant just
awk '{print $2}'
(ie. without the initial >)

James A. Robinson

unread,
Aug 28, 2013, 11:11:42 AM8/28/13
to
On Wed, Aug 28, 2013 at 5:13 AM, dexen deVries <dexen....@gmail.com> wrote:
your selection lacks the final LF to make Rc happy ;-)

a quick and dirty hack would be to always append LF:
exec /usr/local/plan9/bin/rc <{9p read acme/$id/rdsel;echo;}

tested with:
echo foo bar
rc <{9p read acme/$winid/rdsel; echo; }

selecting bare `echo foo bar' (without LF) gives syntax error; selecting whole
line works a-OK

A small variation of this would be to allow for
multiple arguments to Run, following the label,
and to shift the label off the args and pass the
rest to the executing command.

For my own copy of this I read the contents
of rdsel into a separate file and execute it
with any following args (I'm using sh, but I
assume similar functionality is available in
rc).

Jim

0 new messages