From 3a65c0d1929ae8f7c3465c18696c7a6cb7548cd5 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 30 May 2019 19:46:08 +0200 Subject: [PATCH] feedback: when the last line is empty, don't include it in the count Now M-D will report 0 lines instead of 1 line for an empty buffer, and will match the output of 'wc --lines' as long the file is a POSIX file. This fixes https://savannah.gnu.org/bugs/?56054. Bug existed since before version 2.1.10. --- src/text.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/text.c b/src/text.c index 01afb5de..df17ad24 100644 --- a/src/text.c +++ b/src/text.c @@ -3061,6 +3061,7 @@ void do_wordlinechar_count(void) * do, but get the latter in multibyte characters. */ if (was_mark) { lines = openfile->filebot->lineno - openfile->filetop->lineno + 1; + lines -= (openfile->filebot->data[0] == '\0') ? 1 : 0; chars = get_totsize(openfile->filetop, openfile->filebot); /* Unpartition the buffer so that it contains all the text @@ -3069,6 +3070,7 @@ void do_wordlinechar_count(void) openfile->mark = was_mark; } else { lines = openfile->filebot->lineno; + lines -= (openfile->filebot->data[0] == '\0') ? 1 : 0; chars = openfile->totsize; }