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: bulk replacement on region, buffer, file? Date: Wed, 09 Dec 2015 19:21:24 -0700 Message-ID: <87vb87t55n.fsf@pobox.com> Reply-To: help-gnu-emacs@gnu.org, Tom Roche NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1449714116 20171 80.91.229.3 (10 Dec 2015 02:21:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Dec 2015 02:21:56 +0000 (UTC) To: help-gnu-emacs@gnu.org, Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 10 03:21:47 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 1a6qra-0006HQ-N6 for geh-help-gnu-emacs@m.gmane.org; Thu, 10 Dec 2015 03:21:46 +0100 Original-Received: from localhost ([::1]:38955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6qrZ-0000xf-QP for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Dec 2015 21:21:45 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6qrP-0000xW-5p for help-gnu-emacs@gnu.org; Wed, 09 Dec 2015 21:21:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a6qrL-0003q4-Ry for help-gnu-emacs@gnu.org; Wed, 09 Dec 2015 21:21:35 -0500 Original-Received: from pb-smtp0.int.icgroup.com ([208.72.237.35]:63251 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6qrL-0003q0-OR for help-gnu-emacs@gnu.org; Wed, 09 Dec 2015 21:21:31 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id D66C430837; Wed, 9 Dec 2015 21:21:30 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:reply-to:date:message-id:mime-version:content-type :content-transfer-encoding; s=sasl; bh=F03US0i7h1APTIe0wYfcyzpuh LI=; b=XJJrlHXqBQaEmwU07qcA7FWc3P5BDADX58C2kGHHB7pWm8NdpZw3JjZJM CA9SRsTY9/rd6QXLLSWjn7FNBUfitJsYCDzT493qpThhZLqlT5S02HAKebcf0abk m2pZ4ZeRQAe1p42a1TuUHnzNmerdjcbF15kKZywaB0dihCpXms= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :reply-to:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=sasl; b=dZaq8Ybie4vLqEMb9rI 9wHRnbqMXu/18hq9CI9J++9kag6gEQn5KAq9uZs/pgI+mLASKVi2onxe7eHbL2+u QN4rAdVbzn1i2YqbteSRJsBabGqF1HvNNozJQGim+wDnIRgc3+ZjZ59/r3JzMF5h 6iQ0/nqHjiG46mLBGoFtVYOo= Original-Received: from pb-smtp0.int.icgroup.com (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id CE88230836; Wed, 9 Dec 2015 21:21:30 -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 2D99930835; Wed, 9 Dec 2015 21:21:30 -0500 (EST) User-Agent: GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5) X-Pobox-Relay-ID: B952DEAA-9EE4-11E5-A97F-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:108348 Archived-At: I would appreciate pointers to code that enables "bulk replacement" of nume= rous string tuples ({to-replace, replace-with}) in a single call. What I me= an, why I ask: I frequently scrape blocks of text from PDFs into Emacs text buffers. After= I do so, I usually want to replace lots of strings in the buffer. E.g. (us= ing '|' to delimit the strings), |CO 2| -> |CO2| |- | -> || |=E2=80=9C| -> |"| |=E2=80=9D| -> |"| |[weird unicodes used for bulleting]| -> |*| which I do manually by calling `M-x replace-string` or similar interactive = or regexp function. I'd prefer instead to call something that 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 (lik= e those above), similar to `abbrev_defs` but without some constraints of th= e latter that annoy in this usecase. E.g. (unless I'm missing something), I= cannot use `abbrev` to replace the space-delimited 'CO 2' with 'CO2'. 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 Is there elisp to do this? Alternatively, pointers to non-elisp (that I cou= ld invoke on a buffer's file and then `revert-buffer`) would also be apprec= iated. (And, yes, I know this sounds easy to write, but I have other priori= ties at present and no wish to reinvent any well-working wheels.) Apologies if this is a FAQ, but a brief websearch found nothing that looked= useful. TIA, Tom Roche