From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#62857: CUA rectangle mode in occur edit mode Date: Sat, 22 Apr 2023 19:31:49 +0300 Message-ID: <83354r280a.fsf@gnu.org> References: <83v8ho1e18.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24188"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 62857@debbugs.gnu.org To: Daniel Fleischer Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 22 18:32:19 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pqG9r-00064n-9l for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 Apr 2023 18:32:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pqG9b-0006cX-L3; Sat, 22 Apr 2023 12:32:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqG9a-0006cI-2G for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2023 12:32:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pqG9Z-0001cF-Ng for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2023 12:32:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pqG9Z-0008W0-K0 for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2023 12:32:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Apr 2023 16:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62857 X-GNU-PR-Package: emacs Original-Received: via spool by 62857-submit@debbugs.gnu.org id=B62857.168218110032700 (code B ref 62857); Sat, 22 Apr 2023 16:32:01 +0000 Original-Received: (at 62857) by debbugs.gnu.org; 22 Apr 2023 16:31:40 +0000 Original-Received: from localhost ([127.0.0.1]:44050 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pqG9E-0008VL-06 for submit@debbugs.gnu.org; Sat, 22 Apr 2023 12:31:40 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53962) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pqG9C-0008V9-2Q for 62857@debbugs.gnu.org; Sat, 22 Apr 2023 12:31:38 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqG96-0001ZV-Ng; Sat, 22 Apr 2023 12:31:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=GEgNvU/6hjFY8K+5TXTQZyDKUL6BEZPIj7Wmps9qTf4=; b=rB0o6T+jewvh i/yKk2cpzFuVSqJE9hfPq3YnAOwooRBWcqMMIuaYd3DaukK6soxeHQ2uHJG6pAdlRWebMB9BJOm8e XnSnknY+dca+fxIQDaTHhduFFdA1zNDPR7JXYJnmWC0sXJB8qyGn4g/Dh72Nk3+lfyEXyn/LX+frL InCsFeyI5n8zMMrSdCit3HffLarMI5sV4lEDTYlToj8Sm1qxo9df8bg4ZB8j8BmfNzEehihqQYkxy KOZ5JhlnQVCRgtnKKMvtIuGo97AFcA0ZnRKyF38HHyt8OoaNVtsdVgljHk5hgrHWjvMPWtXB/sGre MQ4yACKiCp4/Zw8xOa+NUg==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqG95-00037A-80; Sat, 22 Apr 2023 12:31:32 -0400 In-Reply-To: (message from Daniel Fleischer on Sat, 22 Apr 2023 17:14:54 +0300) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:260480 Archived-At: > From: Daniel Fleischer > Date: Sat, 22 Apr 2023 17:14:54 +0300 > > - `find-file` some file with text. > - `M-x occur` and search some string. > - Move to the occur results buffer. > - `e` to edit it using `occur-edit-mode`. > - Call `M-x cua-rectangle-mark-mode`. > - Create some multiline block (move cursor down and right). > - Start inserting text, e.g. `a`. You get "Args out of range". > - continue inserting. > - `M-x cua-rectangle-mark-mode` to exit the mode. > - Press C-c C-c to apply the changes. > - Now can exit the occur results buffer and/or move to the original file. > - Original file wasn't changed during occur edit mode. 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: 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); }