[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#33567: Syntactic fontification of diff hunks

From: Juri Linkov
Subject: bug#33567: Syntactic fontification of diff hunks
Date: Tue, 04 Dec 2018 01:24:52 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu)

>> Fixing the described problem will remove this comment,
>> but I have no idea how better to do this.  The problem is that
>> we need to provide own created buffer to the call to `vc-find-revision'.
>> Currently it has the following function signature:
>>    (defun vc-find-revision (file revision &optional backend)
>> But VC API in the comments in the beginning of vc.el
>> is documented with a different function signature:
>>    ;; * find-revision (file rev buffer)
>>    ;;
>>    ;;   Fetch revision REV of file FILE and put it into BUFFER.
>>    ;;   If REV is the empty string, fetch the head of the trunk.
>>    ;;   The implementation should pass the value of vc-checkout-switches
>>    ;;   to the backend command.
> That is the VC backend API, not the signatures of public functions in vc.el
> (which would be kinda pointless).
> vc-git-find-revision and friends do indeed have this signature.
> Take a look at the uses of vc-call-backend in
> vc-find-revision[-no]-save. Maybe you need to write a new ???-find-revision
> function that does what you need.

Thanks, I see now that we can freely add a new optional arg:

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index de43544864..4976deefef 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1998,33 +1998,37 @@ vc-find-revision-save
        (set (make-local-variable 'vc-parent-buffer) filebuf))
-(defun vc-find-revision-no-save (file revision &optional backend)
-  "Read REVISION of FILE into a buffer and return the buffer.
+(defun vc-find-revision-no-save (file revision &optional backend buffer)
+  "Read REVISION of FILE into a BUFFER and return the buffer.
 Unlike `vc-find-revision-save', doesn't save the created buffer to file."
-  (let ((filebuf (or (get-file-buffer file) (current-buffer)))
-        (filename (vc-version-backup-file-name file revision 'manual)))
-    (unless (or (get-file-buffer filename)
-                (file-exists-p filename))
+  (let ((filebuf (or buffer (get-file-buffer file) (current-buffer)))
+        (filename (unless buffer (vc-version-backup-file-name file revision 
+    (unless (and (not buffer)
+                 (or (get-file-buffer filename)
+                     (file-exists-p filename)))
       (with-current-buffer filebuf
        (let ((failed t))
              (let ((coding-system-for-read 'no-conversion)
                    (coding-system-for-write 'no-conversion))
-               (with-current-buffer (create-file-buffer filename)
-                  (setq buffer-file-name filename)
+               (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 
                        (vc-call find-revision file revision outbuf))))
                   (goto-char (point-min))
-                  (normal-mode)
+                  (if buffer (let ((buffer-file-name file)) (normal-mode)) 
                  (set-buffer-modified-p nil)
                   (setq buffer-read-only t))
                (setq failed nil))
-           (when (and failed (get-file-buffer filename))
+           (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 (get-file-buffer filename)
+    (let ((result-buf (or buffer
+                          (get-file-buffer filename)
                           (find-file-noselect filename))))
       (with-current-buffer result-buf
        (set (make-local-variable 'vc-parent-buffer) filebuf))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]