unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 33567@debbugs.gnu.org, dgutov@yandex.ru
Subject: bug#33567: Syntactic fontification of diff hunks
Date: Wed, 05 Dec 2018 00:58:49 +0200	[thread overview]
Message-ID: <87r2ew6fda.fsf@mail.linkov.net> (raw)
In-Reply-To: <83bm61aiw9.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 04 Dec 2018 08:46:46 +0200")

[-- Attachment #1: Type: text/plain, Size: 960 bytes --]

>> -(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.
>
> Since you use BUFFER, please drop the "a" part.
>
> Also, the doc string should tell what BUFFER defaults to if omitted or
> nil.

Updated.

>> +  (let ((filebuf (or buffer (get-file-buffer file) (current-buffer)))
>                      ^^^^^^^^^
> I would use bufferp here.  What if someone calls the function with
> something that is not a buffer?

Added buffer-live-p.

> And, btw, are buffer names allowed?

I see that most VC functions work with buffer objects only.
So buffer names could be allowed only when really necessary.

> Similarly with other places where you make the same test (why not make
> it once and bind some local variable to the result, btw?).

Done:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-find-revision-no-save-buffer.2.patch --]
[-- Type: text/x-diff, Size: 2919 bytes --]

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index de43544864..dbbc3e2038 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1998,33 +1998,41 @@ vc-find-revision-save
 	(set (make-local-variable 'vc-parent-buffer) filebuf))
       result-buf)))
 
-(defun vc-find-revision-no-save (file revision &optional backend)
-  "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))
+(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
 	      (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)
+                    (coding-system-for-write 'no-conversion))
+		(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))))
                   (goto-char (point-min))
-                  (normal-mode)
+                  (if buffer (let ((buffer-file-name file)) (normal-mode)) (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	other threads:[~2018-12-04 22:58 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-01 21:55 bug#33567: Syntactic fontification of diff hunks Juri Linkov
2018-12-02  6:56 ` Eli Zaretskii
2018-12-03  0:34   ` Juri Linkov
2018-12-03  6:49     ` Eli Zaretskii
2018-12-03 23:36       ` Juri Linkov
2018-12-04  7:01         ` Eli Zaretskii
2018-12-04 23:16           ` Juri Linkov
2018-12-05  7:19             ` Eli Zaretskii
2018-12-05 23:25               ` Juri Linkov
2018-12-06  6:53                 ` Eli Zaretskii
2018-12-11  0:38               ` Juri Linkov
2018-12-11  6:23                 ` Eli Zaretskii
2018-12-12  0:28                   ` Juri Linkov
2018-12-12 17:11                     ` Eli Zaretskii
2018-12-03 23:59       ` Juri Linkov
2018-12-04  7:36         ` Eli Zaretskii
2018-12-04 23:28           ` Juri Linkov
2018-12-05  7:25             ` Eli Zaretskii
2018-12-05 23:35               ` Juri Linkov
2018-12-12 23:17                 ` Juri Linkov
2018-12-14  9:13                   ` Eli Zaretskii
2018-12-16 23:27                     ` Juri Linkov
2018-12-17 16:13                       ` Eli Zaretskii
2018-12-17 23:11                         ` Juri Linkov
2018-12-18  0:14                           ` Juri Linkov
2018-12-18 15:55                           ` Dmitry Gutov
2018-12-18 22:35                             ` Juri Linkov
2018-12-18 23:33                               ` Dmitry Gutov
2018-12-19  0:11                                 ` Juri Linkov
2018-12-19  0:48                                   ` Dmitry Gutov
2018-12-19  1:35                                     ` Dmitry Gutov
2018-12-19 21:49                                       ` Juri Linkov
2018-12-19 22:50                                         ` Dmitry Gutov
2018-12-20 22:00                                           ` Juri Linkov
2018-12-24  2:29                                             ` Dmitry Gutov
2018-12-25 20:35                                               ` Juri Linkov
2018-12-25 21:15                                                 ` Dmitry Gutov
2018-12-26 22:49                                                   ` Juri Linkov
2018-12-26 23:16                                                     ` Dmitry Gutov
2018-12-27  0:18                                                       ` Juri Linkov
2018-12-27  0:45                                                         ` Dmitry Gutov
2018-12-27  3:34                                                         ` Eli Zaretskii
2018-12-27  3:32                                                       ` Eli Zaretskii
2018-12-19 21:51                                     ` Juri Linkov
2018-12-20  0:11                                       ` Dmitry Gutov
2018-12-20 21:50                                         ` Juri Linkov
2018-12-20  1:15                                   ` Dmitry Gutov
2018-12-20 22:17                                     ` Juri Linkov
2018-12-25 20:39                                       ` Juri Linkov
2018-12-26  1:40                                         ` Dmitry Gutov
2018-12-26 22:59                                           ` Juri Linkov
2018-12-26 23:56                                             ` Dmitry Gutov
2018-12-27 20:39                                               ` Juri Linkov
2018-12-29 23:07                                                 ` Juri Linkov
2018-12-30 23:07                                                   ` Dmitry Gutov
2018-12-26  0:43                                       ` Dmitry Gutov
2018-12-03 11:24     ` Dmitry Gutov
2018-12-03 23:24       ` Juri Linkov
2018-12-04  0:20         ` Dmitry Gutov
2018-12-04  6:46         ` Eli Zaretskii
2018-12-04 22:58           ` Juri Linkov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r2ew6fda.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=33567@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).