GNU bug report logs -
#55847
29.0.50; line-number-at-pos ignores absolute parameter when checking position range
Previous Next
Reported by: Antoine Kalmbach <ane <at> iki.fi>
Date: Wed, 8 Jun 2022 11:45:02 UTC
Severity: normal
Tags: notabug
Found in version 29.0.50
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #11 received at 55847 <at> debbugs.gnu.org (full text, mbox):
tags 55847 notabug
thanks
> From: Antoine Kalmbach <ane <at> iki.fi>
> Date: Wed, 08 Jun 2022 14:44:10 +0300
>
>
> When working with a narrowed buffer, line-number-at-pos complains
> that the passed position parameter is out of range.
>
> I believe this occurs because in fns.c there is check as follows:
>
> if (pos < BEGV || pos > ZV)
Yes, and that's by design. With very rare exceptions, Emacs always
behaves as if text outside of the narrowed region doesn't exist.
This is not a bug.
> This works just fine when the buffer isn't narrowed, but narrowing
> affects BEGV. Suppose the buffer is narrowed, and you want to get the
> line number for position x where x is before where the current narrowing
> begins, passing (line-number-at-pos x t) now reports an error, because
> the correct thing to check is BEGV_BYTE, not BEGV.
You mean BEG, not BEGV_BYTE, I believe. BEGV_BYTE is the _byte_
position corresponding to BEGV (which is a character position).
Anyway, if you want to get line-number-at-pos outside of the
restriction, you can simply do
(save-restriction
(widen)
(line-number-at-pos POS))
This is what we do in Emacs if we want to access position outside of
the narrowed region.
This bug report was last modified 2 years and 348 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.