SlickEdit Community
SlickEdit Product Discussion => SlickEdit® => Features and/or Improvements => Topic started by: eitheta on February 11, 2015, 10:40:18 PM
-
I wish the Find & Replace dialog could run a sed script, rather than just one Search/Replace expression-pair at a time.
-
I wish the Find & Replace dialog could run a sed script, rather than just one Search/Replace expression-pair at a time.
It might be possible with a macro. Can you post a simple example of what the sed script would look like and what it's trying to do.
-
In general, I'm just massaging a portion of a text file. With three or four regex substitutions in a row (each one being of middling complexity). sed would almost be overkill, as I'd probably never use anything except the s/// or s///g command.
An example:
s/^[ \t]*\/\/.*\n//
s/C_DATA_WIDTH[ \t]*-[ \t]*1/63/
s/KEEP_WIDTH[ \t]*-[ \t]*1/7/
s/^[ \t]+(input|output|inout)[ \t]*\[([0-9]+)[ \t]*:[ \t]*([0-9]+)\][ \t]+([a-z][a-zA-Z0-9_]+),[ \t]*$/ \1 [\2:\3] ~\4 ,
s/^[ \t]+(input|output|inout)[ \t]+([a-z][a-zA-Z0-9_]+),[ \t]*$/ \1 ~\2 ,
If it gets more complicated than this, then I write a throwaway python script to do the massaging. If I can do what I need with just one substitution, then of course I do that within SE's Replace dialog. It's when it cannot be done in one step, then I have this discontinuity in my flow. Instead of the Replace dialog somehow growing smoothly to handle the slightly-more-complex task, I have to jump to a different tool (python, sed, etc). Back in the day, CodeWright had an embedded Perl interpreter, that could easily serve as a regex search-and-replace on steroids.
So yes, I think I could create a macro that would run a fileful of s/findpatt/subpatt/g lines. Perhaps I should give it a go - it might turn out less clunky / more usable than I expect.
Thanks.
-
I also would love such a macro that could apply multiple search and replace expressions. I have a set of Perl regexp's I use to clean up code and its a pain to use 1 at a time.
-
I also would love such a macro that could apply multiple search and replace expressions. I have a set of Perl regexp's I use to clean up code and its a pain to use 1 at a time.
Using macro recording you can soon see what to do.
In the call to _mfreplace2 below, the third argument has
* = replace all without prompting
I = case insensitive
L = perl reg exp.
The fifth argument ('') is an exclude file list
The sixth argument '4' selects "append to output"
The 7th argument ('1') selects search results tab 1
The final argument selects "don't show diff"
_command void run_perl_search_replace1() name_info(','VSARG2_REQUIRES_EDITORCTL)
{
_macro('R',1);
clear_highlights();
_mfreplace2('abc.def','123.456','LI*','<Workspace>','*.*','','','1','0');
_mfreplace2('123.456','abc.def','LI*','<Workspace>','*.*','','4','1','0');
_mfreplace2('etc','etc','LI*','<Workspace>','*.*','','4','1','0');
}
-
@rgloden and @eitheta, Edit->Other->Filter Selection... allows you to pipe a selected portion of a file through any external program. If you have a filter that is more complicated than you can easily describe in a regex, this is an easy way to bring more sophisticated tools to bear.