GNU bug report logs - #55847
29.0.50; line-number-at-pos ignores absolute parameter when checking position range

Previous Next

Package: emacs;

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


View this message in rfc822 format

From: Antoine Kalmbach <ane <at> iki.fi>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 55847 <at> debbugs.gnu.org
Subject: bug#55847: 29.0.50; line-number-at-pos ignores absolute parameter when checking position range
Date: Thu, 09 Jun 2022 10:44:25 +0300
Eli Zaretskii <eliz <at> gnu.org> writes:

>> 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.
>

Hmm.  The reason I reported a bug is that the pre-28.1 version of
line-number-at-pos, which was in Lisp, did in fact work when the buffer
was narrowed. What is more, the docstring states that:

   If the buffer is narrowed, the return value by default counts the lines
   from the beginning of the accessible portion of the buffer.  But if the
   second optional argument ABSOLUTE is non-nil, the value counts the lines
   from the absolute start of the buffer, disregarding the narrowing.

Hence I would assume that if absolute is non-nil the call to
line-number-at-pos should work even if the buffer is narrowed, instead
of throwing an error.

> You mean BEG, not BEGV_BYTE, I believe.  BEGV_BYTE is the _byte_
> position corresponding to BEGV (which is a character position).

Right, yes. The actual beginning of the buffer, 1.

> 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.
>

Yes, thanks, this fixes it, it's what the Lisp version of pre-28 did
this when absolute was non-nil.

-- 
Antoine Kalmbach




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.