help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: automatic search/search and replace for a marked string


From: A.Politz
Subject: Re: automatic search/search and replace for a marked string
Date: Sun, 23 Aug 2009 15:05:24 -0700 (PDT)
User-agent: G2/1.0

On Aug 22, 1:07 pm, lichtkind <lichtki...@web.de> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]