From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: I can't yank regexp for/into isearch-forward-regexp's pmpt Date: Thu, 03 Aug 2006 08:18:07 -0600 Organization: IHS Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1154614787 16745 80.91.229.2 (3 Aug 2006 14:19:47 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 3 Aug 2006 14:19:47 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 03 16:19:46 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G8e36-0007E1-VH for geh-help-gnu-emacs@m.gmane.org; Thu, 03 Aug 2006 16:19:46 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G8e36-00049Y-4v for geh-help-gnu-emacs@m.gmane.org; Thu, 03 Aug 2006 10:19:44 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G8e2r-00049J-4e for help-gnu-emacs@gnu.org; Thu, 03 Aug 2006 10:19:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G8e2q-000490-HT for help-gnu-emacs@gnu.org; Thu, 03 Aug 2006 10:19:28 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G8e2q-00048s-Bl for help-gnu-emacs@gnu.org; Thu, 03 Aug 2006 10:19:28 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1G8e6B-0006by-MM for help-gnu-emacs@gnu.org; Thu, 03 Aug 2006 10:22:56 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1G8e2R-000764-BH for help-gnu-emacs@gnu.org; Thu, 03 Aug 2006 16:19:03 +0200 Original-Received: from 207.167.42.206 ([207.167.42.206]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Aug 2006 16:19:03 +0200 Original-Received: from ihs_4664 by 207.167.42.206 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Aug 2006 16:19:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Lines: 107 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 207.167.42.206 User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) In-Reply-To: X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:36440 Archived-At: 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