From: rvclayton@acm.org (R. Clayton)
To: help-gnu-emacs@gnu.org
Subject: Custom query-replace.
Date: Sun, 12 Jul 2015 16:47:56 -0400 [thread overview]
Message-ID: <87y4ilnlvn.fsf@BanjaLuka.rclayton.net> (raw)
I'm trying to write a query-replace command to deal with hyphens in text. For
each match, I want to perform one of three changes:
delete hyphen; go from "for- got" to "forgot"
unspace hyphen; go from "red- headed" to "red-headed"
space hyphen; go from "stop- it" to "stop - it"
as well as the usual query-replace options (quit, skip, and so on). For
example, typing 'D' at the query-replace prompt would delete the hyphen.
I had a hazy idea I could do this by flogging some keymap. However, once I got
this far
(defun rehyphenate ()
(interactive)
(let (f r)
(fset 'r (lambda (data count)
(concat (match-string 1) "-" (match-string 2))))
(fset 'f (lambda ()
(perform-replace
"\\([a-z]\\)- +\\([a-z]\\)" ; from-string
(cons 'r "") ; replacements
t ; query-flag
t ; regexp-flag
nil ; delimited-flag
nil ; repeat-count
nil ; keymap
(point-min) ; start
(point-max) ; end
)))
(while (f)
)))
I realized my hazy idea was hazier than I though. It seems to me I have two
paths I can follow:
Continue to flog the keymap by including commands in the keymap that in turn
flog the replacement text, or otherwise communicate the change choice to the
replacement function.
Move the query from the match to the replacement function, which would forego
standard query-replace behavior, such as quitting and skipping, which is an
ok trade-off.
Both of these paths seem unattractive to me. What alternatives are there
available for me to do what I want? Is there some similarly-behaving code
around I can steal from?
next reply other threads:[~2015-07-12 20:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-12 20:47 R. Clayton [this message]
2015-07-13 7:19 ` Custom query-replace Yuri Khan
2015-07-13 10:55 ` Marcin Borkowski
2015-07-14 17:32 ` R. Clayton
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=87y4ilnlvn.fsf@BanjaLuka.rclayton.net \
--to=rvclayton@acm.org \
--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.