Function: projectile-replace--scan-step
projectile-replace--scan-step is a byte-compiled function defined in
projectile.el.
Signature
(projectile-replace--scan-step BUFFER REMAINING REGEXP BUDGET ON-DONE GENERATION)
Documentation
Scan one chunk of REMAINING candidates for REGEXP into BUFFER.
BUDGET is the remaining match allowance. GENERATION is the scan token
this chunk belongs to; the step no-ops when it no longer matches BUFFER's
current projectile-replace--scan-generation (i.e. the scan was
superseded or canceled). Delivers this chunk's matches into BUFFER and
re-renders; while candidates and budget remain it schedules itself for
the next chunk via a zero-delay timer, otherwise it finishes: clears the
scanning state, does a final render and calls ON-DONE. Guarded against a
killed BUFFER (leaving no work behind) and against \C-g during a chunk
(which cancels the scan cleanly).
Source Code
;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defun projectile-replace--scan-step (buffer remaining regexp budget on-done generation)
"Scan one chunk of REMAINING candidates for REGEXP into BUFFER.
BUDGET is the remaining match allowance. GENERATION is the scan token
this chunk belongs to; the step no-ops when it no longer matches BUFFER's
current `projectile-replace--scan-generation' (i.e. the scan was
superseded or canceled). Delivers this chunk's matches into BUFFER and
re-renders; while candidates and budget remain it schedules itself for
the next chunk via a zero-delay timer, otherwise it finishes: clears the
scanning state, does a final render and calls ON-DONE. Guarded against a
killed BUFFER (leaving no work behind) and against \\`C-g' during a chunk
\(which cancels the scan cleanly)."
(when (and (buffer-live-p buffer)
(= generation
(buffer-local-value 'projectile-replace--scan-generation buffer)))
(condition-case nil
(let ((fold (buffer-local-value 'projectile-replace--case-fold buffer))
(count 0)
(new nil)
(truncated nil)
(stop nil))
;; scan up to a chunk of files, mirroring the sync `--gather' loop:
;; a file is scanned while budget remains; the first file reached
;; with the budget exhausted marks the list truncated and stops.
(while (and remaining (not stop)
(< count projectile-search-scan-chunk-size))
(if (> budget 0)
(let ((ms (let ((case-fold-search fold))
(projectile-replace--scan-file
(car remaining) regexp budget))))
(setq new (append new ms)
budget (- budget (length ms))
remaining (cdr remaining)))
(setq truncated t stop t))
(cl-incf count))
(with-current-buffer buffer
(when new
(setq projectile-replace--matches
(append projectile-replace--matches new)))
(when truncated
(setq projectile-replace--truncated t)))
(if (and remaining (not stop))
;; more to do: show progress and yield to redisplay
(with-current-buffer buffer
;; schedule the next chunk BEFORE rendering, so a render error
;; can't strand the scan with the flag set and no pending timer
(setq projectile-replace--scan-timer
(run-with-timer 0 nil
#'projectile-replace--scan-step
buffer remaining regexp budget on-done generation))
(projectile-replace--render-progress))
;; finished (or budget-truncated): settle and hand off
(with-current-buffer buffer
(setq projectile-replace--scanning nil
projectile-replace--scan-timer nil)
(projectile-replace--render-preserve)
(when on-done (funcall on-done buffer)))))
(quit
(when (buffer-live-p buffer)
(with-current-buffer buffer
(projectile-replace--cancel-scan)
(funcall projectile-replace--render-function)))))))