all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Custom query-replace.
@ 2015-07-12 20:47 R. Clayton
  2015-07-13  7:19 ` Yuri Khan
  0 siblings, 1 reply; 4+ messages in thread
From: R. Clayton @ 2015-07-12 20:47 UTC (permalink / raw)
  To: help-gnu-emacs

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?




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-07-14 17:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-12 20:47 Custom query-replace R. Clayton
2015-07-13  7:19 ` Yuri Khan
2015-07-13 10:55   ` Marcin Borkowski
2015-07-14 17:32   ` R. Clayton

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.