all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Yuri Khan <yurivkhan@gmail.com>
Cc: "Andreas Röhler" <andreas.roehler@online.de>,
	"Emacs developers" <emacs-devel@gnu.org>
Subject: Re: Syntactic fontification of diff hunks
Date: Sun, 19 Aug 2018 23:57:27 +0300	[thread overview]
Message-ID: <8736va48jc.fsf@mail.linkov.net> (raw)
In-Reply-To: <CAP_d_8XgJYcLY=j1XNoPYOKY0+RAOLoXQyLj7sHekh0-t5S3RQ@mail.gmail.com> (Yuri Khan's message of "Sat, 18 Aug 2018 01:34:04 +0700")

> 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 “after”
> version by taking context + added lines and “before” by taking context
> + deleted lines. Then use fontification from “before” for deleted
> lines, and from “after” 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 used
to visit the file, fontify it and copy fontification back to the diff buffer),
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 ‘d’ (log-view-diff) or ‘D’ (log-view-diff-changeset);
3. try to navigate to the corresponding place in the file with ‘C-c C-c’
   (diff-goto-source)

It visits the current file version and most of the time errs with
“Hunk text not found”.

It seems the most sensible would be to checkout the corresponding file
revision like does ‘f’ (log-view-find-revision) from *vc-change-log*
(BTW, I wonder why it creates a file with the name “filename~commit-sha~”
instead of “filename~treefile-sha~”), but unlike ‘f’ 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 ‘-’ or ‘<’?



  reply	other threads:[~2018-08-19 20:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-16 21:08 Syntactic fontification of diff hunks Juri Linkov
2018-08-16 21:44 ` Kaushal Modi
2018-08-16 22:27   ` Juri Linkov
2018-08-16 22:33     ` Kaushal Modi
2018-08-16 22:41       ` Juri Linkov
2018-08-17  5:41 ` Yuri Khan
2018-08-17  6:00   ` Andreas Röhler
2018-08-17  6:47     ` Yuri Khan
2018-08-17 17:47       ` Juri Linkov
2018-08-17 18:34         ` Yuri Khan
2018-08-19 20:57           ` Juri Linkov [this message]
2018-08-18 20:02       ` Andreas Röhler

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

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

  git send-email \
    --in-reply-to=8736va48jc.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=andreas.roehler@online.de \
    --cc=emacs-devel@gnu.org \
    --cc=yurivkhan@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.