From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "A.Politz" Newsgroups: gmane.emacs.help Subject: Re: automatic search/search and replace for a marked string Date: Sun, 23 Aug 2009 15:05:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <61780ed3-2c6b-4233-8f05-3ec082689bb8@s15g2000yqs.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1251067255 22653 80.91.229.12 (23 Aug 2009 22:40:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 23 Aug 2009 22:40:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 24 00:40:48 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MfLjz-0003Cu-Ls for geh-help-gnu-emacs@m.gmane.org; Mon, 24 Aug 2009 00:40:47 +0200 Original-Received: from localhost ([127.0.0.1]:39310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfLjy-0005Qq-ND for geh-help-gnu-emacs@m.gmane.org; Sun, 23 Aug 2009 18:40:46 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2.glorb.com!postnews.google.com!24g2000yqm.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 52 Original-NNTP-Posting-Host: 84.59.206.131 Original-X-Trace: posting.google.com 1251065124 4305 127.0.0.1 (23 Aug 2009 22:05:24 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sun, 23 Aug 2009 22:05:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 24g2000yqm.googlegroups.com; posting-host=84.59.206.131; posting-account=Cb0eCQoAAADOp8Qt5mU0s83Gs6qJzY70 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009061208 Iceweasel/3.0.12 (Debian-3.0.12-1), gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:172309 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:67460 Archived-At: On Aug 22, 1:07=A0pm, lichtkind wrote: > Hello, > > I have marked a string. Now I want to search for this string in the > whole text. I know that I can search with C-R or C-S. and type in the > searchstring. I'm looking for a way, that the marked string is > automatic the searchstring. This should also work for the other > search/ search and replace types. > > Regards > lichtkind As for isearch. (defun isearch-yank-region () (interactive) (when (and transient-mark-mode mark-active) (deactivate-mark) (isearch-yank-string (buffer-substring-no-properties (region-beginning) (region-end))))) >From here you have 3 choices. 1. Make the region the default search string (add-hook 'isearch-mode-hook #'(lambda nil (isearch-update) (isearch-yank-region))) 2. Define a key to yank the region as a search string (define-key isearch-mode-map (kbd "M-w") 'isearch-yank-region) 3. Define new special purpose commands. (defun isearch-region-forward (regexp-flag) (interactive "P") (let ((isearch-mode-hook isearch-mode-hook)) (add-hook 'isearch-mode-hook 'isearch-yank-region) (isearch-forward regexp-flag))) As for the other commands, like query-replace etc. They already use the region as a way to determine the part of the buffer to operate on... -ap