GNU bug report logs - #41934
reverse-region no longer works

Previous Next

Package: emacs;

Reported by: Richard Copley <rcopley <at> gmail.com>

Date: Thu, 18 Jun 2020 16:42:01 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 41934 in the body.
You can then email your comments to 41934 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Thu, 18 Jun 2020 16:42:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Richard Copley <rcopley <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 18 Jun 2020 16:42:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Richard Copley <rcopley <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: reverse-region no longer works
Date: Thu, 18 Jun 2020 17:41:19 +0100
Recipe:
Insert text in a buffer:

abc
def
ghi

Position the mark before the 'a' and point before the 'g'.
Do 'M-x reverse-region'.

An error is signalled, 'There are no full lines in the region'.

See #39376.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Thu, 18 Jun 2020 17:43:01 GMT) Full text and rfc822 format available.

Message #8 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Richard Copley <rcopley <at> gmail.com>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Thu, 18 Jun 2020 20:42:28 +0300
> From: Richard Copley <rcopley <at> gmail.com>
> Date: Thu, 18 Jun 2020 17:41:19 +0100
> 
> Insert text in a buffer:
> 
> abc
> def
> ghi
> 
> Position the mark before the 'a' and point before the 'g'.
> Do 'M-x reverse-region'.
> 
> An error is signalled, 'There are no full lines in the region'.

Thanks.  Does the patch below look good?

diff --git a/lisp/sort.el b/lisp/sort.el
index de0e1b9..6640c8f 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -554,8 +554,8 @@ reverse-region
   (if (> beg end)
       (let (mid) (setq mid end end beg beg mid)))
   (save-excursion
-    (when (or (< (line-beginning-position) beg)
-              (< end (line-end-position)))
+    (when (< (- end beg)
+             (- (line-end-position) (line-beginning-position)))
       (user-error "There are no full lines in the region"))
     ;; Put beg at the start of a line and end and the end of one --
     ;; the largest possible region which fits this criteria.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Thu, 18 Jun 2020 17:54:02 GMT) Full text and rfc822 format available.

Message #11 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Richard Copley <rcopley <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Thu, 18 Jun 2020 18:52:48 +0100
On Thu, 18 Jun 2020 at 18:42, Eli Zaretskii <eliz <at> gnu.org> wrote:
> diff --git a/lisp/sort.el b/lisp/sort.el
> index de0e1b9..6640c8f 100644
> --- a/lisp/sort.el
> +++ b/lisp/sort.el
> @@ -554,8 +554,8 @@ reverse-region
>    (if (> beg end)
>        (let (mid) (setq mid end end beg beg mid)))
>    (save-excursion
> -    (when (or (< (line-beginning-position) beg)
> -              (< end (line-end-position)))
> +    (when (< (- end beg)
> +             (- (line-end-position) (line-beginning-position)))
>        (user-error "There are no full lines in the region"))
>      ;; Put beg at the start of a line and end and the end of one --
>      ;; the largest possible region which fits this criteria.

Thanks,
No, that fails on this example:

[mark]abc
def
[point]abcdefghi




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Thu, 18 Jun 2020 18:00:01 GMT) Full text and rfc822 format available.

Message #14 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Richard Copley <rcopley <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Thu, 18 Jun 2020 18:59:21 +0100
On Thu, 18 Jun 2020 at 18:52, Richard Copley <rcopley <at> gmail.com> wrote:
> On Thu, 18 Jun 2020 at 18:42, Eli Zaretskii <eliz <at> gnu.org> wrote:
> Thanks,
> No, that fails on this example [...]

How's this?

diff --git a/lisp/sort.el b/lisp/sort.el
index de0e1b9519..f878db24a3 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -554,9 +554,6 @@ is the one that ends before END."
   (if (> beg end)
       (let (mid) (setq mid end end beg beg mid)))
   (save-excursion
-    (when (or (< (line-beginning-position) beg)
-              (< end (line-end-position)))
-      (user-error "There are no full lines in the region"))
     ;; Put beg at the start of a line and end and the end of one --
     ;; the largest possible region which fits this criteria.
     (goto-char beg)
@@ -568,6 +565,8 @@ is the one that ends before END."
     ;; reversal; it isn't difficult to add it afterward.
     (or (and (eolp) (not (bolp))) (progn (forward-line -1) (end-of-line)))
     (setq end (point-marker))
+    (when (<= end beg)
+      (user-error "There are no full lines in the region"))
     ;; The real work.  This thing cranks through memory on large regions.
     (let (ll (do t))
       (while do




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Thu, 18 Jun 2020 18:21:02 GMT) Full text and rfc822 format available.

Message #17 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Richard Copley <rcopley <at> gmail.com>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Thu, 18 Jun 2020 21:20:26 +0300
> From: Richard Copley <rcopley <at> gmail.com>
> Date: Thu, 18 Jun 2020 18:52:48 +0100
> Cc: 41934 <at> debbugs.gnu.org
> 
> No, that fails on this example:
> 
> [mark]abc
> def
> [point]abcdefghi

How about this:

diff --git a/lisp/sort.el b/lisp/sort.el
index de0e1b9..8a4a56c 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -554,9 +554,18 @@ reverse-region
   (if (> beg end)
       (let (mid) (setq mid end end beg beg mid)))
   (save-excursion
-    (when (or (< (line-beginning-position) beg)
-              (< end (line-end-position)))
-      (user-error "There are no full lines in the region"))
+    (let ((lbeg (save-excursion
+                  (goto-char beg)
+                  (if (bolp)
+                      beg
+                    (line-beginning-position 2))))
+          (lend (save-excursion
+                  (goto-char end)
+                  (if (bolp)
+                      end
+                    (line-beginning-position)))))
+      (when (>= lbeg lend)
+        (user-error "There are no full lines in the region")))
     ;; Put beg at the start of a line and end and the end of one --
     ;; the largest possible region which fits this criteria.
     (goto-char beg)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Thu, 18 Jun 2020 18:29:02 GMT) Full text and rfc822 format available.

Message #20 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Richard Copley <rcopley <at> gmail.com>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Thu, 18 Jun 2020 21:28:18 +0300
> From: Richard Copley <rcopley <at> gmail.com>
> Date: Thu, 18 Jun 2020 18:59:21 +0100
> Cc: 41934 <at> debbugs.gnu.org
> 
> On Thu, 18 Jun 2020 at 18:52, Richard Copley <rcopley <at> gmail.com> wrote:
> > On Thu, 18 Jun 2020 at 18:42, Eli Zaretskii <eliz <at> gnu.org> wrote:
> > Thanks,
> > No, that fails on this example [...]
> 
> How's this?

Looks good, but what if beg and end are on the same line (at the point
where you added the test)?  Does that not warrant the error message?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Thu, 18 Jun 2020 18:35:01 GMT) Full text and rfc822 format available.

Message #23 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Richard Copley <rcopley <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Thu, 18 Jun 2020 19:33:57 +0100
On Thu, 18 Jun 2020 at 19:28, Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> > From: Richard Copley <rcopley <at> gmail.com>
> > Date: Thu, 18 Jun 2020 18:59:21 +0100
> > Cc: 41934 <at> debbugs.gnu.org
> >
> > On Thu, 18 Jun 2020 at 18:52, Richard Copley <rcopley <at> gmail.com> wrote:
> > > On Thu, 18 Jun 2020 at 18:42, Eli Zaretskii <eliz <at> gnu.org> wrote:
> > > Thanks,
> > > No, that fails on this example [...]
> >
> > How's this?
>
> Looks good, but what if beg and end are on the same line (at the point
> where you added the test)?  Does that not warrant the error message?

Not that error message, no, but rather something like "There are fewer
than two lines in the region".

I don't see the point of this error at all: if there are fewer than
two lines in the region-to-be-reversed at that point, in my opinion
the command should have no effect.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Thu, 18 Jun 2020 18:46:02 GMT) Full text and rfc822 format available.

Message #26 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Richard Copley <rcopley <at> gmail.com>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Thu, 18 Jun 2020 21:44:56 +0300
> From: Richard Copley <rcopley <at> gmail.com>
> Date: Thu, 18 Jun 2020 19:33:57 +0100
> Cc: 41934 <at> debbugs.gnu.org
> 
> > Looks good, but what if beg and end are on the same line (at the point
> > where you added the test)?  Does that not warrant the error message?
> 
> Not that error message, no, but rather something like "There are fewer
> than two lines in the region".

The original message says "lines", plural, so I think it kinda hints
on that.  We could make it say something that will cover both cases.

> I don't see the point of this error at all: if there are fewer than
> two lines in the region-to-be-reversed at that point, in my opinion
> the command should have no effect.

Indeed, it doesn't have any effect.  I'm asking whether this should be
flagged, since doing that makes no sense.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Fri, 19 Jun 2020 11:32:01 GMT) Full text and rfc822 format available.

Message #29 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Richard Copley <rcopley <at> gmail.com>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Fri, 19 Jun 2020 14:31:25 +0300
> From: Richard Copley <rcopley <at> gmail.com>
> Date: Thu, 18 Jun 2020 20:28:15 +0100
> 
> My opinion is:
> 
> (a) no, it doesn't make sense to complain 'user-error: There are no
> full lines in the region' when there is one full line.
> 
> (b) although we could still throw an error in that case (with a more
> appropriate message), I don't think it would help any users.
> 
> And indeed, I don't think raising the error is helpful even when there
> are zero lines to be reversed. It's probably harmless, but conceivably
> it could complicate somebody's hypothetical keyboard macro, for little
> gain.

Fair enough.

Here's the conundrum: I'd like to install your proposed change, but
the sum total of your contributions to Emacs already exceeds the
amount we can accept without legal papers.  So, unless you are willing
to sign the papers now, we cannot install your change.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41934; Package emacs. (Sat, 20 Jun 2020 10:05:01 GMT) Full text and rfc822 format available.

Message #32 received at 41934 <at> debbugs.gnu.org (full text, mbox):

From: Richard Copley <rcopley <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 41934 <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Sat, 20 Jun 2020 11:03:34 +0100
On Fri, 19 Jun 2020 at 12:31, Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> > From: Richard Copley <rcopley <at> gmail.com>
> > Date: Thu, 18 Jun 2020 20:28:15 +0100
> >
> > My opinion is:
> >
> > (a) no, it doesn't make sense to complain 'user-error: There are no
> > full lines in the region' when there is one full line.
> >
> > (b) although we could still throw an error in that case (with a more
> > appropriate message), I don't think it would help any users.
> >
> > And indeed, I don't think raising the error is helpful even when there
> > are zero lines to be reversed. It's probably harmless, but conceivably
> > it could complicate somebody's hypothetical keyboard macro, for little
> > gain.
>
> Fair enough.
>
> Here's the conundrum: I'd like to install your proposed change, but
> the sum total of your contributions to Emacs already exceeds the
> amount we can accept without legal papers.

Damn, sorry about that. You told me otherwise last time the question came up[1].

> So, unless you are willing
> to sign the papers now, we cannot install your change.

It's entirely your decision. I won't be signing the papers any time soon.

[1] https://lists.gnu.org/archive/html/emacs-devel/2018-03/msg00637.html




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Mon, 22 Jun 2020 15:45:02 GMT) Full text and rfc822 format available.

Notification sent to Richard Copley <rcopley <at> gmail.com>:
bug acknowledged by developer. (Mon, 22 Jun 2020 15:45:02 GMT) Full text and rfc822 format available.

Message #37 received at 41934-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Richard Copley <rcopley <at> gmail.com>
Cc: 41934-done <at> debbugs.gnu.org
Subject: Re: bug#41934: reverse-region no longer works
Date: Mon, 22 Jun 2020 18:43:55 +0300
> From: Richard Copley <rcopley <at> gmail.com>
> Date: Sat, 20 Jun 2020 11:03:34 +0100
> Cc: 41934 <at> debbugs.gnu.org
> 
> > Here's the conundrum: I'd like to install your proposed change, but
> > the sum total of your contributions to Emacs already exceeds the
> > amount we can accept without legal papers.
> 
> Damn, sorry about that. You told me otherwise last time the question came up[1].

That was before that additional contribution.

Anyway, I asked RMS, and he said we can accept this patch, since most
of your substantial contribution in the past is now superseded.  So I
installed your patch, and I'm closing the bug.

Thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 21 Jul 2020 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 336 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.