GNU bug report logs -
#52558
Option for easier typing of regexps
Previous Next
Reported by: ndame <laszlomail <at> protonmail.com>
Date: Thu, 16 Dec 2021 17:42:01 UTC
Severity: wishlist
Tags: moreinfo
Fixed in version 29.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
Full log
Message #14 received at 52558 <at> debbugs.gnu.org (full text, mbox):
> You can probably implement what you want by overriding
> `read-regexp'. In principle I'd expect anything prompting
> for a regexp to be using this.
That's what I thought too at first, but turns out it's not
the right way, because then history contains the normalized
regexp, so if the user goes back in history then he doesn't
see the easy version, though the goal is that the user works
with the easy variant.
So read-regexp is not the right place, because the result of
that goes into history. The translation has to be done only
before the regexp is used.
In case of query-replace-regexp it can be done before
perform-replace. Here's a solution with advice:
(defun my-perform-replace (origfun &rest args)
(apply
origfun
(if (fourth args) ;; do conversion only for regexp replace
(cons (let ((s (car args))
(chars '("|" "(" ")"))
(placeholder (format "@placeholder%s@"
(int-to-string
(buffer-modified-tick)))))
(dolist (char chars)
(setq s (replace-regexp-in-string
placeholder char
(replace-regexp-in-string
char (concat "\\\\" char)
(replace-regexp-in-string
(concat "\\\\" char) placeholder
s)))))
s)
(cdr args))
args)))
(advice-add 'perform-replace :around 'my-perform-replace)
This bug report was last modified 3 years and 118 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.