From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Roche Newsgroups: gmane.emacs.help Subject: Re: bulk replacement on region, buffer, file? Date: Mon, 14 Dec 2015 21:16:42 -0700 Message-ID: <87fuz4tkgl.fsf@pobox.com> References: <87vb87t55n.fsf@pobox.com> <87twnrngho.fsf@kuiper.lan.informatimago.com> Reply-To: help-gnu-emacs@gnu.org, Tom Roche NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1450153042 30379 80.91.229.3 (15 Dec 2015 04:17:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Dec 2015 04:17:22 +0000 (UTC) To: help-gnu-emacs@gnu.org, Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 15 05:17:10 2015 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 1a8h2w-0001Kt-1L for geh-help-gnu-emacs@m.gmane.org; Tue, 15 Dec 2015 05:17:06 +0100 Original-Received: from localhost ([::1]:34959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8h2v-0002mM-5N for geh-help-gnu-emacs@m.gmane.org; Mon, 14 Dec 2015 23:17:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8h2j-0002m4-O2 for help-gnu-emacs@gnu.org; Mon, 14 Dec 2015 23:16:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8h2g-0008PO-Hi for help-gnu-emacs@gnu.org; Mon, 14 Dec 2015 23:16:53 -0500 Original-Received: from pb-smtp0.int.icgroup.com ([208.72.237.35]:63467 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8h2g-0008N6-C6 for help-gnu-emacs@gnu.org; Mon, 14 Dec 2015 23:16:50 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id 8606435B9D; Mon, 14 Dec 2015 23:16:48 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:in-reply-to:references:reply-to:date:message-id :mime-version:content-type; s=sasl; bh=mp1Gou3WH/Vinzr6eA8znrh5G t0=; b=Dz0WzSZghEKFMtbeRYK/BxpXJhIS0P47jUuMwB64S9AT399ojzKSG83DN Y6T41i3KDW2WVhBdKegSvw1RvdACQLdPv3tnu6wjsUwsrGP1235F7vsvAOFpBe2N ZgveB5ee9+w9gEss45WCkDBryP5XKu9XDug2DPLiQDFT0tG6AA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :in-reply-to:references:reply-to:date:message-id:mime-version :content-type; q=dns; s=sasl; b=a8p8V9IVQyxKhIkjcQz7iX9z6pvJu9h/ LO0Sl4RqfteHNBcgL4lDEOXUlK2Is9xKONLZVgB5RWeyo3hUkpfN+u4VC77BQDVZ HonXKcARgyiE4NQ49upZcyUUHOHRefXjST5AuCyNj74yzMMz8o4ka7nDY0OcOG37 NeHC+bxszxs= Original-Received: from pb-smtp0.int.icgroup.com (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id 7D6B235B9C; Mon, 14 Dec 2015 23:16:48 -0500 (EST) Original-Received: from tlrW510.pobox.com (unknown [173.25.5.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp0.pobox.com (Postfix) with ESMTPSA id D751335B9B; Mon, 14 Dec 2015 23:16:47 -0500 (EST) In-Reply-To: <87twnrngho.fsf@kuiper.lan.informatimago.com> User-Agent: GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5) X-Pobox-Relay-ID: A8A7EDBE-A2E2-11E5-A9C3-6BD26AB36C07-07218935!pb-smtp0.pobox.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.72.237.35 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:108408 Archived-At: summary: elisp newbie needs help fixing code @ https://bitbucket.org/tlroche/elisp_bulk_replacement details: Apologies for the delay in replying: Tom Roche[1] >>> I would appreciate pointers to code that enables "bulk replacement" of numerous string tuples ({to-replace, replace-with}) in a single call[, such that it] >>> 1. could be called on a region (if selected) or buffer (if not) >>> 2. could read from a user-editable property file of replacement tuples [...] >>> 3. would, for every {to-replace, replace-with} tuple in the file, >>> * if `to-replace` found, replace every instance with `replace-with` >>> * if `to-replace` not found, goto next tuple Pascal J. Bourguignon[2] >> wrapping all together: >> (save-excursion >> (narrow-to-region start end) >> (goto-char (point-min)) >> (replace-multiple-strings >> (with-file "~/.your-replacements.sexp" >> (goto-char (point-min)) ; in case the file is already open. >> (read (current-buffer))))) >> with-file and replace-multiple-strings are found in pjb-emacs.el[6] I've got 3 buffers open (among many others :-), with 1. one buffer on file[3] containing some {to-replace, replace-with} tuples as sexp's, open locally @ filepath=`$HOME/.emacs.d/tlr_bulk_replacements.sexp` 2. another buffer containing text to be bulk-replaced (interspersed with other text). A sample from that buffer ("suitable for testing") is @ [4] 3. yet another buffer[5] containing * the relevant bits of pjb-emacs.el[6] * the path to the sexp's file as `BULK-REPLACE-TUPLES-FILEPATH` * my attempt to transcribe the desired 'wrapping all together' function However, when I run `M-x bulk-replace-current-buffer-with-tuples-from-file` (defined in the code) in the sample-text buffer[4], I get the error *Messages* > save-excursion: Symbol's value as variable is void: start So how to make the code[5] set `start` and `end` appropriately, such that * if function is called with a region set, `start`==region start && `end`==region end * if function is called without a region set, `start`==buffer start && `end`==buffer end ? Your assistance is appreciated, Tom Roche [1]: http://lists.gnu.org/archive/html/help-gnu-emacs/2015-12/msg00077.html [2]: http://lists.gnu.org/archive/html/help-gnu-emacs/2015-12/msg00079.html [3]: https://bitbucket.org/tlroche/elisp_bulk_replacement/src/HEAD/sample_replacements.sexp [4]: https://bitbucket.org/tlroche/elisp_bulk_replacement/src/HEAD/sample_input.txt [5]: https://bitbucket.org/tlroche/elisp_bulk_replacement/src/HEAD/test_code.el [6]: https://github.com/informatimago/emacs/blob/master/pjb-emacs.el