9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] acme: send dot to the stdin of a more complicated command
@ 2009-06-08 12:48 Rudolf Sykora
  2009-06-08 16:04 ` Lyndon Nerenberg
  0 siblings, 1 reply; 16+ messages in thread
From: Rudolf Sykora @ 2009-06-08 12:48 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 12:48 [9fans] acme: send dot to the stdin of a more complicated command Rudolf Sykora
@ 2009-06-08 16:04 ` Lyndon Nerenberg
  2009-06-08 16:34   ` Rudolf Sykora
  0 siblings, 1 reply; 16+ messages in thread
From: Lyndon Nerenberg @ 2009-06-08 16:04 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 16:04 ` Lyndon Nerenberg
@ 2009-06-08 16:34   ` Rudolf Sykora
  2009-06-08 16:58     ` andrey mirtchovski
  0 siblings, 1 reply; 16+ messages in thread
From: Rudolf Sykora @ 2009-06-08 16:34 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> 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



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 16:34   ` Rudolf Sykora
@ 2009-06-08 16:58     ` andrey mirtchovski
  2009-06-08 17:30       ` Rudolf Sykora
  0 siblings, 1 reply; 16+ messages in thread
From: andrey mirtchovski @ 2009-06-08 16:58 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 16:58     ` andrey mirtchovski
@ 2009-06-08 17:30       ` Rudolf Sykora
  2009-06-08 17:35         ` andrey mirtchovski
                           ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Rudolf Sykora @ 2009-06-08 17:30 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> 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



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 17:30       ` Rudolf Sykora
@ 2009-06-08 17:35         ` andrey mirtchovski
  2009-06-08 17:45           ` Rudolf Sykora
  2009-06-08 17:42         ` yy
  2009-06-08 18:15         ` Russ Cox
  2 siblings, 1 reply; 16+ messages in thread
From: andrey mirtchovski @ 2009-06-08 17:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> 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?



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 17:30       ` Rudolf Sykora
  2009-06-08 17:35         ` andrey mirtchovski
@ 2009-06-08 17:42         ` yy
  2009-06-08 18:15         ` Russ Cox
  2 siblings, 0 replies; 16+ messages in thread
From: yy @ 2009-06-08 17:42 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

2009/6/8 Rudolf Sykora <rudolf.sykora@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 .



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 17:35         ` andrey mirtchovski
@ 2009-06-08 17:45           ` Rudolf Sykora
  0 siblings, 0 replies; 16+ messages in thread
From: Rudolf Sykora @ 2009-06-08 17:45 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> 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



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 17:30       ` Rudolf Sykora
  2009-06-08 17:35         ` andrey mirtchovski
  2009-06-08 17:42         ` yy
@ 2009-06-08 18:15         ` Russ Cox
  2009-06-08 18:35           ` Dan Cross
                             ` (3 more replies)
  2 siblings, 4 replies; 16+ messages in thread
From: Russ Cox @ 2009-06-08 18:15 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> 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


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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 18:15         ` Russ Cox
@ 2009-06-08 18:35           ` Dan Cross
  2009-06-08 18:59           ` [9fans] acme: send dot to the stdin of a more complicated Skip Tavakkolian
                             ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: Dan Cross @ 2009-06-08 18:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, Jun 8, 2009 at 2:15 PM, Russ Cox<rsc@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.



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

* Re: [9fans] acme: send dot to the stdin of a more complicated
  2009-06-08 18:15         ` Russ Cox
  2009-06-08 18:35           ` Dan Cross
@ 2009-06-08 18:59           ` Skip Tavakkolian
  2009-06-09  8:28           ` [9fans] acme: send dot to the stdin of a more complicated command Rudolf Sykora
  2013-08-28  8:05           ` Rudolf Sykora
  3 siblings, 0 replies; 16+ messages in thread
From: Skip Tavakkolian @ 2009-06-08 18:59 UTC (permalink / raw)
  To: 9fans

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

nice!




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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 18:15         ` Russ Cox
  2009-06-08 18:35           ` Dan Cross
  2009-06-08 18:59           ` [9fans] acme: send dot to the stdin of a more complicated Skip Tavakkolian
@ 2009-06-09  8:28           ` Rudolf Sykora
  2013-08-28  8:05           ` Rudolf Sykora
  3 siblings, 0 replies; 16+ messages in thread
From: Rudolf Sykora @ 2009-06-09  8:28 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> 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



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2009-06-08 18:15         ` Russ Cox
                             ` (2 preceding siblings ...)
  2009-06-09  8:28           ` [9fans] acme: send dot to the stdin of a more complicated command Rudolf Sykora
@ 2013-08-28  8:05           ` Rudolf Sykora
  2013-08-28 12:13             ` dexen deVries
  3 siblings, 1 reply; 16+ messages in thread
From: Rudolf Sykora @ 2013-08-28  8:05 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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



On 8 June 2009 20:15, Russ Cox <rsc@swtch.com> wrote:
>> 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
>



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2013-08-28  8:05           ` Rudolf Sykora
@ 2013-08-28 12:13             ` dexen deVries
  2013-08-28 12:53               ` Rudolf Sykora
  2013-08-28 15:11               ` James A. Robinson
  0 siblings, 2 replies; 16+ messages in thread
From: dexen deVries @ 2013-08-28 12:13 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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




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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2013-08-28 12:13             ` dexen deVries
@ 2013-08-28 12:53               ` Rudolf Sykora
  2013-08-28 15:11               ` James A. Robinson
  1 sibling, 0 replies; 16+ messages in thread
From: Rudolf Sykora @ 2013-08-28 12:53 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 28 August 2013 14:13, dexen deVries <dexen.devries@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 >)



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

* Re: [9fans] acme: send dot to the stdin of a more complicated command
  2013-08-28 12:13             ` dexen deVries
  2013-08-28 12:53               ` Rudolf Sykora
@ 2013-08-28 15:11               ` James A. Robinson
  1 sibling, 0 replies; 16+ messages in thread
From: James A. Robinson @ 2013-08-28 15:11 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

On Wed, Aug 28, 2013 at 5:13 AM, dexen deVries <dexen.devries@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

[-- Attachment #2: Type: text/html, Size: 1667 bytes --]

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

end of thread, other threads:[~2013-08-28 15:11 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-08 12:48 [9fans] acme: send dot to the stdin of a more complicated command Rudolf Sykora
2009-06-08 16:04 ` Lyndon Nerenberg
2009-06-08 16:34   ` Rudolf Sykora
2009-06-08 16:58     ` andrey mirtchovski
2009-06-08 17:30       ` Rudolf Sykora
2009-06-08 17:35         ` andrey mirtchovski
2009-06-08 17:45           ` Rudolf Sykora
2009-06-08 17:42         ` yy
2009-06-08 18:15         ` Russ Cox
2009-06-08 18:35           ` Dan Cross
2009-06-08 18:59           ` [9fans] acme: send dot to the stdin of a more complicated Skip Tavakkolian
2009-06-09  8:28           ` [9fans] acme: send dot to the stdin of a more complicated command Rudolf Sykora
2013-08-28  8:05           ` Rudolf Sykora
2013-08-28 12:13             ` dexen deVries
2013-08-28 12:53               ` Rudolf Sykora
2013-08-28 15:11               ` James A. Robinson

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