unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20276: 24.4; diff-mode doesn't handle unified diff file headers without tabs
@ 2015-04-07 22:34 Gustav Hållberg
  2015-04-08 20:50 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Gustav Hållberg @ 2015-04-07 22:34 UTC (permalink / raw)
  To: 20276

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

In diff-mode, "o" doesn't recognize unified diff file headers if they do
not contain tabs. Some diff programs will not emit tab + timestamp (as
GNU diff does), but just the file name.

Example working file header (where ".txt" is followed by tabs):

--- a.txt 2015-04-08 00:09:46.000000000 +0200
+++ b.txt 2015-04-08 00:09:51.000000000 +0200

Example failing file header:

--- a.txt
+++ b.txt

The fallback is for "o" to open the file on the leading "diff" line
which may or may not be present.

This used to work in Emacs 24.3.1 but does not as of the patch mentioned
here:
http://stackoverflow.com/questions/14720205/how-do-i-use-emacs-diff-with-spaces

My proposal is to fix this in (diff-hunk-file-names) by removing the
requirement for the trailing tab on the leading diff file header and
replace it with a no-newline check (sorry for not providing proper
patch):

-          (if (looking-at "[-*][-*][-*] \\([^\t]+\\)\t.*\n[-+][-+][-+]
\\([^\t]+\\)")
+          (if (looking-at "[-*][-*][-*] \\([^\t\n]+\\).*\n[-+][-+][-+]
\\([^\t\n]+\\)")

The return values should probably use (match-string-no-properties)
rather than (match-string) as well.

Thanks,
 Gustav

[-- Attachment #2: Type: text/html, Size: 1846 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20276: 24.4; diff-mode doesn't handle unified diff file headers without tabs
  2015-04-07 22:34 bug#20276: 24.4; diff-mode doesn't handle unified diff file headers without tabs Gustav Hållberg
@ 2015-04-08 20:50 ` Stefan Monnier
  2015-04-08 22:38   ` Gustav Hållberg
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2015-04-08 20:50 UTC (permalink / raw)
  To: Gustav Hållberg; +Cc: 20276

> Some diff programs will not emit tab + timestamp (as GNU diff does),
> but just the file name.

Which diff programs do that?

> -          (if (looking-at "[-*][-*][-*] \\([^\t]+\\)\t.*\n[-+][-+][-+]
> \\([^\t]+\\)")
> +          (if (looking-at "[-*][-*][-*] \\([^\t\n]+\\).*\n[-+][-+][-+]
> \\([^\t\n]+\\)")

Adding \n in the char-ranges is fine (it's a good change in itself), but
removing the \t increases the risk of false positives, so I'm a bit
worried about that.


        Stefan





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20276: 24.4; diff-mode doesn't handle unified diff file headers without tabs
  2015-04-08 20:50 ` Stefan Monnier
@ 2015-04-08 22:38   ` Gustav Hållberg
  2015-04-09  1:48     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Gustav Hållberg @ 2015-04-08 22:38 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 20276

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

On Wed, Apr 8, 2015 at 10:50 PM, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > Some diff programs will not emit tab + timestamp (as GNU diff does),
> > but just the file name.
>
> Which diff programs do that?
>

diff -u with -L does for example:

  $ diff -u -Lfoo a.txt -Lbar b.txt
  --- foo
  +++ bar
    :

git diff also does for what it's worth.


>
> > -          (if (looking-at "[-*][-*][-*] \\([^\t]+\\)\t.*\n[-+][-+][-+]
> > \\([^\t]+\\)")
> > +          (if (looking-at "[-*][-*][-*] \\([^\t\n]+\\).*\n[-+][-+][-+]
> > \\([^\t\n]+\\)")
>
> Adding \n in the char-ranges is fine (it's a good change in itself), but
> removing the \t increases the risk of false positives, so I'm a bit
> worried about that.
>

True, but note that diff-font-lock-keywords is more permissive; it does not
require the tab to be present.

- Gustav



>
>
>         Stefan
>

[-- Attachment #2: Type: text/html, Size: 1940 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20276: 24.4; diff-mode doesn't handle unified diff file headers without tabs
  2015-04-08 22:38   ` Gustav Hållberg
@ 2015-04-09  1:48     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2015-04-09  1:48 UTC (permalink / raw)
  To: Gustav Hållberg; +Cc: 20276-done

> git diff also does for what it's worth.

Ah, indeed.  This doesn't bite us too hard because git also happens to
provide the "diff ..." line.

> True, but note that diff-font-lock-keywords is more permissive; it does not
> require the tab to be present.

Of course a false positive in diff-font-lock-keywords will only look
funny but won't affect actual behavior, which is why I thought it was OK
to be more permissive.

Anyway, I guess we have to bite this bullet, so I installed your patch
into "master".  Thanks,


        Stefan





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-09  1:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-07 22:34 bug#20276: 24.4; diff-mode doesn't handle unified diff file headers without tabs Gustav Hållberg
2015-04-08 20:50 ` Stefan Monnier
2015-04-08 22:38   ` Gustav Hållberg
2015-04-09  1:48     ` Stefan Monnier

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).