diff options
| author | Juri Linkov | 2018-12-07 00:38:42 +0200 |
|---|---|---|
| committer | Juri Linkov | 2018-12-07 00:38:42 +0200 |
| commit | bcd74314626db88a8ff3c9deeb6ea7fbcd337413 (patch) | |
| tree | 64149092b12cc07994e8d906f196f83b11b8a0c0 | |
| parent | 0e8e5da1e8da0752fc02bf590a17697af4c0afd3 (diff) | |
| download | emacs-bcd74314626db88a8ff3c9deeb6ea7fbcd337413.tar.gz emacs-bcd74314626db88a8ff3c9deeb6ea7fbcd337413.zip | |
* lisp/vc/vc.el (vc-find-revision-no-save): Add optional arg BUFFER.
(Bug#33567)
| -rw-r--r-- | lisp/vc/vc.el | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index de43544864f..dbbc3e20380 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el | |||
| @@ -1998,33 +1998,41 @@ Saves the buffer to the file." | |||
| 1998 | (set (make-local-variable 'vc-parent-buffer) filebuf)) | 1998 | (set (make-local-variable 'vc-parent-buffer) filebuf)) |
| 1999 | result-buf))) | 1999 | result-buf))) |
| 2000 | 2000 | ||
| 2001 | (defun vc-find-revision-no-save (file revision &optional backend) | 2001 | (defun vc-find-revision-no-save (file revision &optional backend buffer) |
| 2002 | "Read REVISION of FILE into a buffer and return the buffer. | 2002 | "Read REVISION of FILE into BUFFER and return the buffer. |
| 2003 | Unlike `vc-find-revision-save', doesn't save the created buffer to file." | 2003 | If BUFFER omitted or nil, this function creates a new buffer and sets |
| 2004 | (let ((filebuf (or (get-file-buffer file) (current-buffer))) | 2004 | `buffer-file-name' to the name constructed from the file name and the |
| 2005 | (filename (vc-version-backup-file-name file revision 'manual))) | 2005 | revision number. |
| 2006 | (unless (or (get-file-buffer filename) | 2006 | Unlike `vc-find-revision-save', doesn't save the buffer to the file." |
| 2007 | (file-exists-p filename)) | 2007 | (let* ((buffer (when (buffer-live-p buffer) buffer)) |
| 2008 | (filebuf (or buffer (get-file-buffer file) (current-buffer))) | ||
| 2009 | (filename (unless buffer (vc-version-backup-file-name file revision 'manual)))) | ||
| 2010 | (unless (and (not buffer) | ||
| 2011 | (or (get-file-buffer filename) | ||
| 2012 | (file-exists-p filename))) | ||
| 2008 | (with-current-buffer filebuf | 2013 | (with-current-buffer filebuf |
| 2009 | (let ((failed t)) | 2014 | (let ((failed t)) |
| 2010 | (unwind-protect | 2015 | (unwind-protect |
| 2011 | (let ((coding-system-for-read 'no-conversion) | 2016 | (let ((coding-system-for-read 'no-conversion) |
| 2012 | (coding-system-for-write 'no-conversion)) | 2017 | (coding-system-for-write 'no-conversion)) |
| 2013 | (with-current-buffer (create-file-buffer filename) | 2018 | (with-current-buffer (or buffer (create-file-buffer filename)) |
| 2014 | (setq buffer-file-name filename) | 2019 | (unless buffer (setq buffer-file-name filename)) |
| 2015 | (let ((outbuf (current-buffer))) | 2020 | (let ((outbuf (current-buffer))) |
| 2016 | (with-current-buffer filebuf | 2021 | (with-current-buffer filebuf |
| 2017 | (if backend | 2022 | (if backend |
| 2018 | (vc-call-backend backend 'find-revision file revision outbuf) | 2023 | (vc-call-backend backend 'find-revision file revision outbuf) |
| 2019 | (vc-call find-revision file revision outbuf)))) | 2024 | (vc-call find-revision file revision outbuf)))) |
| 2020 | (goto-char (point-min)) | 2025 | (goto-char (point-min)) |
| 2021 | (normal-mode) | 2026 | (if buffer (let ((buffer-file-name file)) (normal-mode)) (normal-mode)) |
| 2022 | (set-buffer-modified-p nil) | 2027 | (set-buffer-modified-p nil) |
| 2023 | (setq buffer-read-only t)) | 2028 | (setq buffer-read-only t)) |
| 2024 | (setq failed nil)) | 2029 | (setq failed nil)) |
| 2025 | (when (and failed (get-file-buffer filename)) | 2030 | (when (and failed (unless buffer (get-file-buffer filename))) |
| 2031 | (with-current-buffer (get-file-buffer filename) | ||
| 2032 | (set-buffer-modified-p nil)) | ||
| 2026 | (kill-buffer (get-file-buffer filename))))))) | 2033 | (kill-buffer (get-file-buffer filename))))))) |
| 2027 | (let ((result-buf (or (get-file-buffer filename) | 2034 | (let ((result-buf (or buffer |
| 2035 | (get-file-buffer filename) | ||
| 2028 | (find-file-noselect filename)))) | 2036 | (find-file-noselect filename)))) |
| 2029 | (with-current-buffer result-buf | 2037 | (with-current-buffer result-buf |
| 2030 | (set (make-local-variable 'vc-parent-buffer) filebuf)) | 2038 | (set (make-local-variable 'vc-parent-buffer) filebuf)) |