Function: vc-find-revision-no-save

vc-find-revision-no-save is an autoloaded and byte-compiled function defined in vc.el.gz.

Signature

(vc-find-revision-no-save FILE REVISION &optional BACKEND BUFFER)

Documentation

Read REVISION of FILE into BUFFER and return the buffer.

If BUFFER omitted or nil, this function creates a new buffer and sets buffer-file-name(var)/buffer-file-name(fun) to the name constructed from the file name and the revision number. Unlike vc-find-revision-save, doesn't save the buffer to the file.

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
(defun vc-find-revision-no-save (file revision &optional backend buffer)
  "Read REVISION of FILE into BUFFER and return the buffer.
If BUFFER omitted or nil, this function creates a new buffer and sets
`buffer-file-name' to the name constructed from the file name and the
revision number.
Unlike `vc-find-revision-save', doesn't save the buffer to the file."
  (let* ((buffer (when (buffer-live-p buffer) buffer))
         (filebuf (or buffer (get-file-buffer file) (current-buffer)))
         (filename (unless buffer (vc-version-backup-file-name file revision 'manual))))
    (unless (and (not buffer)
                 (or (get-file-buffer filename)
                     (file-exists-p filename)))
      (with-current-buffer filebuf
	(let ((failed t))
	  (unwind-protect
	      (with-current-buffer (or buffer (create-file-buffer filename))
                (unless buffer (setq buffer-file-name filename))
		(let ((outbuf (current-buffer)))
		  (with-current-buffer filebuf
		    (if backend
			(vc-call-backend backend 'find-revision file revision outbuf)
		      (vc-call find-revision file revision outbuf))))
                (decode-coding-inserted-region (point-min) (point-max) file)
                (after-insert-file-set-coding (- (point-max) (point-min)))
                (goto-char (point-min))
                (if buffer
                    ;; For non-interactive, skip any questions
                    (let ((enable-local-variables :safe) ;; to find `mode:'
                          (buffer-file-name file))
                      ;; Don't run hooks that might assume buffer-file-name
                      ;; really associates buffer with a file (bug#39190).
                      (ignore-errors (delay-mode-hooks (set-auto-mode))))
                  (normal-mode))
                (set-buffer-modified-p nil)
                (setq buffer-read-only t)
                (setq failed nil))
	    (when (and failed (unless buffer (get-file-buffer filename)))
	      (with-current-buffer (get-file-buffer filename)
		(set-buffer-modified-p nil))
	      (kill-buffer (get-file-buffer filename)))))))
    (let ((result-buf (or buffer
                          (get-file-buffer filename)
                          (find-file-noselect filename))))
      (with-current-buffer result-buf
        (setq-local vc-parent-buffer filebuf))
      result-buf)))