From: Tom Roche <Tom_Roche@pobox.com>
To: help-gnu-emacs@gnu.org,
Subject: Re: bulk replacement on region, buffer, file?
Date: Mon, 14 Dec 2015 21:16:42 -0700 [thread overview]
Message-ID: <87fuz4tkgl.fsf@pobox.com> (raw)
In-Reply-To: <87twnrngho.fsf@kuiper.lan.informatimago.com>
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 <Tom_Roche@pobox.com>
[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
next prev parent reply other threads:[~2015-12-15 4:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1767.1449714096.31583.help-gnu-emacs@gnu.org>
2015-12-10 3:13 ` bulk replacement on region, buffer, file? Pascal J. Bourguignon
2015-12-15 4:16 ` Tom Roche [this message]
2015-12-10 2:21 Tom Roche
2015-12-10 3:21 ` Emanuel Berg
2015-12-10 16:40 ` Bob Proulx
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=87fuz4tkgl.fsf@pobox.com \
--to=tom_roche@pobox.com \
--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.