From: Daniel Fleischer <danflscr@gmail.com>
To: 62857@debbugs.gnu.org
Subject: bug#62857: CUA rectangle mode in occur edit mode
Date: Sat, 22 Apr 2023 22:00:27 +0300 [thread overview]
Message-ID: <m2ttx7ivxw.fsf@gmail.com> (raw)
In-Reply-To: <m27cudzc4u.fsf@gmail.com>
Eli Zaretskii <eliz@gnu.org> writes:
> Thanks. This actually reveals a serious bug in the C
> re-implementation of line-number-at-pos: it was signaling an error for
> positions outside of the narrowing, where the original Lisp
> implementation didn't. I've now fixed this on the emacs-29 branch.
> Can you test the fix? The diffs are below, for your convenience:
Tested on master 3badd2358d5, works as expected. Thanks!
> diff --git a/src/fns.c b/src/fns.c
> index ff364c6..e8cd621 100644
> --- a/src/fns.c
> +++ b/src/fns.c
> @@ -6116,29 +6116,40 @@ DEFUN ("line-number-at-pos", Fline_number_at_pos,
> from the absolute start of the buffer, disregarding the narrowing. */)
> (register Lisp_Object position, Lisp_Object absolute)
> {
> - ptrdiff_t pos, start = BEGV_BYTE;
> + ptrdiff_t pos_byte, start_byte = BEGV_BYTE;
>
> if (MARKERP (position))
> - pos = marker_position (position);
> + {
> + /* We don't trust the byte position if the marker's buffer is
> + not the current buffer. */
> + if (XMARKER (position)->buffer != current_buffer)
> + pos_byte = CHAR_TO_BYTE (marker_position (position));
> + else
> + pos_byte = marker_byte_position (position);
> + }
> else if (NILP (position))
> - pos = PT;
> + pos_byte = PT_BYTE;
> else
> {
> CHECK_FIXNUM (position);
> - pos = XFIXNUM (position);
> + ptrdiff_t pos = XFIXNUM (position);
> + /* Check that POSITION is valid. */
> + if (pos < BEG || pos > Z)
> + args_out_of_range_3 (position, make_int (BEG), make_int (Z));
> + pos_byte = CHAR_TO_BYTE (pos);
> }
>
> if (!NILP (absolute))
> - start = BEG_BYTE;
> + start_byte = BEG_BYTE;
> + else if (NILP (absolute))
> + pos_byte = clip_to_bounds (BEGV_BYTE, pos_byte, ZV_BYTE);
>
> - /* Check that POSITION is in the accessible range of the buffer, or,
> - if we're reporting absolute positions, in the buffer. */
> - if (NILP (absolute) && (pos < BEGV || pos > ZV))
> - args_out_of_range_3 (make_int (pos), make_int (BEGV), make_int (ZV));
> - else if (!NILP (absolute) && (pos < 1 || pos > Z))
> - args_out_of_range_3 (make_int (pos), make_int (1), make_int (Z));
> + /* Check that POSITION is valid. */
> + if (pos_byte < BEG_BYTE || pos_byte > Z_BYTE)
> + args_out_of_range_3 (make_int (BYTE_TO_CHAR (pos_byte)),
> + make_int (BEG), make_int (Z));
>
> - return make_int (count_lines (start, CHAR_TO_BYTE (pos)) + 1);
> + return make_int (count_lines (start_byte, pos_byte) + 1);
> }
> \f
>
>
>
>
>
--
Daniel Fleischer
next prev parent reply other threads:[~2023-04-22 19:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-15 10:13 bug#62857: CUA rectangle mode in occur edit mode Daniel Fleischer
2023-04-22 9:06 ` Eli Zaretskii
2023-04-22 14:14 ` Daniel Fleischer
2023-04-22 16:31 ` Eli Zaretskii
2023-04-22 19:00 ` Daniel Fleischer [this message]
2023-04-22 19:28 ` Eli Zaretskii
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=m2ttx7ivxw.fsf@gmail.com \
--to=danflscr@gmail.com \
--cc=62857@debbugs.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).