all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* I can't yank regexp for/into isearch-forward-regexp's pmpt
@ 2006-08-03  3:40 David Combs
  2006-08-03 14:18 ` Kevin Rodgers
       [not found] ` <mailman.4806.1154614770.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: David Combs @ 2006-08-03  3:40 UTC (permalink / raw)


Subject: I can't yank regexp for/into isearch-forward-regexp's pmpt

[  ESC C-s runs the command isearch-forward-regexp  ]

My problem:


Doing isearch-forward-regexp against the line (note the "x"):

     "aaa  aaaa   aaaaaaaa   aaaaa   aaaaax    aa"

  , via the regexp "x", works fine -- and does so REGARDLESS
  of whether the regexp is:

    (a) typed-in the "x" by hand or
    (b) *META*-YANKED-in (ie via "M-y" -- not a plain "y").

However, when yanked-in, none of *these* (for trying to match
FIVE "a's") will match that *same* 
"aaaaaa aaa..." string (at least not for me!):

---- candidate regexps to try with C-y and/or M-y:

1: "a{5}"
2: "a\{5\}"      <<--- works fine IF prompt answered TYPED-IN BY HAND.
3: "a\\{5\\}"
4: "a\\\{5\\\}"

But *none* of the four work (for me) via yank, ie regionize
the regexp, grab it via M-w, put POINT somewhere before that
"aaaaa"-string, and then, as above, do the M-C-s 
(ie isearch-forward-regexp), and respond to its prompt
with M-y.

(Well, it does match, but not that "aaaaaa..."-line,
but rather the very one of the four trial-regexps
I had just grabbed -- as if it were a straight
*non*-regexp search!)


[ But note: the grab-regexp then yank back as prompt-response works
  JUST FINE, not with issearch-whatever, but with M-x OCCUR, 
  and for it's prompt, all it needs is just a PLAIN "C-y"! ]

Please, guys, what's up?


All I want to do is to be able to save into a file some regexps I find useful,
and then be able to use them merely by grabbing one via M-w, and then
answer the prompt by merely yanking or even meta-yanking it into or as
the prompt-response.


Please, what am I doing wrong?

Thanks!


Is there any good way to *explain* it in some tutorial-way that I (or any
user) a rule or technique for doing this with *any* regexp-prompting-for
command, eg that will work equally for *both*:

    M-x occur

    isearch-forward-regexp

    isearch-forward

    M-x query-replace-regexp

    etc, etc


 AND also, what rules for back-slashing a regexp as needed
     for *any* of the above.

Thanks again,

David

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

* Re: I can't yank regexp for/into isearch-forward-regexp's pmpt
  2006-08-03  3:40 I can't yank regexp for/into isearch-forward-regexp's pmpt David Combs
@ 2006-08-03 14:18 ` Kevin Rodgers
  2006-08-04 14:05   ` Kevin Rodgers
       [not found] ` <mailman.4806.1154614770.9609.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2006-08-03 14:18 UTC (permalink / raw)


David Combs wrote:
> Doing isearch-forward-regexp against the line (note the "x"):
> 
>      "aaa  aaaa   aaaaaaaa   aaaaa   aaaaax    aa"
> 
>   , via the regexp "x", works fine -- and does so REGARDLESS
>   of whether the regexp is:
> 
>     (a) typed-in the "x" by hand or
>     (b) *META*-YANKED-in (ie via "M-y" -- not a plain "y").
> 
> However, when yanked-in, none of *these* (for trying to match
> FIVE "a's") will match that *same* 
> "aaaaaa aaa..." string (at least not for me!):
> 
> ---- candidate regexps to try with C-y and/or M-y:
> 
> 1: "a{5}"
> 2: "a\{5\}"      <<--- works fine IF prompt answered TYPED-IN BY HAND.
> 3: "a\\{5\\}"
> 4: "a\\\{5\\\}"

Remember, the regexp itself only uses a single backslash to introduce
special characters like the left and right braces.  It is only when
the regexp needs to be represented as a Lisp string literal (delimited
by double quotes) that the backslash needs to be doubled.  That's why
regexp #2 works (without the double quotes, of course) and the others
don't when entered directly in minibuffer.

> But *none* of the four work (for me) via yank, ie regionize
> the regexp, grab it via M-w, put POINT somewhere before that
> "aaaaa"-string, and then, as above, do the M-C-s 
> (ie isearch-forward-regexp), and respond to its prompt
> with M-y.
> 
> (Well, it does match, but not that "aaaaaa..."-line,
> but rather the very one of the four trial-regexps
> I had just grabbed -- as if it were a straight
> *non*-regexp search!)
> 
> 
> [ But note: the grab-regexp then yank back as prompt-response works
>   JUST FINE, not with issearch-whatever, but with M-x OCCUR, 
>   and for it's prompt, all it needs is just a PLAIN "C-y"! ]
> 
> Please, guys, what's up?
> 
> 
> All I want to do is to be able to save into a file some regexps I find useful,
> and then be able to use them merely by grabbing one via M-w, and then
> answer the prompt by merely yanking or even meta-yanking it into or as
> the prompt-response.
> 
> 
> Please, what am I doing wrong?

You're not doing anything wrong.  But Emacs assumes that the text you
are yanking is literal text, not a regexp, even when you are doing a
regexp search.  In isearch-mode-map, M-y is bound to isearch-yank-kill,
which calls isearch-yank-string, which explicitly turns the yanked text
into a regexp (when doing a regexp search) so that you end up searching
for the regexp itself in the buffer (vs. the text that matches the
regexp).

You might be able to do what you want with a little hacking:

(defun isearch-yank-kill-as-regexp ()
   "Like `isearch-yank-kill', except during regular expression search:
Search for the text that matches the string (as a regexp) instead of
searching for the literal string itself."
   (let ((isearch-regexp nil))
     (isearch-yank-kill)))

(define-key isearch-mode-map "\M-z" 'isearch-yank-kill-as-regexp)

> Is there any good way to *explain* it in some tutorial-way that I (or any
> user) a rule or technique for doing this with *any* regexp-prompting-for
> command, eg that will work equally for *both*:
> 
>     M-x occur
> 
>     isearch-forward-regexp
> 
>     isearch-forward

isearch-forward does not prompt for a regexp, unless you toggle it
with M-r.

>     M-x query-replace-regexp
> 
>     etc, etc

M-x occur and M-x query-replace-regexp prompt for and read the regexp in
the minibuffer, like any other normal command argument.  But isearch
does not read an argument: you don't have to terminate the regexp with
RET.  Instead, isearch is implemented as a special minor mode, with its
own keymap, to implement the search incrementally -- have you noticed
that typing a single SPC in regexp isearch matches any number of
consecutive whitespace characters?

>  AND also, what rules for back-slashing a regexp as needed
>      for *any* of the above.

I think I answered that above.

-- 
Kevin

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

* Re: I can't yank regexp for/into isearch-forward-regexp's pmpt
  2006-08-03 14:18 ` Kevin Rodgers
@ 2006-08-04 14:05   ` Kevin Rodgers
  2006-08-04 16:37     ` Drew Adams
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2006-08-04 14:05 UTC (permalink / raw)


Kevin Rodgers wrote:
> You might be able to do what you want with a little hacking:
> 
> (defun isearch-yank-kill-as-regexp ()
>   "Like `isearch-yank-kill', except during regular expression search:
> Search for the text that matches the string (as a regexp) instead of
> searching for the literal string itself."
>   (let ((isearch-regexp nil))
>     (isearch-yank-kill)))
> 
> (define-key isearch-mode-map "\M-z" 'isearch-yank-kill-as-regexp)

Drew Adams points out that we need an (interactive) form between
isearch-yank-kill-as-regexp's argument list and its doc string.

He also reports:

| 2. For some reason, when using `C-M-s' followed by `M-z', the search seems
| to always start at the end of the buffer. So, it first fails, and then it
| can succeed on overwrap search (repeating `C-s'). This problem doesn't 
occur
| for simple `C-s' search. I'm not sure why this happens.

I suspect it has something to do with the global binding of M-z to
zap-to-char and/or the squirrely business with isearch-other-meta-char,
which I don't understand.  Does the problem go away if you bind a
different meta-character or a control-character to
isearch-yank-kill-as-regexp?

-- 
Kevin

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

* RE: I can't yank regexp for/into isearch-forward-regexp's pmpt
  2006-08-04 14:05   ` Kevin Rodgers
@ 2006-08-04 16:37     ` Drew Adams
  0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2006-08-04 16:37 UTC (permalink / raw)


    > (defun isearch-yank-kill-as-regexp ()
    >   "Like `isearch-yank-kill', except during regular expression search:
    > Search for the text that matches the string (as a regexp) instead of
    > searching for the literal string itself."
    >   (let ((isearch-regexp nil))
    >     (isearch-yank-kill)))
    > 
    > (define-key isearch-mode-map "\M-z" 'isearch-yank-kill-as-regexp)
    
    | For some reason, when using `C-M-s' followed by `M-z', the 
    | search seems to always start at the end of the buffer. So, it
    | first fails, and then it can succeed on overwrap search
    | (repeating `C-s'). This problem doesn't occur
    | for simple `C-s' search. I'm not sure why this happens.
    
    I suspect it has something to do with the global binding of M-z to
    zap-to-char and/or the squirrely business with isearch-other-meta-char,
    which I don't understand.  Does the problem go away if you bind a
    different meta-character or a control-character to
    isearch-yank-kill-as-regexp?
    
No, I get the same result with just `C-o', instead of `M-z':

(define-key isearch-mode-map "\C-o" 'isearch-yank-kill-as-regexp)

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

* Re: I can't yank regexp for/into isearch-forward-regexp's pmpt
       [not found] ` <mailman.4806.1154614770.9609.help-gnu-emacs@gnu.org>
@ 2006-08-13  1:10   ` David Combs
  0 siblings, 0 replies; 5+ messages in thread
From: David Combs @ 2006-08-13  1:10 UTC (permalink / raw)


In article <mailman.4806.1154614770.9609.help-gnu-emacs@gnu.org>,
Kevin Rodgers  <ihs_4664@yahoo.com> wrote:
>
>You might be able to do what you want with a little hacking:
>
>(defun isearch-yank-kill-as-regexp ()
>   "Like `isearch-yank-kill', except during regular expression search:
>Search for the text that matches the string (as a regexp) instead of
>searching for the literal string itself."
>   (let ((isearch-regexp nil))
>     (isearch-yank-kill)))
>
>(define-key isearch-mode-map "\M-z" 'isearch-yank-kill-as-regexp)
>

Thanks! -- I'll give it a try and report back (don't hold breath,
though).

Thanks also for the explanations.

David

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

end of thread, other threads:[~2006-08-13  1:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-03  3:40 I can't yank regexp for/into isearch-forward-regexp's pmpt David Combs
2006-08-03 14:18 ` Kevin Rodgers
2006-08-04 14:05   ` Kevin Rodgers
2006-08-04 16:37     ` Drew Adams
     [not found] ` <mailman.4806.1154614770.9609.help-gnu-emacs@gnu.org>
2006-08-13  1:10   ` David Combs

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.