- (let (found beg-found give-up
- (backward (eq direction 'backward))
- (onode Info-current-node)
- (ofile Info-current-file)
- (opoint (point))
- (opoint-min (point-min))
- (opoint-max (point-max))
- (ostart (window-start))
- (osubfile Info-current-subfile))
- (setq Info-search-case-fold case-fold-search)
- (save-excursion
- (save-restriction
- (widen)
- (when backward
- ;; Hide Info file header for backward search
- (narrow-to-region (save-excursion
- (goto-char (point-min))
- (search-forward "\n\^_")
- (1- (point)))
- (point-max)))
- (while (and (not give-up)
- (or (null found)
- (not (run-hook-with-args-until-failure
- 'isearch-filter-predicates beg-found found))))
- (let ((search-spaces-regexp Info-search-whitespace-regexp))
- (if (if backward
- (re-search-backward regexp bound t)
- (re-search-forward regexp bound t))
- (setq found (point) beg-found (if backward (match-end 0)
- (match-beginning 0)))
- (setq give-up t))))))
-
- (when (and isearch-mode Info-isearch-search
- (not Info-isearch-initial-node)
- (not bound)
- (or give-up (and found (not (and (> found opoint-min)
- (< found opoint-max))))))
+ (setq Info-search-case-fold case-fold-search)
+ (let* ((backward (eq direction 'backward))
+ (onode Info-current-node)
+ (ofile Info-current-file)
+ (opoint (point))
+ (opoint-min (point-min))
+ (opoint-max (point-max))
+ (ostart (window-start))
+ (osubfile Info-current-subfile)
+ (found
+ (save-excursion
+ (save-restriction
+ (widen)
+ (Info--search-loop regexp bound backward)))))
+
+ (unless (or (not isearch-mode) (not Info-isearch-search)
+ Info-isearch-initial-node
+ bound
+ (and found (> found opoint-min) (< found opoint-max)))