From 0488fea0dea7f092f6c4bbaa744118f0d6275263 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 13 Dec 2015 12:41:30 +0900 Subject: [PATCH] vim-patch:7.4.635 Problem: If no NL or CR is found in the first block of a file then the 'fileformat' may be set to "mac". (Issue 77) Solution: Check if a CR was found. (eswald) https://github.com/vim/vim/commit/05eb612ff3597fb7102f892bfd320f28b56d2fc6 --- src/nvim/fileio.c | 11 +++++++++++ src/nvim/version.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index bc5b08ef24..7cc483ea11 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1544,6 +1544,11 @@ rewind_retry: /* First try finding a NL, for Dos and Unix */ if (try_dos || try_unix) { for (p = ptr; p < ptr + size; ++p) { + // Reset the carriage return counter. + if (try_mac) { + try_mac = 1; + } + if (*p == NL) { if (!try_unix || (try_dos && p > ptr && p[-1] == CAR)) @@ -1551,6 +1556,8 @@ rewind_retry: else fileformat = EOL_UNIX; break; + } else if (*p == CAR && try_mac) { + try_mac++; } } @@ -1571,6 +1578,10 @@ rewind_retry: if (try_mac > try_unix) fileformat = EOL_MAC; } + } else if (fileformat == EOL_UNKNOWN && try_mac == 1) { + // Looking for CR but found no end-of-line markers at all: + // use the default format. + fileformat = default_fileformat(); } } diff --git a/src/nvim/version.c b/src/nvim/version.c index 2b0d6f22f2..fef499ed6c 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -361,7 +361,7 @@ static int included_patches[] = { // 638 NA 637, 636, - // 635, + 635, // 634, 633, // 632 NA