Function: consult--find-file-temporarily-1
consult--find-file-temporarily-1 is a byte-compiled function defined
in consult.el.
Signature
(consult--find-file-temporarily-1 NAME)
Documentation
Open file NAME, helper function for consult--find-file-temporarily.
Source Code
;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(defun consult--find-file-temporarily-1 (name)
"Open file NAME, helper function for `consult--find-file-temporarily'."
;; file-attributes may throw permission denied error
(when-let* ((attrs (ignore-errors (file-attributes name)))
(size (file-attribute-size attrs)))
(let* ((partial (>= size consult-preview-partial-size))
(buffer (if partial
(generate-new-buffer (format "consult-partial-preview-%s" name))
(find-file-noselect name 'nowarn)))
(success nil))
(unwind-protect
(with-current-buffer buffer
(if (not partial)
(when (or (eq major-mode 'hexl-mode)
(and (eq major-mode 'fundamental-mode)
(save-excursion (search-forward "\0" nil 'noerror))))
(error "No preview of binary file"))
(with-silent-modifications
(setq buffer-read-only t)
(insert-file-contents name nil 0 consult-preview-partial-chunk)
(goto-char (point-max))
(insert "\nFile truncated. End of partial preview.\n")
(goto-char (point-min)))
(when (save-excursion (search-forward "\0" nil 'noerror))
(error "No partial preview of binary file"))
;; Auto detect major mode and hope for the best, given that the
;; file is only previewed partially. If an error is thrown the
;; buffer will be killed and preview is aborted.
(set-auto-mode)
(font-lock-mode 1))
(when (bound-and-true-p so-long-detected-p)
(error "No preview of file with long lines"))
;; Run delayed hooks listed in `consult-preview-allowed-hooks'.
(dolist (hook (reverse (cons 'after-change-major-mode-hook delayed-mode-hooks)))
(run-hook-wrapped hook (lambda (fun)
(when (consult--preview-allowed-p fun)
(funcall fun))
nil)))
(setq success (current-buffer)))
(unless success
(kill-buffer buffer))))))