all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#39376: [PATCH] Throw error when calling reverse-region on a single line
@ 2020-01-31 21:26 Philip K
  2020-02-15  8:51 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Philip K @ 2020-01-31 21:26 UTC (permalink / raw)
  To: 39376

The current implementation of reverse region will delete everything
following the current line, if the region marks only a part of a
line. This is because the algorithm implemented below accidentally
deletes all following lines, and fails before being able to reinsert
them.

This patch sends an error (could be changed to an user-error) in that
case, as it makes no sense for a single line to be reversed.
---
 lisp/sort.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/sort.el b/lisp/sort.el
index 6ea1c44060..8848c5bf24 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -543,6 +543,8 @@ reverse-region
   (if (> beg end)
       (let (mid) (setq mid end end beg beg mid)))
   (save-excursion
+    (when (< (line-beginning-position) beg end (line-end-position))
+      (error "Cannot reverse a single line"))
     ;; 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)
-- 
2.20.1






^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#39376: [PATCH] Throw error when calling reverse-region on a single line
  2020-01-31 21:26 bug#39376: [PATCH] Throw error when calling reverse-region on a single line Philip K
@ 2020-02-15  8:51 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2020-02-15  8:51 UTC (permalink / raw)
  To: Philip K; +Cc: 39376-done

> From: Philip K <philip@warpmail.net>
> Date: Fri, 31 Jan 2020 22:26:24 +0100
> 
> The current implementation of reverse region will delete everything
> following the current line, if the region marks only a part of a
> line. This is because the algorithm implemented below accidentally
> deletes all following lines, and fails before being able to reinsert
> them.
> 
> This patch sends an error (could be changed to an user-error) in that
> case, as it makes no sense for a single line to be reversed.

Thanks.  I installed a slightly different change, because the command
would still delete the following lines if only BEG or END (bit not
both) was not at a line beginning/end.

I also fixed the doc string and the comments there.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-15  8:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-31 21:26 bug#39376: [PATCH] Throw error when calling reverse-region on a single line Philip K
2020-02-15  8:51 ` Eli Zaretskii

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.