diff --git a/lisp/isearch.el b/lisp/isearch.el index 943e24aa56..c924b73607 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -178,10 +178,13 @@ isearch-mode-hook (defvar isearch-update-post-hook nil "Function(s) to call after isearch has found matches in the buffer.") -(defvar isearch-mode-end-hook nil +(defcustom isearch-mode-end-hook nil "Function(s) to call after terminating an incremental search. When these functions are called, `isearch-mode-end-hook-quit' -is non-nil if the user quits the search.") +is non-nil if the user quits the search." + :type 'hook + :options '(isearch-exit-other-end) + :version "28.1") (defvar isearch-mode-end-hook-quit nil "Non-nil while running `isearch-mode-end-hook' if the user quits the search.") @@ -1417,6 +1420,15 @@ isearch-done (and (not edit) isearch-recursive-edit (exit-recursive-edit))) +(defun isearch-exit-other-end () + "Move point to the beginning of the found search string. +Can be used in `isearch-mode-end-hook' or interactively to exit isearch." + (interactive) + (when isearch-mode + (isearch-exit)) + (when isearch-other-end + (goto-char isearch-other-end))) + (defvar isearch-mouse-commands '(mouse-minor-mode-menu) "List of mouse commands that are allowed during Isearch.")