9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] How to do this with [acme | sam | sed ] ?
@ 2013-01-11 11:19 Peter A. Cejchan
  2013-01-11 11:44 ` Rudolf Sykora
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Peter A. Cejchan @ 2013-01-11 11:19 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

## How to do this with [acme | sam | sed ]  ?
# compound commands
# remove outermost pair of braces:  abcd(x+(y-z))efgh  --> abcdx+(y-z)efgh
         [ no idea :-( ]
# remove semicolon before // comments:  xyz;[tab][space]*//  --> xyz
         [ Edit /;[ 	]*\/\// Edit s/;//	# find and remove semicolon
before // comments ]
# prefix to postfix operator: ++i --> i++
         [ Edit s/\+\+[a-zA-Z]+[0-9a-zA-Z]*/&++/ Edit s/\+\+/d]

thanks,
++pac



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 11:19 [9fans] How to do this with [acme | sam | sed ] ? Peter A. Cejchan
@ 2013-01-11 11:44 ` Rudolf Sykora
  2013-01-11 12:24   ` Peter A. Cejchan
  2013-01-11 14:24   ` erik quanstrom
  2013-01-11 11:46 ` Bence Fábián
  2013-01-11 12:09 ` Nicolas Bercher
  2 siblings, 2 replies; 12+ messages in thread
From: Rudolf Sykora @ 2013-01-11 11:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 11 January 2013 12:19, Peter A. Cejchan <tyapca7@gmail.com> wrote:
> # remove outermost pair of braces:  abcd(x+(y-z))efgh  --> abcdx+(y-z)efgh

This, I believe, can't be achieved only with regexps. I'd write a
small external program and use it as a filter.

> # prefix to postfix operator: ++i --> i++
>          [ Edit s/\+\+[a-zA-Z]+[0-9a-zA-Z]*/&++/ Edit s/\+\+/d]

using the \1 (used to be undocumented on plan9) may be sometimes easier
Edit s/\+\+([A-Za-z]+[A-Za-z0-9])*/\1++/

Ruda



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 11:19 [9fans] How to do this with [acme | sam | sed ] ? Peter A. Cejchan
  2013-01-11 11:44 ` Rudolf Sykora
@ 2013-01-11 11:46 ` Bence Fábián
  2013-01-11 12:07   ` Peter A. Cejchan
  2013-01-11 12:09 ` Nicolas Bercher
  2 siblings, 1 reply; 12+ messages in thread
From: Bence Fábián @ 2013-01-11 11:46 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

for the third:
/\+\+[a-zA-Z_]+[0-9a-zA-Z_]*/{
x/\+\+/d
a/++/
}

the braces stuff is pretty tough, but maybe someone will have an idea.
however it is really easy to do it by hand in acme.

click on the inside of the opening paren with a double click then click
button 2
(while still holding down button 1 from the double click) this will cut
everything
inside that and the matching paren. then highlight the remaining () and
while
still holding down button 1 push button3.
Looks complicated written down but it's a really quick and easy to learn
sequence.



2013/1/11 Peter A. Cejchan <tyapca7@gmail.com>

> ## How to do this with [acme | sam | sed ]  ?
> # compound commands
> # remove outermost pair of braces:  abcd(x+(y-z))efgh  --> abcdx+(y-z)efgh
>          [ no idea :-( ]
> # remove semicolon before // comments:  xyz;[tab][space]*//  --> xyz
>          [ Edit /;[     ]*\/\// Edit s/;//      # find and remove semicolon
> before // comments ]
> # prefix to postfix operator: ++i --> i++
>          [ Edit s/\+\+[a-zA-Z]+[0-9a-zA-Z]*/&++/ Edit s/\+\+/d]
>
> thanks,
> ++pac
>
>

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

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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 11:46 ` Bence Fábián
@ 2013-01-11 12:07   ` Peter A. Cejchan
  0 siblings, 0 replies; 12+ messages in thread
From: Peter A. Cejchan @ 2013-01-11 12:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

how it come i didn't realize that ;-)  !
thanks,
peter

On Fri, Jan 11, 2013 at 12:46 PM, Bence Fábián <begnoc@gmail.com> wrote:
> for the third:
> /\+\+[a-zA-Z_]+[0-9a-zA-Z_]*/{
> x/\+\+/d
> a/++/
> }
>
> the braces stuff is pretty tough, but maybe someone will have an idea.
> however it is really easy to do it by hand in acme.
>
> click on the inside of the opening paren with a double click then click
> button 2
> (while still holding down button 1 from the double click) this will cut
> everything
> inside that and the matching paren. then highlight the remaining () and
> while
> still holding down button 1 push button3.
> Looks complicated written down but it's a really quick and easy to learn
> sequence.
>
>
>
> 2013/1/11 Peter A. Cejchan <tyapca7@gmail.com>
>
>> ## How to do this with [acme | sam | sed ]  ?
>> # compound commands
>> # remove outermost pair of braces:  abcd(x+(y-z))efgh  --> abcdx+(y-z)efgh
>>          [ no idea :-( ]
>> # remove semicolon before // comments:  xyz;[tab][space]*//  --> xyz
>>          [ Edit /;[     ]*\/\// Edit s/;//      # find and remove
>> semicolon
>> before // comments ]
>> # prefix to postfix operator: ++i --> i++
>>          [ Edit s/\+\+[a-zA-Z]+[0-9a-zA-Z]*/&++/ Edit s/\+\+/d]
>>
>> thanks,
>> ++pac
>>
>



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 11:19 [9fans] How to do this with [acme | sam | sed ] ? Peter A. Cejchan
  2013-01-11 11:44 ` Rudolf Sykora
  2013-01-11 11:46 ` Bence Fábián
@ 2013-01-11 12:09 ` Nicolas Bercher
  2013-01-11 13:10   ` Peter A. Cejchan
  2 siblings, 1 reply; 12+ messages in thread
From: Nicolas Bercher @ 2013-01-11 12:09 UTC (permalink / raw)
  To: 9fans

On 11/01/2013 12:19, Peter A. Cejchan wrote:
> ## How to do this with [acme | sam | sed ]  ?
> # compound commands
> # remove outermost pair of braces:  abcd(x+(y-z))efgh  -->  abcdx+(y-z)efgh
>           [ no idea :-( ]

Is this enough?

   echo 'abcd(x+(y-z))efgh' | sed 's;\(;;' | sed 's;(.*)\);\1;'

Nicolas



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 11:44 ` Rudolf Sykora
@ 2013-01-11 12:24   ` Peter A. Cejchan
  2013-01-11 12:27     ` dexen deVries
  2013-01-11 14:24   ` erik quanstrom
  1 sibling, 1 reply; 12+ messages in thread
From: Peter A. Cejchan @ 2013-01-11 12:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I am now on p9p and this does not work - at least with (... )*
> using the \1 (used to be undocumented on plan9) may be sometimes easier
> Edit s/\+\+([A-Za-z]+[A-Za-z0-9])*/\1++/>


Petr.



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 12:24   ` Peter A. Cejchan
@ 2013-01-11 12:27     ` dexen deVries
  2013-01-11 12:38       ` Bence Fábián
  0 siblings, 1 reply; 12+ messages in thread
From: dexen deVries @ 2013-01-11 12:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Friday 11 of January 2013 13:24:12 Peter A. Cejchan wrote:
> I am now on p9p and this does not work - at least with (... )*
> 
> > using the \1 (used to be undocumented on plan9) may be sometimes easier
> > Edit s/\+\+([A-Za-z]+[A-Za-z0-9])*/\1++/>

oughta be 
Edit s/\+\+([A-Za-z]+[A-Za-z0-9]*)/\1++/
the * moves to the left.


also, probably oughta be
Edit ,s/....../g

to work on all lines, and change multiple matches in one go.

-- 
dexen deVries

[[[↓][→]]]


Reality is just a convenient measure of complexity.
                -- Alvy Ray Smith



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 12:27     ` dexen deVries
@ 2013-01-11 12:38       ` Bence Fábián
  0 siblings, 0 replies; 12+ messages in thread
From: Bence Fábián @ 2013-01-11 12:38 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

Main problem with the parens one is handling

foo (bar) (baz)

or

foo(
bar(baz)
)

i don't think it's easy with regexes. i'm with Ruda on that one.
writing  a filter would be easier.

-bence

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

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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 12:09 ` Nicolas Bercher
@ 2013-01-11 13:10   ` Peter A. Cejchan
  2013-01-11 13:24     ` Nicolas Bercher
  0 siblings, 1 reply; 12+ messages in thread
From: Peter A. Cejchan @ 2013-01-11 13:10 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>   echo 'abcd(x+(y-z))efgh' | sed 's;\(;;' | sed 's;(.*)\);\1;'

Thanks, this is fine for my purpose (porting from C to Go), thanks!
Just removing parens around for and if statements on a single line.

     | 9 sed 's/\(//; s/(.*)\)/\1/'
(linux's sed does not work with it)

best,
++pac



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 13:10   ` Peter A. Cejchan
@ 2013-01-11 13:24     ` Nicolas Bercher
  0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Bercher @ 2013-01-11 13:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 11/01/2013 14:10, Peter A. Cejchan wrote:
>>    echo 'abcd(x+(y-z))efgh' | sed 's;\(;;' | sed 's;(.*)\);\1;'
>
> Thanks, this is fine for my purpose (porting from C to Go), thanks!
> Just removing parens around for and if statements on a single line.
>
>       | 9 sed 's/\(//; s/(.*)\)/\1/'
> (linux's sed does not work with it)

Under Linux, you have to switch the syntax between escaped and literal
parenthesis, this works fine:

       | 9 sed 's/(//; s/\(.*\))/\1/'

Nicolas



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 11:44 ` Rudolf Sykora
  2013-01-11 12:24   ` Peter A. Cejchan
@ 2013-01-11 14:24   ` erik quanstrom
  2013-01-11 15:16     ` Rudolf Sykora
  1 sibling, 1 reply; 12+ messages in thread
From: erik quanstrom @ 2013-01-11 14:24 UTC (permalink / raw)
  To: 9fans

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

> # remove outermost pair of braces:  abcd(x+(y-z))efgh  --> abcdx+(y-z)efgh
>          [ no idea :-( ]

this is made simple since * is "greedy":

Edit s:\((.*)\):\1:g

On Fri Jan 11 06:45:39 EST 2013, rudolf.sykora@gmail.com wrote:
> On 11 January 2013 12:19, Peter A. Cejchan <tyapca7@gmail.com> wrote:
> > # remove outermost pair of braces:  abcd(x+(y-z))efgh  --> abcdx+(y-z)efgh
> 
> This, I believe, can't be achieved only with regexps. I'd write a
> small external program and use it as a filter.
> 
> > # prefix to postfix operator: ++i --> i++
> >          [ Edit s/\+\+[a-zA-Z]+[0-9a-zA-Z]*/&++/ Edit s/\+\+/d]
> 
> using the \1 (used to be undocumented on plan9) may be sometimes easier
> Edit s/\+\+([A-Za-z]+[A-Za-z0-9])*/\1++/

should be "Edit s/\+\+([A-Za-z]+[A-Za-z0-9]*)/\1++/"

ideally one should include _ and ¡-￿.

- erik



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

* Re: [9fans] How to do this with [acme | sam | sed ] ?
  2013-01-11 14:24   ` erik quanstrom
@ 2013-01-11 15:16     ` Rudolf Sykora
  0 siblings, 0 replies; 12+ messages in thread
From: Rudolf Sykora @ 2013-01-11 15:16 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 11 January 2013 15:24, erik quanstrom <quanstro@quanstro.net> wrote:
>> # remove outermost pair of braces:  abcd(x+(y-z))efgh  --> abcdx+(y-z)efgh
>>          [ no idea :-( ]
>
> this is made simple since * is "greedy":
>
> Edit s:\((.*)\):\1:g
>

Sure, this (the greediness) basically already stands behind the solution
of N. Bercher above (though it was unnecessarily complicated). The problem with
such solutions is that you must always ensure there is just one
'expression' that
you want to be edited in the dot. Being so, the 'clicking' solution
proposed by B. Fabian
might be easier (but it depends). General solution (which would handle multiple
expressions at once), I think, is beyond simple regexps.

Ruda



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

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

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-11 11:19 [9fans] How to do this with [acme | sam | sed ] ? Peter A. Cejchan
2013-01-11 11:44 ` Rudolf Sykora
2013-01-11 12:24   ` Peter A. Cejchan
2013-01-11 12:27     ` dexen deVries
2013-01-11 12:38       ` Bence Fábián
2013-01-11 14:24   ` erik quanstrom
2013-01-11 15:16     ` Rudolf Sykora
2013-01-11 11:46 ` Bence Fábián
2013-01-11 12:07   ` Peter A. Cejchan
2013-01-11 12:09 ` Nicolas Bercher
2013-01-11 13:10   ` Peter A. Cejchan
2013-01-11 13:24     ` Nicolas Bercher

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