Function: isearch-repeat

isearch-repeat is a byte-compiled function defined in isearch.el.gz.

Signature

(isearch-repeat DIRECTION &optional COUNT)

Source Code

;; Defined in /usr/src/emacs/lisp/isearch.el.gz
(defun isearch-repeat (direction &optional count)
  ;; Utility for isearch-repeat-forward and isearch-repeat-backward.
  (if (eq isearch-forward (eq direction 'forward))
      ;; C-s in forward or C-r in reverse.
      (if (equal isearch-string "")
	  ;; If search string is empty, use last one.
	  (if (null (if isearch-regexp regexp-search-ring search-ring))
	      (setq isearch-error "No previous search string")
	    (setq isearch-string
		  (car (if isearch-regexp regexp-search-ring search-ring))
		  isearch-message
		  (mapconcat 'isearch-text-char-description
			     isearch-string "")
		  isearch-case-fold-search isearch-last-case-fold-search)
	    ;; After taking the last element, adjust ring to previous one.
	    (isearch-ring-adjust1 nil))
	;; If already have what to search for, repeat it.
	(unless (or isearch-success (null isearch-wrap-pause))
	  ;; Set isearch-wrapped before calling isearch-wrap-function
	  (setq isearch-wrapped t)
	  (if isearch-wrap-function
	      (funcall isearch-wrap-function)
	    (goto-char (if isearch-forward (point-min) (point-max))))))
    ;; C-s in reverse or C-r in forward, change direction.
    (if (and isearch-other-end isearch-repeat-on-direction-change)
        (goto-char isearch-other-end))
    (setq isearch-forward (not isearch-forward)
	  isearch-success t))

  (setq isearch-barrier (point)) ; For subsequent \| if regexp.

  (if (equal isearch-string "")
      (setq isearch-success t)
    ;; For the case when count > 1, don't keep intermediate states
    ;; added to isearch-cmds by isearch-push-state in this loop.
    (let ((isearch-cmds isearch-cmds)
          (was-success isearch-success))
      (while (<= 0 (setq count (1- (or count 1))))
	(if (and isearch-success
		 (equal (point) isearch-other-end)
		 (not isearch-just-started))
	    ;; If repeating a search that found
	    ;; an empty string, ensure we advance.
	    (if (if isearch-forward (eobp) (bobp))
		;; If there's nowhere to advance to, fail (and wrap next time).
		(progn
		  (setq isearch-success nil)
		  (ding))
	      (forward-char (if isearch-forward 1 -1))
	      (isearch-search))
	  (isearch-search))
	  (when (> count 0)
	    ;; Update isearch-cmds, so if isearch-search fails later,
	    ;; it can restore old successful state from isearch-cmds.
	    (isearch-push-state))
          (cond
           ;; Wrap immediately and repeat the search again
           ((memq isearch-wrap-pause '(no no-ding))
            (if isearch-success
                (setq was-success isearch-success)
              ;; If failed this time after succeeding last time
              (when was-success
                (setq was-success nil)
                (setq count (1+ count)) ;; Increment to force repeat
                (setq isearch-wrapped t)
                (if isearch-wrap-function
                    (funcall isearch-wrap-function)
                  (goto-char (if isearch-forward (point-min) (point-max)))))))
           ;; Stop looping on failure
           (t (when (or (not isearch-success) isearch-error)
                (setq count 0)))))))

  (isearch-push-state)
  (isearch-update))