From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#33567: Syntactic fontification of diff hunks Date: Wed, 12 Dec 2018 02:28:08 +0200 Organization: LINKOV.NET Message-ID: <871s6nn01r.fsf@mail.linkov.net> References: <878t18j4is.fsf@mail.linkov.net> <83a7lobemr.fsf@gnu.org> <87a7lnv6ex.fsf@mail.linkov.net> <83pnuj9kb8.fsf@gnu.org> <87bm62npwr.fsf@mail.linkov.net> <83a7llai7v.fsf@gnu.org> <87va4826tz.fsf@mail.linkov.net> <83sgzc8mp0.fsf@gnu.org> <87a7lcj2f8.fsf@mail.linkov.net> <83tvjk1t06.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1544575275 32137 195.159.176.226 (12 Dec 2018 00:41:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 12 Dec 2018 00:41:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 33567@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 12 01:41:11 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWsaM-0008GY-If for geb-bug-gnu-emacs@m.gmane.org; Wed, 12 Dec 2018 01:41:10 +0100 Original-Received: from localhost ([::1]:42055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWscT-0000pd-8g for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Dec 2018 19:43:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWscF-0000nn-7J for bug-gnu-emacs@gnu.org; Tue, 11 Dec 2018 19:43:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWscC-000639-48 for bug-gnu-emacs@gnu.org; Tue, 11 Dec 2018 19:43:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40036) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gWscC-00062x-0B for bug-gnu-emacs@gnu.org; Tue, 11 Dec 2018 19:43:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gWscB-0006y4-Tn for bug-gnu-emacs@gnu.org; Tue, 11 Dec 2018 19:43:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Dec 2018 00:43:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33567 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 33567-submit@debbugs.gnu.org id=B33567.154457536526735 (code B ref 33567); Wed, 12 Dec 2018 00:43:03 +0000 Original-Received: (at 33567) by debbugs.gnu.org; 12 Dec 2018 00:42:45 +0000 Original-Received: from localhost ([127.0.0.1]:44290 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWsbt-0006x9-2U for submit@debbugs.gnu.org; Tue, 11 Dec 2018 19:42:45 -0500 Original-Received: from palegreen.birch.relay.mailchannels.net ([23.83.209.140]:60581) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWsbr-0006wz-7Y for 33567@debbugs.gnu.org; Tue, 11 Dec 2018 19:42:43 -0500 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 5CB4A3E35F2; Wed, 12 Dec 2018 00:42:41 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a34.g.dreamhost.com (unknown [100.96.33.121]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 130F73E3123; Wed, 12 Dec 2018 00:42:41 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a34.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.16.2); Wed, 12 Dec 2018 00:42:41 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Troubled-Towering: 02ddcdfc1e1fa256_1544575361177_1300027579 X-MC-Loop-Signature: 1544575361177:3603106414 X-MC-Ingress-Time: 1544575361176 Original-Received: from pdx1-sub0-mail-a34.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a34.g.dreamhost.com (Postfix) with ESMTP id A0D11807B4; Tue, 11 Dec 2018 16:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=wWwvZM2puHTqGcH9TbxpZtSBBAk=; b= 1HUIeF4Bj7tr2ZgGJExy9XlaKt+RGXbXxYdVnhgc+RHIxTjO4XliwSj/cB17qJGB CRraOgWHUgtFukr+cfrLpy2jjcDLVt40pZBKuLGkF8B7ZAYvE0wkDG1oHi/PY3ZI jUleBflnngVu8C7h0xiKvJQDhzy8auK73Pl2zucU3ec= Original-Received: from mail.jurta.org (m91-129-96-177.cust.tele2.ee [91.129.96.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a34.g.dreamhost.com (Postfix) with ESMTPSA id 59ADB807AB; Tue, 11 Dec 2018 16:42:38 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a34 In-Reply-To: <83tvjk1t06.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 11 Dec 2018 08:23:37 +0200") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrudegkedgvdeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrdeliedrudejjeenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepmhgrihhlrdhjuhhrthgrrdhorhhgpdhinhgvthepledurdduvdelrdeliedrudejjedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopegvlhhiiiesghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpedt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:153372 Archived-At: > . 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. Thanks for the explanation. I explored more on this subject, and found the most suitable existing function: `decode-coding-inserted-region'. I tested it with different codings and everything works well: diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 5ff9f4d5be..127661a039 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -2042,6 +2042,8 @@ vc-find-revision-no-save (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 (let ((buffer-file-name file)) (normal-mode)) (normal-mode)) (set-buffer-modified-p nil)