unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: ndame <laszlomail@protonmail.com>
Cc: 52558@debbugs.gnu.org
Subject: bug#52558: Option for easier typing of regexps
Date: Sun, 19 Dec 2021 20:38:10 +0200	[thread overview]
Message-ID: <8635moe8z1.fsf@mail.linkov.net> (raw)
In-Reply-To: <dw-TfQUmHalrx6cxKhyGy1pYG_UADEvcnatJWBdbBNxJ4o_ManKkKG-SZWVpnBofTyZvStMTrMNWk4OYl239l86EobdV9vi-CPg631NYgUM=@protonmail.com> (ndame's message of "Sun, 19 Dec 2021 17:39:35 +0000")

>> Such option already exists, and it allows using custom regexp syntax
>> both for isearch and query-replace:
>
> Interesting, though its help mentions only isearch, so if I start
> M-x query-replace-regexp directly, it doesn't seem affected.

If you want to use M-x query-replace directly,
then simpler would be add replace-regexp-function
that you can use with:

(setq replace-regexp-function
      (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)))

diff --git a/lisp/replace.el b/lisp/replace.el
index 0e81b15a09..84c2d523d7 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2621,6 +2621,8 @@ replace-re-search-function
 It is called with three arguments, as if it were
 `re-search-forward'.")
 
+(defvar replace-regexp-function nil)
+
 (defun replace-search (search-string limit regexp-flag delimited-flag
 		       case-fold &optional backward)
   "Search for the next occurrence of SEARCH-STRING to replace."
@@ -2633,7 +2635,8 @@ replace-search
   ;; outside of this function because then another I-search
   ;; used after `recursive-edit' might override them.
   (let* ((isearch-regexp regexp-flag)
-	 (isearch-regexp-function (or delimited-flag
+	 (isearch-regexp-function (or replace-regexp-function
+                                      delimited-flag
 				      (and replace-char-fold
 					   (not regexp-flag)
 					   #'char-fold-to-regexp)))
-- 






  parent reply	other threads:[~2021-12-19 18:38 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 17:41 bug#52558: Option for easier typing of regexps ndame via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-17 10:07 ` Phil Sainty
2021-12-18 16:47   ` ndame via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-18  4:41 ` Richard Stallman
2021-12-19 11:56 ` Lars Ingebrigtsen
2021-12-19 13:03   ` Phil Sainty
2021-12-19 14:08     ` ndame via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-19 16:11       ` Phil Sainty
2021-12-19 15:10   ` Michael Heerdegen
2021-12-20  4:43   ` Richard Stallman
2021-12-20 19:46   ` Jim Porter
2021-12-22  4:16     ` Richard Stallman
2021-12-19 17:01 ` Juri Linkov
2021-12-19 17:39   ` ndame via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-19 17:52     ` Juri Linkov
2021-12-19 17:57       ` Juri Linkov
2021-12-19 18:38     ` Juri Linkov [this message]
2021-12-19 18:48       ` Juri Linkov
2021-12-28 19:15         ` Juri Linkov
2021-12-28 20:21           ` Eli Zaretskii
2021-12-28 20:25             ` Juri Linkov
2021-12-28 20:35               ` Eli Zaretskii
2021-12-28 20:51                 ` Juri Linkov
2021-12-29 12:32                   ` Eli Zaretskii
2021-12-29 17:17                     ` Juri Linkov
2021-12-29 18:25                       ` Eli Zaretskii
2022-01-22 14:23         ` Lars Ingebrigtsen
2022-01-22 19:01           ` Juri Linkov
2022-01-23 12:36             ` Lars Ingebrigtsen
2022-01-23 18:09               ` Juri Linkov
2022-01-23 18:29                 ` Lars Ingebrigtsen
2022-01-24 18:46                   ` Juri Linkov

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8635moe8z1.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=52558@debbugs.gnu.org \
    --cc=laszlomail@protonmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).