Providing a region to search in emacs

Is there a way to provide a scope for a search?

I want to reload isearch so that:

Cs → 1. normal if no region is selected OR 2. isearch with the region as the string used to search

example: I 'select' the words "no exit", then Cs should look for a buffer for "no exit". In a sense, this can be done with Cs Cw Cw when the cursor is at the beginning of "no". I wonder if there is a way to undo this, so first select (some like) and then use the highlight to search

+3
source share
2 answers

You can find the teams narrow-to-regionboth widenuseful C-h f narrow-to-region RETand C-h f widen RETto find out more

UPDATE

, , , ,

(add-hook 'isearch-mode-end-hook (lambda ()
                                   (when (buffer-narrowed-p)
                                     (widen))))

(defun my-isearch(&optional start end)
  (interactive "r")
  (when (region-active-p)
      (narrow-to-region start end))
    (call-interactively 'isearch-forward-regexp))

2

, ,

(defun my-isearch(&optional start end)
  (interactive "r")
  (if (region-active-p)
      (progn
        (let ((string (buffer-substring-no-properties start end)))
          (deactivate-mark)
          (isearch-resume string nil nil t string nil)))
    (call-interactively 'isearch-forward-regexp)))
+2

, Isearch + (isearch+.el). , isearchp-restrict-to-region-flag.

C-x n ( isearchp-toggle-region-restriction) .

isearchp-deactivate-region-flag , (, ).

( , ).

( Isearch Info, Info + (info+.el).


UPDATE

, , . , ; , . , .

+2

All Articles