[PATCH 0/2] runtime: syntax: diff: further fixes

15 views
Skip to first unread message

Felipe Contreras

unread,
Dec 30, 2020, 11:38:41 AM12/30/20
to vim...@vim.org, Bram Moolenaar, Felipe Contreras
Patch 8.2.2128 fixed one issue with the diff syntax, but we can do better.

Felipe Contreras (2):
runtime: syntax: diff: fix order of files
runtime: syntax: diff: automatically detect format

runtime/syntax/diff.vim | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

--
2.30.0

Felipe Contreras

unread,
Dec 30, 2020, 11:38:42 AM12/30/20
to vim...@vim.org, Bram Moolenaar, Felipe Contreras
This way the correct ordering is always detected.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
runtime/syntax/diff.vim | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/runtime/syntax/diff.vim b/runtime/syntax/diff.vim
index 31ca835bf..5673284d5 100644
--- a/runtime/syntax/diff.vim
+++ b/runtime/syntax/diff.vim
@@ -348,11 +348,16 @@ syn match diffLine "^\d\+\(,\d\+\)\=[cda]\d\+\>.*"
syn match diffFile "^diff\>.*"
syn match diffFile "^Index: .*"
syn match diffFile "^==== .*"
-" Old style diff uses *** for old and --- for new.
-" Unified diff uses --- for old and +++ for new; names are wrong but it works.
-syn match diffNewFile "^+++ .*"
-syn match diffNewFile "^\*\*\* .*"
-syn match diffOldFile "^--- .*"
+
+if search('^@@ -\S\+ +\S\+ @@', 'nw', '', 100)
+ " unified
+ syn match diffOldFile "^--- .*"
+ syn match diffNewFile "^+++ .*"
+else
+ " context
+ syn match diffOldFile "^\*\*\* .*"
+ syn match diffNewFile "^--- .*"
+endif

" Used by git
syn match diffIndexLine "^index \x\x\x\x.*"
--
2.30.0

Felipe Contreras

unread,
Dec 30, 2020, 11:38:42 AM12/30/20
to vim...@vim.org, Bram Moolenaar, Felipe Contreras
If the order of files is going to be wrong, it should be wrong on the
vastly less used style: the older context format, not the newer unified
format.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
runtime/syntax/diff.vim | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/runtime/syntax/diff.vim b/runtime/syntax/diff.vim
index ac43d6650..31ca835bf 100644
--- a/runtime/syntax/diff.vim
+++ b/runtime/syntax/diff.vim
@@ -350,9 +350,9 @@ syn match diffFile "^Index: .*"
syn match diffFile "^==== .*"
" Old style diff uses *** for old and --- for new.
" Unified diff uses --- for old and +++ for new; names are wrong but it works.
-syn match diffOldFile "^+++ .*"
-syn match diffOldFile "^\*\*\* .*"
-syn match diffNewFile "^--- .*"
+syn match diffNewFile "^+++ .*"
+syn match diffNewFile "^\*\*\* .*"
+syn match diffOldFile "^--- .*"

Bram Moolenaar

unread,
Dec 30, 2020, 12:46:09 PM12/30/20
to vim...@googlegroups.com, Felipe Contreras, vim...@vim.org

Felipe Contreras wrote:

> This way the correct ordering is always detected.

Interesting idea. I suppose this will work best.


--
hundred-and-one symptoms of being an internet addict:
50. The last girl you picked up was only a jpeg.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages