all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philip K <philip@warpmail.net>
To: 39376@debbugs.gnu.org
Subject: bug#39376: [PATCH] Throw error when calling reverse-region on a single line
Date: Fri, 31 Jan 2020 22:26:24 +0100	[thread overview]
Message-ID: <20200131212624.4658-1-philip@warpmail.net> (raw)

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






             reply	other threads:[~2020-01-31 21:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31 21:26 Philip K [this message]
2020-02-15  8:51 ` bug#39376: [PATCH] Throw error when calling reverse-region on a single line 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

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

  git send-email \
    --in-reply-to=20200131212624.4658-1-philip@warpmail.net \
    --to=philip@warpmail.net \
    --cc=39376@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 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.