all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to yank a regexp in isearch-mode?
@ 2018-11-11  0:46 Zhang Haijun
  2018-11-11  2:22 ` Drew Adams
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang Haijun @ 2018-11-11  0:46 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Is there a functions like isearch-yank-string but yank a regexp?

(defun my-isearch-foobar ()
  (interactive)
  (isearch-mode t)
  (isearch-yank-string “ foobar "))


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

* RE: How to yank a regexp in isearch-mode?
  2018-11-11  0:46 How to yank a regexp in isearch-mode? Zhang Haijun
@ 2018-11-11  2:22 ` Drew Adams
       [not found]   ` <C911266F-D49A-4164-ABAF-BF84D9C2C8F9@outlook.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Adams @ 2018-11-11  2:22 UTC (permalink / raw)
  To: Zhang Haijun, help-gnu-emacs

> Is there a functions like isearch-yank-string but yank a regexp?
> 
> (defun my-isearch-foobar ()
>   (interactive)
>   (isearch-mode t)
>   (isearch-yank-string " foobar "))

`isearch-yank-string' can yank a regexp string as well.

If you use Isearch+ then you have option
`isearchp-regexp-quote-yank-flag':

Non-nil means escape special chars in text yanked for a regexp isearch.
You can toggle this using `isearchp-toggle-regexp-quote-yank', bound
to `C-`' during Isearch.

IOW, if you turn off this escaping then regexp search
interprets yanked regexps normally.  If you turn it on
then a yanked regexp string has its special chars
quoted (escaped).

With this escaping turned off, you can yank text such
as `^\*.*' without it being transformed to `\^\\\*\.\*'.

Isearch+:

https://www.emacswiki.org/emacs/IsearchPlus




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

* RE: How to yank a regexp in isearch-mode?
       [not found]   ` <C911266F-D49A-4164-ABAF-BF84D9C2C8F9@outlook.com>
@ 2018-11-11 17:13     ` Drew Adams
  2018-11-12 10:43       ` Zhang Haijun
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Adams @ 2018-11-11 17:13 UTC (permalink / raw)
  To: Zhang Haijun; +Cc: help-gnu-emacs

> > `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.




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

* Re: How to yank a regexp in isearch-mode?
  2018-11-11 17:13     ` Drew Adams
@ 2018-11-12 10:43       ` Zhang Haijun
  0 siblings, 0 replies; 4+ messages in thread
From: Zhang Haijun @ 2018-11-12 10:43 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs@gnu.org



On 11/12/2018 01:13 AM, Drew Adams wrote:
>>> `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.
> 

OK. Thank you for your advice.I will try it.

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

end of thread, other threads:[~2018-11-12 10:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-11  0:46 How to yank a regexp in isearch-mode? Zhang Haijun
2018-11-11  2:22 ` Drew Adams
     [not found]   ` <C911266F-D49A-4164-ABAF-BF84D9C2C8F9@outlook.com>
2018-11-11 17:13     ` Drew Adams
2018-11-12 10:43       ` Zhang Haijun

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.