unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Juri Linkov <juri@linkov.net>
Cc: 33567@debbugs.gnu.org
Subject: bug#33567: Syntactic fontification of diff hunks
Date: Tue, 11 Dec 2018 08:23:37 +0200	[thread overview]
Message-ID: <83tvjk1t06.fsf@gnu.org> (raw)
In-Reply-To: <87a7lcj2f8.fsf@mail.linkov.net> (message from Juri Linkov on Tue, 11 Dec 2018 02:38:18 +0200)

> From: Juri Linkov <juri@linkov.net>
> Cc: 33567@debbugs.gnu.org
> Date: Tue, 11 Dec 2018 02:38:18 +0200
> 
> > If you still want to reuse the literal contents of the file, as
> > inserted by vc-git-find-revision etc., then you will have to duplicate
> > what insert-file-contents does internally.  I suggest to look at how
> > this is done in archive-set-buffer-as-visiting-file.
> 
> I looked at archive-set-buffer-as-visiting-file, and it seems it could
> be simplified based on the assumption that the backend inserts output
> in the binary coding.

"Binary coding" means what we have in the buffer is exactly what we
had on disk.  IOW, we have there the contents of the file in its
original encoding, and so decoding it correctly needs to use the same
facilities we normally use when visiting a file with the likes of
find-file.  archive-set-buffer-as-visiting-file solves precisely the
same problem.

> I tried and this fixes the problem:
> 
> diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
> index 5ff9f4d5be..c980369fa9 100644
> --- a/lisp/vc/vc.el
> +++ b/lisp/vc/vc.el
> @@ -2042,6 +2042,7 @@ vc-find-revision-no-save
>  		      (if backend
>  			  (vc-call-backend backend 'find-revision file revision outbuf)
>  			(vc-call find-revision file revision outbuf))))
> +                  (recode-region (point-min) (point-max) buffer-file-coding-system 'binary)

Where does the value of buffer-file-coding-system come from here?
Isn't that just (default-value 'buffer-file-coding-system)?  If so,
you were just lucky that it worked for you; in general, if the
encoding of the file is different from your locale-derived defaults,
the above won't DTRT.

In any case, really don't think recode-region is TRT in this case, for
several reasons:

 . recode-region is a command, so it wastes cycles checking the
   argument coding-system, which is entirely unnecessary in this case
 . it narrows the buffer, something that again is a waste of cycles
   for your case
 . it wastes even more cycles for "encoding" with 'binary', which in
   this case is a no-op, since the text was not decoded on reading
 . it doesn't use the following facilities for determining the right
   encoding, where you use buffer-file-coding-system:
    - auto-coding-function, which is where we detect the 'coding:'
      cookies in the first line and in the local vars, and use the
      data in auto-coding-alist and auto-coding-regexp-alist, and also
      call auto-coding-functions if needed
    - find-operation-coding-system by file name, which uses the data
      in file-coding-system-alist to determine the appropriate
      encoding given the file's name

The hard problem here is to determine what coding-system to use for
decoding a region that was inserted without any conversions; once the
encoding is determined, the rest boils down to calling
decode-coding-region with that encoding.  The method used by
archive-set-buffer-as-visiting-file solves that very problem, whereas
recode-region does not, because it is a command that relies on the
caller to specify the encoding, and is otherwise nothing more than a
thin wrapper around decode-coding-region.

If you need further help understanding what
archive-set-buffer-as-visiting-file does, and which parts might not be
relevant to the function you are writing, please ask specific
questions and I will gladly help as much as I can.  But recode-region
is IMO not the right tool for this job.

Thanks.





  reply	other threads:[~2018-12-11  6:23 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 [this message]
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

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=83tvjk1t06.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=33567@debbugs.gnu.org \
    --cc=juri@linkov.net \
    /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).