Discussion:
How to select multiple lines
Eric Bouyoux
2009-09-08 07:14:07 UTC
Permalink
Hi,

The title is not very explicit. Let's have an example.
My file contains :
module toto ;
... (1000 lines of code)
endmodule

I want to remove all lines between "module toto" and "endmodule".
One possibility is to select all lines between the 2 keywords and to
remove them. But how can I do this automaticaly ?

I tried with the replace function and the following reg exp but it
didn't work (^module.+endmodule).

Regards.

Eric Bouyoux.
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Matthijs van Aalten
2009-09-08 07:27:04 UTC
Permalink
Hi,

Try the following search/replace:
Search for: "(?n(^module toto ;\n).*(^endmodule\n))"
Replace with: "\1\2"
(enable reg. expression search, of course)
(and only the part within the double quotes - not the double quotes themselves)

Your problem is that regular expressions in NEdit by default do not match newlines, so your part with ".+" does not match multiple lines. If you make a regular expression with the construction
"(?n<regexp>)", it does match newlines. See menu "Help => Regular Expressions => Parenthetical Constructs" for more information on this topic.

The rest is standard stuff: search for a line starting with 'module toto ;' and a newline, keep this line in buffer #1; then match one or more characters including newlines, then match a line starting with 'endmodule' and a newline (and keep this line in buffer #2). Replace all this with the content of buffers #1 and #2.

Regards,
Matthijs van Aalten


-----Original Message-----
From: discuss-bounces-***@public.gmane.org [mailto:discuss-bounces-***@public.gmane.org] On Behalf Of Eric Bouyoux
Sent: Tuesday 8 September 2009 9:14
To: General NEdit discussion list
Subject: How to select multiple lines

Hi,

The title is not very explicit. Let's have an example.
My file contains :
module toto ;
... (1000 lines of code)
endmodule

I want to remove all lines between "module toto" and "endmodule".
One possibility is to select all lines between the 2 keywords and to
remove them. But how can I do this automaticaly ?

I tried with the replace function and the following reg exp but it
didn't work (^module.+endmodule).

Regards.

Eric Bouyoux.
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Thomas Orgis
2009-09-08 07:59:29 UTC
Permalink
Am Tue, 08 Sep 2009 09:14:07 +0200
Post by Eric Bouyoux
Hi,
The title is not very explicit. Let's have an example.
module toto ;
... (1000 lines of code)
endmodule
I want to remove all lines between "module toto" and "endmodule".
One possibility is to select all lines between the 2 keywords and to
remove them. But how can I do this automaticaly ?
Interesting point. I am not sure how many other Fortran programmers are here... there is an equivalent task in C-style languages, the operation to got to a machting bracket/brace/parentheses:

function bla()
{
(100 lines of code)
}

You can place the cursor on the first {, then press Ctrl+M and the cursor jumps to the closing brace. The interesting part for you is that you can hold the shift key while doing that, marking the whole block as result.
OK, that marks the braces, too, and they will be removed when you hit "delete", but they are easily replaced...

The whole functionality to jump to the end of a block would be nice for Wirth/Fortran-style languages (with begin / end, if / end if, do / end do, ...) when it worked with words instead of only braces / parentheses.
I'm quite confident that one could add this functionality as macro (is the current Ctrl+M already a macro, perhaps?), but I am not friends of the nedit macro language. I just keep getting told that I can implement every feature I want with it (visual indent of soft-broken lines, for example).


Alrighty then,

Thomas.

PS: I have to nit-pick: A 1000-line module would always reside in its own file in my code... so removing all the inner module code would involve pressing shift, then ctrl+end to mark everything up to the end... going a line back (to keep "end module"), hit delete.
Erez Amit
2009-09-08 08:56:59 UTC
Permalink
Hi,
There's a macro on the Niki site called Verilog Find Pair (
http://nedit.hackvalue.nl/niki/index.php/VerilogFindPair). It's called that
way because it was initially written with Verilog keywords in mind, other
then that it can be easily customized and used in any other language.

Currently the macro does the following:
You place the cursor on a supported keyword, press the macro's bind-key or
accelerator and the macro jumps-to and selects the corresponding keyword.
In Eric's case it would either jump from module to endmodule or the other
way around.

It should be easy enough to add a 'select' option that would select all text
between the keywords. I'm currently quite busy, but if you have the patience
Eric, I'll do it as soon as I can.

Regards,
Erez
Post by Thomas Orgis
Am Tue, 08 Sep 2009 09:14:07 +0200
Post by Eric Bouyoux
Hi,
The title is not very explicit. Let's have an example.
module toto ;
... (1000 lines of code)
endmodule
I want to remove all lines between "module toto" and "endmodule".
One possibility is to select all lines between the 2 keywords and to
remove them. But how can I do this automaticaly ?
Interesting point. I am not sure how many other Fortran programmers are
here... there is an equivalent task in C-style languages, the operation to
function bla()
{
(100 lines of code)
}
You can place the cursor on the first {, then press Ctrl+M and the cursor
jumps to the closing brace. The interesting part for you is that you can
hold the shift key while doing that, marking the whole block as result.
OK, that marks the braces, too, and they will be removed when you hit
"delete", but they are easily replaced...
The whole functionality to jump to the end of a block would be nice for
Wirth/Fortran-style languages (with begin / end, if / end if, do / end do,
...) when it worked with words instead of only braces / parentheses.
I'm quite confident that one could add this functionality as macro (is the
current Ctrl+M already a macro, perhaps?), but I am not friends of the nedit
macro language. I just keep getting told that I can implement every feature
I want with it (visual indent of soft-broken lines, for example).
Alrighty then,
Thomas.
PS: I have to nit-pick: A 1000-line module would always reside in its own
file in my code... so removing all the inner module code would involve
pressing shift, then ctrl+end to mark everything up to the end... going a
line back (to keep "end module"), hit delete.
--
http://www.nedit.org/mailman/listinfo/discuss
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Eric Bouyoux
2009-09-08 13:37:27 UTC
Permalink
Hi,

Thank you for all the explanations.
I knew I could use keywords (module and endmodule) and then the ^M key
(go to matching).
These 2 keywords are not recognized in my nedit environment but I know
how to make it work.
But I wanted something more general such as Matthijs van Aalten's
regular expression in a "Replace" window "(?n(^module toto
;\n).*(^endmodule\n))" but it does not exactly works the way I want. It
starts from the first "module" found and goes to the very last
"endmodule" in the file. I want it to stop at the FIRST "endmodule"
encountered.
I tried several changes in the reg exp but I could not make it work.
Any idea ?

Regards.

Eric Bouyoux.
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Matthijs van Aalten
2009-09-08 13:47:05 UTC
Permalink
Hi,

Ah, you want lazy matching instead of greedy...
Search for: "(?n(^module toto;\n).*?(^endmodule\n))"
Replace with: "\1\2"

Adding a "?" to a ".", "*" or "?" will match as little as possible, instead of the default as much as possible.

Regards,
Matthijs


-----Original Message-----
From: discuss-bounces-***@public.gmane.org [mailto:discuss-bounces-***@public.gmane.org] On Behalf Of Eric Bouyoux
Sent: Tuesday 8 September 2009 15:37
To: General NEdit discussion list
Subject: Re: How to select multiple lines

Hi,

Thank you for all the explanations.
I knew I could use keywords (module and endmodule) and then the ^M key
(go to matching).
These 2 keywords are not recognized in my nedit environment but I know
how to make it work.
But I wanted something more general such as Matthijs van Aalten's
regular expression in a "Replace" window "(?n(^module toto
;\n).*(^endmodule\n))" but it does not exactly works the way I want. It
starts from the first "module" found and goes to the very last
"endmodule" in the file. I want it to stop at the FIRST "endmodule"
encountered.
I tried several changes in the reg exp but I could not make it work.
Any idea ?

Regards.

Eric Bouyoux.
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Eric Bouyoux
2009-09-08 13:59:01 UTC
Permalink
Post by Matthijs van Aalten
Hi,
Ah, you want lazy matching instead of greedy...
Search for: "(?n(^module toto;\n).*?(^endmodule\n))"
Replace with: "\1\2"
I already tried it but it does not do the job. It still goes the the
very last endmodule.

Regards.

Eric.
Post by Matthijs van Aalten
Adding a "?" to a ".", "*" or "?" will match as little as possible, instead of the default as much as possible.
Regards,
Matthijs
-----Original Message-----
Sent: Tuesday 8 September 2009 15:37
To: General NEdit discussion list
Subject: Re: How to select multiple lines
Hi,
Thank you for all the explanations.
I knew I could use keywords (module and endmodule) and then the ^M key
(go to matching).
These 2 keywords are not recognized in my nedit environment but I know
how to make it work.
But I wanted something more general such as Matthijs van Aalten's
regular expression in a "Replace" window "(?n(^module toto
;\n).*(^endmodule\n))" but it does not exactly works the way I want. It
starts from the first "module" found and goes to the very last
"endmodule" in the file. I want it to stop at the FIRST "endmodule"
encountered.
I tried several changes in the reg exp but I could not make it work.
Any idea ?
Regards.
Eric Bouyoux.
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Andrew Hood
2009-09-08 22:19:45 UTC
Permalink
Post by Eric Bouyoux
Hi,
Thank you for all the explanations.
I knew I could use keywords (module and endmodule) and then the ^M key
(go to matching).
These 2 keywords are not recognized in my nedit environment but I know
how to make it work.
But I wanted something more general such as Matthijs van Aalten's
regular expression in a "Replace" window "(?n(^module toto
;\n).*(^endmodule\n))" but it does not exactly works the way I want. It
starts from the first "module" found and goes to the very last
"endmodule" in the file. I want it to stop at the FIRST "endmodule"
encountered.
I tried several changes in the reg exp but I could not make it work.
Any idea ?
You could be running up against the maximum size of a regex match. You
can not find/replace a string longer that that limit.

In nedit.h it says:

#define SEARCHMAX 5119 /* Maximum length of search/replace
strings */

Change it to something bigger - I user 65535 with no obvious ill effects
- and recompile.
--
There's no point in being grown up if you can't be childish sometimes.
-- Dr. Who
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Philippe Poilbarbe
2009-09-08 08:48:48 UTC
Permalink
Post by Thomas Orgis
Am Tue, 08 Sep 2009 09:14:07 +0200
Post by Eric Bouyoux
Hi,
The title is not very explicit. Let's have an example.
module toto ;
... (1000 lines of code)
endmodule
I want to remove all lines between "module toto" and "endmodule".
One possibility is to select all lines between the 2 keywords and to
remove them. But how can I do this automaticaly ?
function bla()
{
(100 lines of code)
}
...
There is no kind of braces to delimit blocs in fortran. It is done by
keywords or by lines.

You can do what you want
Replace the function by nothing. The replacement done by using regular
expressions.
Put the RE "module\s+toto(?n.*?)endmodule" (without quotes) in the
"string to find" box and nothing in the "replace with" box and click on
"Regular expression".
The (?n) construct instruct the search process to include the newline in
the characters matched by '.'.
The '?' character is there to stop on the first 'endmodule' encountered
(for the case there is more than one module in the file).

To be sure you take the whole lines you can enhance the RE with this
(but not very readable :) ):
^\s*module\s+toto(?n.*?)\n\s*end\s*module\s*$

This take also the spaces before 'module' and the ones after 'endmodule'
(end maybe some between 'end' and 'module')
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Eric Bouyoux
2009-09-08 14:10:12 UTC
Permalink
Hi,

The following regexp from Philippe Poilbarbe works fine :
"module\s+(?n.*?)endmodule"

I am not sure to understand the reason why it works. Should it be read as :
I search for "module" followed by at least one space or tab followed by
0 or more of any character including newline preceding "endmodule". The
number of character including newline preceding "endmodule" should be as
small as possible (? keyword).

Thank you.

Eric.
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Continue reading on narkive:
Loading...