From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Syntactic fontification of diff hunks Date: Sun, 19 Aug 2018 23:57:27 +0300 Organization: LINKOV.NET Message-ID: <8736va48jc.fsf@mail.linkov.net> References: <87in4af29r.fsf@mail.linkov.net> <87o9e0khr7.fsf@mail.linkov.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1534715229 31402 195.159.176.226 (19 Aug 2018 21:47:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 19 Aug 2018 21:47:09 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: Andreas =?iso-8859-1?Q?R=F6hler?= , Emacs developers To: Yuri Khan Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 19 23:47:05 2018 Return-path: Envelope-to: ged-emacs-devel@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 1frVXN-000855-0R for ged-emacs-devel@m.gmane.org; Sun, 19 Aug 2018 23:47:05 +0200 Original-Received: from localhost ([::1]:44203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frVZT-0001wg-Dq for ged-emacs-devel@m.gmane.org; Sun, 19 Aug 2018 17:49:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frVZN-0001wP-AC for emacs-devel@gnu.org; Sun, 19 Aug 2018 17:49:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frVZK-00022Y-77 for emacs-devel@gnu.org; Sun, 19 Aug 2018 17:49:09 -0400 Original-Received: from homie-sub3.mail.dreamhost.com ([69.163.253.7]:46233 helo=homiemail-a22.g.dreamhost.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1frVZJ-00022B-UX for emacs-devel@gnu.org; Sun, 19 Aug 2018 17:49:06 -0400 Original-Received: from homiemail-a22.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTP id D4330114066; Sun, 19 Aug 2018 14:49:03 -0700 (PDT) Original-Received: from localhost.linkov.net (m91-129-110-6.cust.tele2.ee [91.129.110.6]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTPSA id 97A3F114065; Sun, 19 Aug 2018 14:49:02 -0700 (PDT) In-Reply-To: (Yuri Khan's message of "Sat, 18 Aug 2018 01:34:04 +0700") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 69.163.253.7 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:228699 Archived-At: > I see another potential issue. In your patch above, the whole hunk is > fontified as a whole, with all its context lines, deleted lines, and > added lines. A change on the line that opens a multiline string will > disrupt syntax until the end of hunk: > > (def foo () > - "Lorem ipsum > + "Cthulhu fhtagn > dolor sit amet") > > A more robust approach would be to fontify separately the =E2=80=9Cafte= r=E2=80=9D > version by taking context + added lines and =E2=80=9Cbefore=E2=80=9D by= taking context > + deleted lines. Then use fontification from =E2=80=9Cbefore=E2=80=9D f= or deleted > lines, and from =E2=80=9Cafter=E2=80=9D for context and added lines. Yes, this is easy to do. Also there is one significant difference between diff refinement overlays and diff syntax overlays: while for multiline refinement it's probably ok to put a refined overlay over the diff indicator symbols (such as + or - on at the beginning of the line) when refinement is highlighted using background colors and indicator with foreground color, but for multiline syntax elements (e.g. multiline strings) their foreground colors will overwrite foreground colors of diff indicators. A solution would be to split multiline syntax overlays and put them separately on each diff line. But the real problem is with git diffs. I tried to reuse the same code that visits a diff hunk in the corresponding file (this code could be use= d to visit the file, fontify it and copy fontification back to the diff buf= fer), but bumped into a deficiency: 1. try to open some git log with vc-print-log in a *vc-change-log* buffer= ; 2. open a diff using =E2=80=98d=E2=80=99 (log-view-diff) or =E2=80=98D=E2= =80=99 (log-view-diff-changeset); 3. try to navigate to the corresponding place in the file with =E2=80=98C= -c C-c=E2=80=99 (diff-goto-source) It visits the current file version and most of the time errs with =E2=80=9CHunk text not found=E2=80=9D. It seems the most sensible would be to checkout the corresponding file revision like does =E2=80=98f=E2=80=99 (log-view-find-revision) from *vc-= change-log* (BTW, I wonder why it creates a file with the name =E2=80=9Cfilename~comm= it-sha~=E2=80=9D instead of =E2=80=9Cfilename~treefile-sha~=E2=80=9D), but unlike =E2=80=98= f=E2=80=99 better not to save it, but just to create a file buffer and navigate to the changed place. Another question: shouldn't diff-goto-source be context-sensitive? Currently it visits the old file when invoked with the prefix arg. Maybe better also allow it to visit the old file when invoked on old lines beginning with =E2=80=98-=E2=80=99 or =E2=80=98<=E2=80=99?