9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Acme, Edit, code and newline
@ 2014-03-31 15:20 Daniel Peyrolon
  2014-03-31 15:36 ` Mark van Atten
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Peyrolon @ 2014-03-31 15:20 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

Hi there,

I'm using p9p's acme, and I would like to take a piece of code and change,
for example this:

int main(int argc, char *argv[]) {

For this:

int main(int argc, char *argv[])
{

So, for doing that, I thought about using some regexps and the Edit command.

I would like to work with some generic regexp, so I wrote the following:

Edit , x/^[^ ]+[ ]*[^(]*\([^)]*\)[ ]*\{[ ]*$/ s/[ ]*{[ ]*$/\n{/g

By the man, the x command, under sam(1) does execute the command after the
x. Also, we
have to use \n, instead of a real newline.

AFAICT, these two commands work, separatedly. Using the first one prints me
the whole
set of function definitions, and using the s// when selecting the line that
holds something like:

blah blah (blah blah) {

Does indeed change that for:
blah blah (blah blah)
{

But when used together, this command doesn't work. Could please someone
provide
me with some insight on why this doesn't work? Thanks a lot.

(Sorry for the blah)

--
Daniel

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

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

* Re: [9fans] Acme, Edit, code and newline
  2014-03-31 15:20 [9fans] Acme, Edit, code and newline Daniel Peyrolon
@ 2014-03-31 15:36 ` Mark van Atten
  2014-03-31 15:39   ` erik quanstrom
  2014-03-31 15:54   ` Daniel Peyrolon
  0 siblings, 2 replies; 9+ messages in thread
From: Mark van Atten @ 2014-03-31 15:36 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Edit , x/^[^ ]+[ ]*[^(]*\([^)]*\)[ ]*\{[ ]*\n/ s/[ ]*\{[ ]*\n/\n\{/g

Mark.



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

* Re: [9fans] Acme, Edit, code and newline
  2014-03-31 15:36 ` Mark van Atten
@ 2014-03-31 15:39   ` erik quanstrom
  2014-03-31 15:44     ` Mark van Atten
  2014-03-31 15:54   ` Daniel Peyrolon
  1 sibling, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2014-03-31 15:39 UTC (permalink / raw)
  To: 9fans

On Mon Mar 31 11:37:51 EDT 2014, vanattenmark@gmail.com wrote:
> Edit , x/^[^ ]+[ ]*[^(]*\([^)]*\)[ ]*\{[ ]*\n/ s/[ ]*\{[ ]*\n/\n\{/g

\ before { is not necesary.

- erik



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

* Re: [9fans] Acme, Edit, code and newline
  2014-03-31 15:39   ` erik quanstrom
@ 2014-03-31 15:44     ` Mark van Atten
  2014-03-31 15:46       ` erik quanstrom
  0 siblings, 1 reply; 9+ messages in thread
From: Mark van Atten @ 2014-03-31 15:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> \ before { is not necesary.

Don't know how I got that one in there; thanks for catching it!

Mark.



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

* Re: [9fans] Acme, Edit, code and newline
  2014-03-31 15:44     ` Mark van Atten
@ 2014-03-31 15:46       ` erik quanstrom
  0 siblings, 0 replies; 9+ messages in thread
From: erik quanstrom @ 2014-03-31 15:46 UTC (permalink / raw)
  To: 9fans

> > \ before { is not necesary.
>
> Don't know how I got that one in there; thanks for catching it!

it was in the original.

- erik



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

* Re: [9fans] Acme, Edit, code and newline
  2014-03-31 15:36 ` Mark van Atten
  2014-03-31 15:39   ` erik quanstrom
@ 2014-03-31 15:54   ` Daniel Peyrolon
  2014-03-31 16:23     ` Ruben Schuller
  2014-04-01  7:24     ` Mark van Atten
  1 sibling, 2 replies; 9+ messages in thread
From: Daniel Peyrolon @ 2014-03-31 15:54 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

> Edit , x/^[^ ]+[ ]*[^(]*\([^)]*\)[ ]*\{[ ]*\n/ s/[ ]*\{[ ]*\n/\n\{/g

So, it was simply a matter of changing "$" for "\n" at the x command!
How come my command didn't work?
It really should work with the "$", shouldn't it?

Or even without the \n or the $, since the regexp already matched until the
'{',
so the substitution should have worked.

Also, thanks for pointing me that the '\' wasn't actually needed.
Many thanks!



2014-03-31 17:36 GMT+02:00 Mark van Atten <vanattenmark@gmail.com>:

> Edit , x/^[^ ]+[ ]*[^(]*\([^)]*\)[ ]*\{[ ]*\n/ s/[ ]*\{[ ]*\n/\n\{/g
>
> Mark.
>
>


--
Daniel

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

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

* Re: [9fans] Acme, Edit, code and newline
  2014-03-31 15:54   ` Daniel Peyrolon
@ 2014-03-31 16:23     ` Ruben Schuller
  2014-04-01  7:24     ` Mark van Atten
  1 sibling, 0 replies; 9+ messages in thread
From: Ruben Schuller @ 2014-03-31 16:23 UTC (permalink / raw)
  To: 9fans

Hi,

2014-03-31 17:54 Daniel Peyrolon <tuchalia@gmail.com>:

> > Edit , x/^[^ ]+[ ]*[^(]*\([^)]*\)[ ]*\{[ ]*\n/ s/[ ]*\{[ ]*\n/\n\{/g
>
> So, it was simply a matter of changing "$" for "\n" at the x command!
> How come my command didn't work?
> It really should work with the "$", shouldn't it?
>
> Or even without the \n or the $, since the regexp already matched
> until the '{',
> so the substitution should have worked.

I'm not really that proficient in acme/sam but, from the sam
manpage:

       $      The null string at the end of the file.

I'd also recommend reading
http://doc.cat-v.org/bell_labs/sam_lang_tutorial/ .
It helped me a lot getting a better undestanding of the command
language.

Take care,
Ruben



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

* Re: [9fans] Acme, Edit, code and newline
  2014-03-31 15:54   ` Daniel Peyrolon
  2014-03-31 16:23     ` Ruben Schuller
@ 2014-04-01  7:24     ` Mark van Atten
  2014-04-01  8:23       ` Daniel Peyrolon
  1 sibling, 1 reply; 9+ messages in thread
From: Mark van Atten @ 2014-04-01  7:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, Mar 31, 2014 at 5:54 PM, Daniel Peyrolon <tuchalia@gmail.com> wrote:
>> Edit , x/^[^ ]+[ ]*[^(]*\([^)]*\)[ ]*\{[ ]*\n/ s/[ ]*\{[ ]*\n/\n\{/g
>
> So, it was simply a matter of changing "$" for "\n" at the x command!

Yes. (In the version I gave, the replacement of the second $, the one
in the s command, by \n was superfluous.)

> How come my command didn't work?
> It really should work with the "$", shouldn't it?

In the original version, the x command matches up to the end of the
line, but the resulting selection is no longer itself a line; so the
subsequent s command, trying to match various things and then the
empty string at the end of a line ($), does not succeed.

But replacing, in the x command, the $ by \n leaves the result of a
match (now one character longer because it includes the \n) a line, in
which the s command then successfully matches $.

As ever,
Mark.



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

* Re: [9fans] Acme, Edit, code and newline
  2014-04-01  7:24     ` Mark van Atten
@ 2014-04-01  8:23       ` Daniel Peyrolon
  0 siblings, 0 replies; 9+ messages in thread
From: Daniel Peyrolon @ 2014-04-01  8:23 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

Hi there everyone,

Many thanks for the explanation, it's much clearer now.


2014-04-01 9:24 GMT+02:00 Mark van Atten <vanattenmark@gmail.com>:

> On Mon, Mar 31, 2014 at 5:54 PM, Daniel Peyrolon <tuchalia@gmail.com>
> wrote:
> >> Edit , x/^[^ ]+[ ]*[^(]*\([^)]*\)[ ]*\{[ ]*\n/ s/[ ]*\{[ ]*\n/\n\{/g
> >
> > So, it was simply a matter of changing "$" for "\n" at the x command!
>
> Yes. (In the version I gave, the replacement of the second $, the one
> in the s command, by \n was superfluous.)
>
> > How come my command didn't work?
> > It really should work with the "$", shouldn't it?
>
> In the original version, the x command matches up to the end of the
> line, but the resulting selection is no longer itself a line; so the
> subsequent s command, trying to match various things and then the
> empty string at the end of a line ($), does not succeed.
>
> But replacing, in the x command, the $ by \n leaves the result of a
> match (now one character longer because it includes the \n) a line, in
> which the s command then successfully matches $.
>
> As ever,
> Mark.
>
>


--
Daniel

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

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

end of thread, other threads:[~2014-04-01  8:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-31 15:20 [9fans] Acme, Edit, code and newline Daniel Peyrolon
2014-03-31 15:36 ` Mark van Atten
2014-03-31 15:39   ` erik quanstrom
2014-03-31 15:44     ` Mark van Atten
2014-03-31 15:46       ` erik quanstrom
2014-03-31 15:54   ` Daniel Peyrolon
2014-03-31 16:23     ` Ruben Schuller
2014-04-01  7:24     ` Mark van Atten
2014-04-01  8:23       ` Daniel Peyrolon

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