help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: How to yank a regexp in isearch-mode?


From: Drew Adams
Subject: RE: How to yank a regexp in isearch-mode?
Date: Sun, 11 Nov 2018 09:13:59 -0800 (PST)

> > `isearch-yank-string' can yank a regexp string as well.
> 
> But it escape the string if isearch-regexp is not nil.

Yes.  That's why Isearch+ adds `isearchp-regexp-quote-yank-flag'
(and a key to toggle that during Isearch): to give you a choice
(control).

> > If you use Isearch+ then you have option
> > `isearchp-regexp-quote-yank-flag':...
> >
> > With this escaping turned off, you can yank text such
> > as `^\*.*' without it being transformed to `\^\\\*\.\*'.
> >
> > Isearch+:
> >
> > https://www.emacswiki.org/emacs/IsearchPlus
> 
> I see it. It is a big package. It is too big for my use case. I just
> want to yank a regexp.

It's not very big, if you remove the Commentary.  But
yes, it's purpose is not just to let you yank  regexp.

If you don't want to use Isearch+ then just advise or
redefine `isearch-yank-string', like Isearch+ does.
It's trivial to do.  E.g., change this:

(if isearch-regexp (setq string (regexp-quote string)))

to this:

(when (and isearch-regexp  your-variable)
  (setq string  (regexp-quote string)))

Or define a separate command that yanks without doing
`regexp-quote' - same defun but without that line
(if regexp-quote...).  And bind that command to a different
key.

IOW, either use a variable with two values (and maybe a
toggle command) or two different keys.  Pretty simple.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]