Menu

Global replace

Help
2007-03-06
2012-12-07
  • Roger Sperberg

    Roger Sperberg - 2007-03-06

    I've found doing global replacements in XCE can sometimes be frustrating.

    In the first place, the fields are too short for about half of the replacements I'm doing, so I can't really see everything to make sure it's right.

    I tried the workaround of building the search string and replacement string in a document window intending to copy and paste them in to the boxes but that doesn't work -- you can't leave the global replace dialog to go and copy the second string. That is, you can't click back in your document window and cancelling loses the first string.

    (Really painful workaround -- make one string consisting of both pieces and paste it into both text boxes and delete the unnecessary half in each box.)

    What's also frustrating is when I construct a fairly elaborate regex and make a change and then realize I made a mistake. Undoing the mistake is OK, but when I go back to the replace dialog, I can't just edit the regex because 9 times out of 10 it's gone, so I have to reconstruct it from scratch, only this time fixing the mistake.

    Comparing this to TextPad, the editor I'm coming from:
    - find next, replace and replace next are in the same dialog so the regex can be tested
    - the contents of each box persist
    - you can move between dialog and windows with no problems
    - the current and the previous 9 search and replace strings are available so you can recall a previous action (especially useful when performing several replacements on different files)

    TextPad's replace feature isn't ideal -- I would make the number recallable strings much larger, it will _only_ do greedy regex searches, and I ultimately went in and edited the binary file to make the dialog much wider and the font used bigger -- but it highlights where XCE could improve.

    I have some other info and thoughts on replace, but I'll put them in a separate message so as not to make complicated threads.

    Roger

     
    • gnschmidt

      gnschmidt - 2007-03-06

      Thanks Roger, I agree 100%. For 1.0.9.1 I will widen the input fields for the Global Replace. (The replace pane is limited here as it has to fit on a 800x600 screen, hence the short fields & Regex rather than Regular Expressions.

      <the contents of each box persist>
      They should, so this is a bug.

      <You can move between dialog and windows with no problems.>
      Good point. I'll try to make the dialog non-modal.

      <the current and the previous 9 search and replace strings are available so you can recall a previous action (especially useful when performing several replacements on different files)>
      Yes, this would be very useful. I need to look into ways of doing this. Were you thinking of RAM caching only, or would you expect the strings to persist when the application closes?

      Best,
      Gerald

      PS The global replacement regexes are full Perl-compatible regexes. The incremental find/replace regexes use Scintilla's minimal, built-in regular expression engine.

       
    • Roger Sperberg

      Roger Sperberg - 2007-03-06

      I have only been using Global Replace, so I didn't realize the Replace panel had Replace and Replace All. I might try using that instead (don't know if I'll bump up against a regex limitation there).

      If it doesn't seem like overkill to you, you might add a Replace Next button -- Replace leaves the insertion point where it is, Replace Next is like clicking Find Next after replacing. Sometimes you want to stick around when you make the replacement to see that it worked properly and after a few you want to go on to the next right away, so having both seems useful to me.

      In TextPad, the previous search and replace strings show up as entries in a popup menu. That works fine for "let's do several replacements and then do to a new file and do the same replacements." The search and replace strings do persist between sessions and I do access them from previous days, if I can. They cycle out pretty fast when you're really massaging a text. 

      I've thought it would be nice to be able to permanently preserve any search or replace string (or as a pair with a single click) and then be able to recall them later. For instance, I might convert an e-book to FB2 format and then not make the same conversion to another text for a couple months. But the same replacements need to be made.

      As for that, however, TextPad has a clip library for cutting and pasting re-used text, but I never explored its use for these search-and-replace strings. I guess what I'm saying is that I think this is what I want, but it's not something I've ever used so I can't confirm its utility. It just seems so practical though.

      Thanks,

      Roger

       
    • gnschmidt

      gnschmidt - 2007-03-08

      <In the first place, the fields are too short for about half of the replacements I'm doing, so I can't really see everything to make sure it's right.>
      I've made the fields larger for version 1.0.9.1. Does the new size work better? The other enhancements are still in progress.
      -Gerald

       
    • Roger Sperberg

      Roger Sperberg - 2007-03-08

      I'll have to try 1.0.9.1 -- you're faster with fixes than I'm used to keeping up with! :-)

      What I've been doing -- what I did yesterday, I guess, is more accurate -- is to write the regex search and replacement strings in a plain text editor window (TextPad), then copy and paste them into the Replace panel boxes.

      None of the regexes I've written has worked there, btw.

      However, when I choose Global Replace (which I'm restricting to the current document), the search string is filled in, and some of the time the replace string is as well. If not, it's still in my clipboard and I paste it in, then do the replace all from that dialog.

      What seems to persist in the boxes in Global Replace is the content in the Replace panel boxes, as opposed to what was last entered in Global Replace. A couple times I clicked out of the replace string box in the Replace panel and voila that text appeared in Global Replace replace string box. But this didn't always work, so I'm not sure what the trigger is.

      ^ to indicate beginning of line and $ to indicate end definitely aren't working in Global Replace for me. Could be a "the regex version I learned" vs "Perl version of regex" issue but I can't say for sure till I look into it a lot closer.

      Thanks,

      Roger

       
      • gnschmidt

        gnschmidt - 2007-03-08

        Hi Roger

        I think you'll find the ^ matches the beginning of the document. To match the beginning of lines other than the first, you should be able to use \n.

        As you say, the built-in regex engine used for the panels is not quite satisfactory.

        -Gerald

         
    • Roger Sperberg

      Roger Sperberg - 2007-03-09

      The larger fields in Global Replace are much appreciated.

      As it happens, many of the regexes I'm writing are even longer than this (in this month's project, about 100 characters seems to be the limit).

      If you make the dialog even wider (your choice, but I'm in favor) AND you make it non-modal, I'd suggest making it as short as possible, so it won't cover up too much territory if the user leaves it open.

      Roger

       
    • gnschmidt

      gnschmidt - 2007-03-09

      Will look into this. Making the dialogue non-modal is not entirely trivial as it would share a message queue with the main window (potentially containing a find/replace panel etc.).

      In any case limiting the height is a good idea and I'm happy to stretch the input boxes a little further.

      -G

      PS I never said _why_ ^ matches the start of the document: it's standard scripting practice to read files one line at a time, perform matches and move on to the next line. Fetching the lines from the editor one line at a time would be much slower. What I need to find out is if there is a setting that treats ^ as either start of string or start of line.

       
    • Roger Sperberg

      Roger Sperberg - 2007-03-09

      I've learned one new thing about the replacing.

      If I paste in a regex into the Find: box in the Replace panel, and paste in a regex into the Replace with: box, and then choose Global Replace, then only the regex in the Find: box is in the Global Replace dialog. As best as I can recall, the Replace with: field there is occupied by whatever was in the Replace panel's replace field prior to my pasting.

      However . . .

      if I first click on Find Next or Replace All (never tried the third button), even if nothing is found, THEN when I go to Global Replace both boxes there have what I pasted into the Replace panel boxes.

      So this is my workaround for not having a non-modal dialog:
      - write the regexes in a text editor
      - copy and paste them into the Replace panel boxes
      - click on Find Next
      - choose the Global Replace command
      - make sure that "Replace in all open documents" is deselected
      - click on OK to make the change to all the instances in my document

      It's a workaround, but it gets me there.

      Because these boxes in Global Replace are so important, I wonder if there is some way to make the font in the box itself larger, or maybe a different font?

      Typically, my system is set to use a sans-serif, proportional font for text boxes, but in TextPad I went in with a binary editor and changed the code directly so that Courier was used in the Find and Replace dialogs, to make sure the regexes were easier to check.

      I don't know that that is what you want to do in this application but I do want to bring it to your attention.

      ----

      Btw, I will just add as an aside that I have yet to write a regex that works in the Replace panel. It doesn't seem like what I'm doing is all that complex but that regex engine must be _really_ limited.

       
      • gnschmidt

        gnschmidt - 2007-03-09

        Roger, I'm afraid you're right: the regex engine built into Scintilla is VERY limited. Basically it lets you define simple groups [a-z] and offers memory (though annoyingly only if the parantheses are preceded by a backslash) with \1, \2 access in the replacement string.

        -Gerald

        PS I will try to find out why find/replace strings are only remembered after Find Next is pressed.

         

Log in to post a comment.