Subject: bug#39512: 28.0.50; Add command isearch-yank-region

From: Juri Linkov <[email-masked]>
Date: Mon, 10 Aug 2020 02:23:59 +0300

>> Thanks for creating a new feature request that unlike these discussions
>> on emacs-devel won't fall into oblivion.
>
> This was in February, though, and the patch still hasn't been applied.  :-/
>
> I think this addition makes sense...  was there any particular reason
> it's not applied?

I really don't see a need for adding isearch-yank-region.  I think that
isearch-forward-region proposed by Ergus should be sufficient because
typing 'M-s M-.' (bound globally to isearch-forward-region) even when
isearch mode is active, will exit Isearch and restart Isearch with the
contents of the still active region added to the search string.
This will cover all cases requested here with just one new command:

  (defun isearch-forward-region ()
    "Do incremental search forward for text from the active region.
  Like ordinary incremental search except that text from the region
  is added to the search string initially if the region is active."
    (interactive)
    (isearch-forward nil 1)
    (cond
     ((use-region-p)
      (when (< (mark) (point))
        (exchange-point-and-mark))
      (isearch-yank-string
       (buffer-substring-no-properties (region-beginning) (region-end)))
      (deactivate-mark))
     (t
      (setq isearch-error "No active region")
      (isearch-push-state)
      (isearch-update))))

  (define-key search-map "\M-." 'isearch-forward-region)