Subject: bug#52558: Option for easier typing of regexps

From: Juri Linkov <[email-masked]>
Date: Sun, 19 Dec 2021 19:01:40 +0200

> I use query replace regexp a lot, as I imagine other people do, and I
> always found that typing capturing groups and alternation is clumsy,
> because they have to be escaped, and they are the ones  needed
> most often: \(...\) \|
>
> There could be a user option to make these easier to type by providing
> a variable which controls which characters need escaping in
> interactive mode, so the user could list those characters for which
> the escaping rules are reversed when typing in the regexp replace
> prompt.

Such option already exists, and it allows using custom regexp syntax
both for isearch and query-replace:

(setq search-default-mode
      (lambda (s &optional _lax)
	(let ((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)))

The same way more choices could be added easily to this user option,
such as `pcre' or `rx'.