From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: bulk replacement on region, buffer, file?
Date: Thu, 10 Dec 2015 04:21:43 +0100 [thread overview]
Message-ID: <87vb873s54.fsf@debian.uxu> (raw)
In-Reply-To: 87vb87t55n.fsf@pobox.com
Tom Roche <Tom_Roche@pobox.com> writes:
> I would appreciate pointers to code that enables
> "bulk replacement" of numerous string tuples
> ({to-replace, replace-with}) in a single call.
> What I mean, 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. (using
> '|' to delimit the strings),
>
> |CO 2| -> |CO2|
> |- | -> ||
> |“| -> |"|
> |”| -> |"|
> |[weird unicodes used for bulleting]| -> |*|
I hear you - everything is fair in the struggle against
those goofy chars! Down with unicode!
(Except: putting them as a quote when they aren't!)
Aaanyway...
Probably best way is to use set functions - another
good way tho is recursion. And I'm not just saying
that...
(defun replace-strings (tuple-list)
(when tuple-list
(let*((tuple (car tuple-list))
(rest (cdr tuple-list))
(replace-match (car tuple))
(replace-string (cadr tuple)) )
(goto-char (point-min))
(while (re-search-forward replace-match (point-max) t) ; NOERROR
(replace-match replace-string) )
(replace-strings rest) )))
;; Eval this to fix the below typos:
(replace-strings '(("Robb Hall" "Rob Hall")
("Scott Ficsher" "Scott Fischer") ))
;; Robb Hall
;;
;; Scott Ficsher
;;
;; Robb Hall
;;
;; Scott Ficsher
--
underground experts united
http://user.it.uu.se/~embe8573
next prev parent reply other threads:[~2015-12-10 3:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-10 2:21 bulk replacement on region, buffer, file? Tom Roche
2015-12-10 3:21 ` Emanuel Berg [this message]
2015-12-10 16:40 ` Bob Proulx
[not found] <mailman.1767.1449714096.31583.help-gnu-emacs@gnu.org>
2015-12-10 3:13 ` Pascal J. Bourguignon
2015-12-15 4:16 ` Tom Roche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vb873s54.fsf@debian.uxu \
--to=embe8573@student.uu.se \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.