From 8922c42ad93c5c1bfeb0ed29c598941e9141227c Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Wed, 7 Apr 2021 10:39:19 +0000 Subject: [PATCH] Add options when exiting isearch * lisp/isearch.el (isearch-exit): Add three options when exiting isearch, that can be used with prefix arguments. --- lisp/isearch.el | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lisp/isearch.el b/lisp/isearch.el index a828c569aa..e4679f78a8 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1532,16 +1532,29 @@ REGEXP if non-nil says use the regexp search ring." ;; Commands active while inside of the isearch minor mode. -(defun isearch-exit () +(defun isearch-exit (&optional arg) "Exit search normally. However, if this is the first command after starting incremental search and `search-nonincremental-instead' is non-nil, do a -nonincremental search instead via `isearch-edit-string'." - (interactive) +nonincremental search instead via `isearch-edit-string'. +With a single prefix argument, move point to the other end of the +search match, unless the region is active. +With two prefix arguments, activate the region around the search +match, unless the region is already active. +With three prefix arguments, activate the region around the search +match and move point to the other end of the search match, unless +the region is already active." + (interactive "p") (if (and search-nonincremental-instead (= 0 (length isearch-string))) (let ((isearch-nonincremental t)) (isearch-edit-string)) ;; this calls isearch-done as well + (if (and (> arg 1) isearch-other-end (not (use-region-p))) + (if (> arg 4) + (progn + (push-mark isearch-other-end t 'activate) + (if (> arg 16) (exchange-point-and-mark))) + (goto-char isearch-other-end))) (isearch-done)) (isearch-clean-overlays)) -- 2.30.2