Function: projectile-replace--scan-file
projectile-replace--scan-file is a byte-compiled function defined in
projectile.el.
Signature
(projectile-replace--scan-file FILE REGEXP BUDGET)
Documentation
Return up to BUDGET matches of REGEXP in FILE.
A file visited in a live buffer is scanned from that buffer's current text (so the preview matches what will be edited, even when the buffer has unsaved changes); otherwise it is read from disk into a temp buffer. Binary-looking and unreadable files are skipped.
Source Code
;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defun projectile-replace--scan-file (file regexp budget)
"Return up to BUDGET matches of REGEXP in FILE.
A file visited in a live buffer is scanned from that buffer's current
text (so the preview matches what will be edited, even when the buffer
has unsaved changes); otherwise it is read from disk into a temp buffer.
Binary-looking and unreadable files are skipped."
;; Capture the intended `case-fold-search' (bound dynamically around the
;; gather) before entering a live buffer, then re-establish it there: some
;; major modes make `case-fold-search' buffer-local, which would otherwise
;; shadow the dynamic binding and make the case toggle a no-op for that file.
(let ((buffer (get-file-buffer file))
(fold case-fold-search))
(if buffer
(with-current-buffer buffer
(let ((case-fold-search fold))
(projectile-replace--scan-region file buffer regexp budget)))
(condition-case nil
(with-temp-buffer
;; Read what is on disk. `insert-file-contents' dispatches
;; through `file-name-handler-alist', so jka-compr decompresses
;; every archive in the candidate set and EPA decrypts every
;; `.gpg' - work thrown away a line later when the result is
;; classified as binary, and which on an encrypted file can stop
;; the whole search on a passphrase prompt. Only those two
;; handlers are inhibited, so a remote project still reads
;; through TRAMP.
(let ((inhibit-file-name-handlers
(append '(jka-compr-handler epa-file-handler)
inhibit-file-name-handlers))
(inhibit-file-name-operation 'insert-file-contents))
(insert-file-contents file))
(unless (projectile-replace--binary-p)
(let ((case-fold-search fold))
(projectile-replace--scan-region file nil regexp budget))))
(error nil)))))