!Edit search/replace
Chris Hall (132) 3554 posts |
I should like !Edit’s search/replace facility to be able to store the ten most recently used search/replace strings rather than just one. I should also like to be able to load a script file that would populate these ‘last ten’ so that I could apply them one by one. Ideally I would like !Edit to be able to process a script file containing a list of successive search/replace strings. I frequently have the need to do the following set of search/replace operations, with the end-of-file replace option:
and it would be nice to have this automated. |
Steve Pampling (1551) 8155 posts |
I think we may have been here before, but I think you are basically asking for StrongED. InsertFile (filename) |
Chris Hall (132) 3554 posts |
I cannot get my head around StrongEd’s search/replace syntax though to get an exactly equivalent search/replace to the one I describe for !Edit. |
Steve Pampling (1551) 8155 posts |
Sorry, I wasn’t aware that Edit had that complex a search and replace facility. |
Fred Graute (114) 645 posts |
A brief comparison (by me) of Edit vs StrongED searching can be found here If you need any further help, just ask. |
Chris Hall (132) 3554 posts |
That’s very helpful. I’ll try it when I have a moment. |
GavinWraith (26) 1563 posts |
This script will do n consecutive replacements, of the from s by the to s, in a StrongED window when SHIFT-dragged to its apply icon. Fill in the values of the from s and to s with the appropriate strings.
|
Fred Graute (114) 645 posts |
Gavin’s Lua script is one way of automating this with StrongED. Another is to use named search/replace expressions and then use them in the Replace function. For this you need to add the required definitions to a ModeFile. If we call your list of replacements S1,R1 … S5,R5 then you’d have to make the following additions to an appropriate mode (either an existing mode or a newly created one). Search, Replace and Functions are sections in a ModeFile.
You can then execute the list of replacements by using the associated key/icon/menu. It might seem a bit cryptic right now but once you’ve done this a few times it becomes very easy to add this kind of functionality through ModeFiles. |
Vince M Hudd (116) 534 posts |
Chris:
Or you could just use a different application that can process search and replace [and various other] operations from a script. A fugly script language, but that’s another matter. ;) I don’t know the Edit syntax (having not touched edit since around the time the dinosaurs died out), so I can’t be 100% sure – but I’d hope it can do the specific search and replace tasks you need. If not, you know the developer. Looking at your list and trying to remember, though: [09][0D]$ to [09]\ [0D]$ - replace blank R.H. cell with hard space Would become: Replace.ChangeFrom = "|i|m|j" Replace.ChangeTo = "|i |m|j" Content.Replace I’m not sure why you’re calling that a “blank R.H. cell” though – it appears to be a tab followed by an alien end of line – and you aren’t replacing it with a non-breaking space, you’re inserting a non-breaking space between the tab and the line ending. <br>$ to <br> - delete [CTRL]-ENTER after <br> (repeat until none found) That’s a more difficult one. The basic search and replace is easy enough: Replace.ChangeFrom = "<br>|j" Replace.ChangeTo = "<br>" Content.Replace The problem is making it repeat until it doesn’t find any – there’s currently no mechanism in WebChange to do that. Should be possible to add, though. [0D]$ to \\ - remember end of full line as '\' That would be: Replace.ChangeFrom = "|m|j" Replace.ChangeTo = "\" Content.Replace I’m curious as to how a line with a carriage return as well as a line feed is a “full line” though, and one without (next task) is presumably not. Something to do with how the file(s) are generated? $ to <space> - replace [CTRL]-ENTER with space other than end of line That’s: Replace.ChangeFrom = "|j" Replace.ChangeTo = " " Content.Replace And finally, [sort of] reversing the one before the last: \\ to $ - replace end of full line Is: Replace.ChangeFrom = "\" Replace.ChangeTo = "|j" Content.Replace The full script, then, with some added comments and conveniently ignoring the need for conditional repetition on the 2nd: WebChange.Script ; None of what follows uses wildcards so let's switch 'em off for efficiency Replace.Wildcards = "No" ; Case insensitivity is also unnecessary - so a bit more efficiency Replace.CaseSensitive = "Yes" ; Insert a non-breaking space between a tab and CRLF line ending Replace.ChangeFrom = "|i|m|j" Replace.ChangeTo = "|i |m|j" Content.Replace ; Get rid of linefeeds after <br> tags - the bit that needs to be conditionally repeated Replace.ChangeFrom = "<br>|j" Replace.ChangeTo = "<br>" Content.Replace ; 'hide' CRLF line endings from the next search and replace Replace.ChangeFrom = "|m|j" Replace.ChangeTo = "\" Content.Replace ; Replace linefeeds with spaces Replace.ChangeFrom = "|j" Replace.ChangeTo = " " Content.Replace ; now put those original line endings back - but as LFs only Replace.ChangeFrom = "\" Replace.ChangeTo = "|j" Content.Replace Since part of the process effectively changes those CRLF line endings with LF only, it’s a pity you need to change LF-only line endings with spaces first – WebChange currently provides no mechanism to replace something conditionally in the way that’s needed. Otherwise we could reduce the number of steps, and change one search/replace with a different function. Edit: while I was correctly turning your [0D] into |m in each case, I was forgetting in the case of $ (i.e. [0A]) and using |a instead of |j – do’h! Also, I’m not 100% sure OTTOMH it’s “Yes”/“No” for the settings. It might be “On”/“Off”. Perhaps I do need a manual after all ;) Steve:
Go to its “Find” menu item, and in the dialogue select the “Magic characters” option. |
Steve Pampling (1551) 8155 posts |
That’s he sort of search & replace where you drop in a temporary alternate string for one string containing a specific substring and then do the replace on the remaining substring instances then replace the temporary string with the intended target string. |
Chris Hall (132) 3554 posts |
I’m not sure why you’re calling that a “blank R.H. cell” though The source file is a TAB-separated, no-quotes csv file saved by OpenOfficeCalc (Excel 97 can’t cope with this). If the rightmost cell is blank rather than space, this makes sure it is a (non-breaking) space (for later processing). CR’s entered in a cell (to make it readable) appear as LF, end of line as CRLF. Deliberate ‘new lines’ are entered in a cell as “<br>”. The full, gory detail is here and I have written it up for Archive magazine. I used to produce a book relying on IE6 to format a rather complex HTML table, printed by Acrobat Distiller. I decided to justify the text and render the pages myself as IE kept getting updated and (in Windows-speak) improved. |
Vince M Hudd (116) 534 posts |
Quite so – and that’s what Chris’ original sequence does in Edit, and my script therefore does in WebChange. It would be feasible for me to add a couple of variables to the search and replace function (one to specify a string that needs to be protected and another to define the protection string) which would therefore allow the final three steps to be rolled into one in the script but in reality WebChange would still be performing three search and replace operations, so it wouldn’t really add much – other than to make the script itself shorter. |
Vince M Hudd (116) 534 posts |
Ah, okay – that explains not only the inserted non-breaking space, but also the reason for the mixed line endings. |