Selecting a C function in Acme

143 views
Skip to first unread message

Deepanjan Kesh

unread,
Dec 3, 2022, 8:03:47 AM12/3/22
to plan9port-dev
Hello all,

I have tried to construct a minimal example for selecting the function
"hello" in Acme, and the problem I am facing.

To select the funtion mentioned, I am using the following -

   
:0+/^void hello\(\)\n/,.+/^}/

If my cursor is before the closing brace of "main", Acme generates

    addresses out of order

On the other hand, if it is after the brace, it selects the function.

Can anybody help with the mistake I am making?

Thank you,
Deepanjan Kesh


#include <stdio.h>

void hello();

int main()
{
    hello();
   
    return 0;
}

void hello()
{
    printf("hello, world!\n");
}

Jacob Vosmaer

unread,
Dec 3, 2022, 10:04:34 AM12/3/22
to plan9port-dev
This seems to work:

:/^void hello\(\)\n(([^}].*)?\n)*}

Op za 3 dec. 2022 om 14:03 schreef Deepanjan Kesh <deep...@gmail.com>:
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "plan9port-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to plan9port-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/plan9port-dev/105e617d-3470-41af-9837-20c39b08e4e6n%40googlegroups.com.
Message has been deleted

Deepanjan Kesh

unread,
Dec 3, 2022, 11:36:54 PM12/3/22
to plan9port-dev
Thank you, it works but with a caveat - the expression only works within an Acme window. But I wanted to use as text file hyperlinking as

    file_name:address

and unfortunately it does not work in this scenario.

Any help or suggestion would be greatly appreciated.


Jacob Vosmaer

unread,
Dec 4, 2022, 6:41:30 AM12/4/22
to plan9port-dev
It appears that with the addr,addr form, the regexes both get
evaluated from the same starting point so the right hand side will
capture the first closing brace it finds.

I don't use the addr,addr form often so I don't know exactly what is
and isn't possible with it. But looking at what your goal was, a
multi-line regex seemed like it should work and it did.


Op zo 4 dec. 2022 om 04:59 schreef Deepanjan Kesh <deep...@gmail.com>:
>
> Thank you, it works perfectly fine. I will also very much appreciate if anybody can point out the mistake in my expression.
> To view this discussion on the web visit https://groups.google.com/d/msgid/plan9port-dev/d5f61ac5-4f2c-4863-b781-e97e880b96e5n%40googlegroups.com.

Deepanjan Kesh

unread,
Dec 4, 2022, 11:18:12 PM12/4/22
to plan9port-dev
I am writing certain notes about some code I am writing, and the file, I had hoped, would contain links to the code sections I am discussing. I was under the impression that selections in Acme and in file hyperlinking work in the same way, so I had asked help on the simpler of two scenarios. From your observations it seems that that is not the case.

Anyway, thank you for all your help. If anybody can resolve the issue, it would help me immensely.

Russ Cox

unread,
Dec 5, 2022, 2:23:05 PM12/5/22
to deep...@gmail.com, plan9port-dev
When you write 

    :0+/^void hello\(\)\n/,.+/^}/

both addresses 0+/^void hello\(\)\n/ and .+/^}/ are evaluated independently, which is why you get an out of order error the .+/^}/ finds some unrelated closing brace.

According to '9 man 1 sam', it looks like you want to use a semicolon instead of a comma, to use the 'a1;a2' form not the 'a1,a2' form. That is:

     :0+/^void hello\(\)\n/;.+/^}/

Best,
Russ


Deepanjan Kesh

unread,
Dec 5, 2022, 8:40:21 PM12/5/22
to plan9port-dev
Dear Russ,

Thank you for your solution - it works perfectly.

I, too, came up with a way to select a code section, albeit a bit cumbersome

1) For the first address, search for the beginning of the function as

   
0+/^void hello\(\)\n/

2) For the second address, search for the beginning of the function followed by the closing brace, as

    0+/^void hello\(\)\n/+/^}/

Combining the two gives us -

    :0+/^void hello\(\)\n/,0+/^void hello\(\)\n/+/^}/

Thank you,
Deepanjan Kesh
Reply all
Reply to author
Forward
0 new messages