* count-lines and off-by-one error
@ 2020-08-26 12:29 Thibaut Verron
0 siblings, 0 replies; only message in thread
From: Thibaut Verron @ 2020-08-26 12:29 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1174 bytes --]
Hello,
The documentation for `count-lines' is the following:
> Return number of lines between START and END.
> This is usually the number of newlines between them,
> but can be one more if START is not equal to END
> and the greater of them is not at the start of a line.
I can vaguely understand this behaviour: it counts the number of non-empty
lines between START and END... except that it also counts empty lines if
they are in the middle. So, the number of lines, including the last one if
non-empty. Is that so?
Is there no built-in function computing the number of newlines between two
positions? There are multiple ways to do it, for example a subtraction
between `line-number-at-pos' (which does call `count-lines' but returns the
correct result), a wrapper around `count-lines' working around the edge
cases, or a call to `count-matches'. But it seems to me that it's a common
enough task to warrant a built-in method.
At the very least, `count-screen-lines' takes an optional argument
specifying whether to _always_ count this extra line (so, even at the
beginning of a line), maybe `count-lines' could get this behaviour too?
Thanks, best regards,
Thibaut
[-- Attachment #2: Type: text/html, Size: 1409 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-26 12:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-26 12:29 count-lines and off-by-one error Thibaut Verron
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.