help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: search across linebreaks


From: Drew Adams
Subject: RE: search across linebreaks
Date: Sun, 17 Feb 2013 07:52:35 -0800

> I'm going to need to do a large scale search-and-replace on a 
> series of text files, using a sort of dictionary or hash-table of 
> search terms and their replacement. The text files are filled
> to the usual fill column.  The search terms may be broken across
> linebreaks, and I'm not sure of the best way to handle this.
> If it was regular English words I could probably manage a
> programmatic version of `isearch-toggle-word', but in
> this case these are solid strings, and might be broken anywhere.
> 
> The two solutions I can think of are: 1) break up the characters
> in the search string and insert "\n?" between each one to create
> regexps to search on, and 2) unfill the whole file at the start
> of the procedure and then refill it afterwards. Neither of these
> seems like a great idea -- does anyone have any brighter ideas?

What's not clear is whether any of the newline chars are significant.  From what
you wrote I'm guessing no: they can all be ignored or just removed.  But in that
case, filling would mean filling one big paragraph.

Or perhaps consecutive newlines (\n\n) are significant, separating paragraphs?
In that case, you could remove all newlines except one for each consecutive
group (i.e., paragraph separation).

Assuming no newlines are significant (or only one of consecutive ones is), the
two solutions you propose sound reasonable to me.  Which of them to use might
depend on size etc. - relative time to remove newlines and later refill vs the
\n? regexp match time.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]