diff --git a/lisp/isearch.el b/lisp/isearch.el index 6280afebdc..3de0493c8a 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -413,6 +413,17 @@ and doesn't remove full-buffer highlighting after a search." :group 'lazy-count :version "27.1") +(defcustom isearch-autoinsert-region nil + "If non-nil, the text in the region will be auto-inserted for searching. +This works only if the variable `transient-mark-mode' is enabled +and the region is active." + :type 'boolean + :group 'isearch + :version "27.1") + +(defvar isearch-deactivated-mark nil + "If for some reason isearch removed the mark on start.") + ;; Define isearch help map. @@ -1205,7 +1216,8 @@ used to set the value of `isearch-regexp-function'." ;; Save the original value of `minibuffer-message-timeout', and ;; set it to nil so that isearch's messages don't get timed out. isearch-original-minibuffer-message-timeout minibuffer-message-timeout - minibuffer-message-timeout nil) + minibuffer-message-timeout nil + isearch-deactivated-mark nil) (if (local-variable-p 'tool-bar-map) (setq isearch-tool-bar-old-map tool-bar-map)) @@ -1244,6 +1256,15 @@ used to set the value of `isearch-regexp-function'." ;; `isearch-push-state' to save mode-specific initial state. (Bug#4994) (isearch-push-state) + (when (and isearch-autoinsert-region ;; Check option + (use-region-p) + (not (region-noncontiguous-p)) + (= (count-lines (region-beginning) (region-end)) 1)) + (isearch-yank-string + (buffer-substring-no-properties (region-beginning) (region-end))) + (setq mark-active nil + isearch-deactivated-mark t)) + (isearch-update) (add-hook 'pre-command-hook 'isearch-pre-command-hook) @@ -1782,6 +1803,9 @@ The following additional command keys are active while editing. (isearch--set-state (car isearch-cmds))) (goto-char isearch-opoint)) (isearch-done t) ; Exit isearch.. + (when isearch-deactivated-mark + (setq isearch-deactivated-mark nil + activate-mark t) (isearch-clean-overlays) (signal 'quit nil)) ; ..and pass on quit signal.