unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Antoine Kalmbach <ane@iki.fi>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 55847@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	[thread overview]
Message-ID: <lysfoez3fq.fsf@iki.fi> (raw)
In-Reply-To: <83bkv35k3r.fsf@gnu.org> (message from Eli Zaretskii on Wed, 08 Jun 2022 17:02:32 +0300)

Eli Zaretskii <eliz@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





  reply	other threads:[~2022-06-09  7:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 11:44 bug#55847: 29.0.50; line-number-at-pos ignores absolute parameter when checking position range Antoine Kalmbach
2022-06-08 12:52 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-08 14:02 ` Eli Zaretskii
2022-06-09  7:44   ` Antoine Kalmbach [this message]
2022-06-09 10:46     ` Lars Ingebrigtsen
2022-06-09 11:19       ` Antoine Kalmbach
2022-06-09 12:43         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=lysfoez3fq.fsf@iki.fi \
    --to=ane@iki.fi \
    --cc=55847@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).