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.
master
Benno Schulenberg 2019-05-30 19:46:08 +02:00
parent e1c011c9a1
commit 3a65c0d192
1 changed files with 2 additions and 0 deletions

View File

@ -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;
}