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

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

Re: search across linebreaks


From: Eric Abrahamsen
Subject: Re: search across linebreaks
Date: Mon, 18 Feb 2013 11:52:58 +0800
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2 (gnu/linux)

"Drew Adams" <drew.adams@oracle.com> writes:

>> 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.

Thanks to all! Sed is something I've considered learning, but given its
learning curve, and the time I've already put into elisp, (and the fact
that I'm not even "supposed" to be a programmer in the first place!)
I'll probably go with an in-emacs solution.

For the unfill solution, I was thinking of actually running through the
file with fill-paragraph and a giant fill-column value, rather than just
deleting newlines, but I'm hesitating. These are org-mode files, and
fill-paragraph ought not to wreck them, but still...

This is a one-time bulk operation -- I'm translating a bunch of key
terms -- so the expense of the operation isn't that big a deal. The
consecutive newline question is a good one: definitely only one in a
row, but then there's potential indentation whitespace on the left...
I'll think I'll give this one a shot for now.

Thanks for the food for thought,

E




reply via email to

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