all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: I can't yank regexp for/into isearch-forward-regexp's pmpt
Date: Thu, 03 Aug 2006 08:18:07 -0600	[thread overview]
Message-ID: <eat0jq$g3a$1@sea.gmane.org> (raw)
In-Reply-To: <earr6m$1pk$1@panix2.panix.com>

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

  reply	other threads:[~2006-08-03 14:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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

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

  git send-email \
    --in-reply-to='eat0jq$g3a$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.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 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.