diff --git a/lisp/isearch.el b/lisp/isearch.el index 035ff69327..3e6e696a74 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1547,7 +1547,7 @@ isearch-abort (isearch-pop-state)) (isearch-update))) -(defun isearch-repeat (direction) +(defun isearch-repeat (direction &optional count) ;; Utility for isearch-repeat-forward and -backward. (if (eq isearch-forward (eq direction 'forward)) ;; C-s in forward or C-r in reverse. @@ -1590,21 +1590,29 @@ isearch-repeat (setq isearch-success nil) (ding)) (forward-char (if isearch-forward 1 -1)) - (isearch-search)) - (isearch-search))) + (isearch-search count)) + (isearch-search count))) (isearch-push-state) (isearch-update)) -(defun isearch-repeat-forward () - "Repeat incremental search forwards." - (interactive) - (isearch-repeat 'forward)) - -(defun isearch-repeat-backward () - "Repeat incremental search backwards." - (interactive) - (isearch-repeat 'backward)) +(defun isearch-repeat-forward (&optional arg) + "Repeat incremental search forwards. +With a prefix argument, repeat a search ARG times." + (interactive "P") + (let ((count (and arg (abs (prefix-numeric-value arg))))) + ;; Take into account one search iteration to reverse direction. + (when (and count (not isearch-forward)) (setq count (1+ count))) + (isearch-repeat 'forward count))) + +(defun isearch-repeat-backward (&optional arg) + "Repeat incremental search backwards. +With a prefix argument, repeat a search ARG times." + (interactive "P") + (let ((count (and arg (abs (prefix-numeric-value arg))))) + ;; Take into account one search iteration to reverse direction. + (when (and count isearch-forward) (setq count (1+ count))) + (isearch-repeat 'backward count))) ;;; Toggles for `isearch-regexp-function' and `search-default-mode'. @@ -2910,7 +2918,7 @@ isearch-search-fun-default (t (regexp-quote string))) bound noerror count)))) -(defun isearch-search-string (string bound noerror) +(defun isearch-search-string (string bound noerror &optional count) "Search for the first occurrence of STRING or its translation. STRING's characters are translated using `translation-table-for-input' if that is non-nil. @@ -2921,7 +2929,10 @@ isearch-search-string Optional third argument, if t, means if fail just return nil (no error). If not nil and not t, move to limit of search and return nil." (let* ((func (isearch-search-fun)) - (pos1 (save-excursion (funcall func string bound noerror))) + (pos1 (save-excursion (if count + (funcall func string bound noerror count) + ;; Backward-compatibility for functions that don't support count arg + (funcall func string bound noerror)))) pos2) (when (and ;; Avoid "obsolete" warnings for translation-table-for-input. @@ -2960,7 +2971,7 @@ isearch-search-string (goto-char pos1) pos1))) -(defun isearch-search () +(defun isearch-search (&optional count) ;; Do the search with the current search string. (if (and (eq isearch-case-fold-search t) search-upper-case) (setq isearch-case-fold-search @@ -2974,7 +2985,7 @@ isearch-search (setq isearch-error nil) (while retry (setq isearch-success - (isearch-search-string isearch-string nil t)) + (isearch-search-string isearch-string nil t count)) ;; Clear RETRY unless the search predicate says ;; to skip this search hit. (if (or (not isearch-success)