From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-15?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: search across linebreaks Date: Sun, 17 Feb 2013 18:05:32 +0100 Message-ID: <51210DDC.5070505@easy-emacs.de> References: <878v6nbd1i.fsf@ericabrahamsen.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1361121055 2684 80.91.229.3 (17 Feb 2013 17:10:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 17 Feb 2013 17:10:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 17 18:11:18 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U77lg-0004UT-Fy for geh-help-gnu-emacs@m.gmane.org; Sun, 17 Feb 2013 18:11:12 +0100 Original-Received: from localhost ([::1]:39087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U77lL-0007qA-EA for geh-help-gnu-emacs@m.gmane.org; Sun, 17 Feb 2013 12:10:51 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:35953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U77lC-0007pZ-Eg for help-gnu-emacs@gnu.org; Sun, 17 Feb 2013 12:10:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U77kv-0001ZF-GW for help-gnu-emacs@gnu.org; Sun, 17 Feb 2013 12:10:26 -0500 Original-Received: from moutng.kundenserver.de ([212.227.17.9]:55722) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U77kv-0001Z4-5j for help-gnu-emacs@gnu.org; Sun, 17 Feb 2013 12:10:25 -0500 Original-Received: from [192.168.178.21] (brln-4dbc54fd.pool.mediaWays.net [77.188.84.253]) by mrelayeu.kundenserver.de (node=mreu4) with ESMTP (Nemesis) id 0MD155-1TydMk3a2l-009ga2; Sun, 17 Feb 2013 18:05:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 In-Reply-To: <878v6nbd1i.fsf@ericabrahamsen.net> X-Provags-ID: V02:K0:uGAAxKKiX83mf2aHVZg3cPe25A2XYGxxf7J2Dtq8m5I 2OCjKP8usbzX1o6e7T9s9ktR+Va7E7TrT+04zl5vYkahRrOLVx 7mP9dMvYsF3Is3E5yz9gyl0GndoZ+heR4wPKaghczRKR5gBR7Y 6q8fpDKDHDXy7jTqZDYzKDxXpcRzuWNOmRC8MbebUihnSeIwfK XOejAfij9dz7AYC3A5UfHO7xRJXiC18kQHuZHo4QBhqDmcnGOl i1ap1RCziqA167o2v2oMdmIobfZ5cQmQ1s7q5FyvDKaVTSfmL+ mioSV7SyikNqn0bfK04FBqmESqQyLrnvdKLVkdLMUgFs9fUIHl 8rdmek7QBeGxCthTDC4THLas9fQYsx3rasRm0J2tV X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.17.9 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89133 Archived-At: Am 17.02.2013 08:43, schrieb Eric Abrahamsen: > 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? > > Thanks, > Eric > > > IMO Emacs Lisp is much better suited for that kind of tasks than sed, awk, Perl etc. That's because you can cascade matching conditions nearly to infinite, while jumping around in buffer, that way break complex regexps up, avoid them. Write a function which first takes your files list than (while files-list (while (re-search-forward 1nd-condition) (while (re-search-forward 2nd-condition) ... do-what-its-needed)))