[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-27 b392c9f: Fix 'reverse-region' when less than one line is in reg
From: |
Eli Zaretskii |
Subject: |
emacs-27 b392c9f: Fix 'reverse-region' when less than one line is in region |
Date: |
Sat, 15 Feb 2020 03:49:27 -0500 (EST) |
branch: emacs-27
commit b392c9f365d081d98d9fbad5d54cadb7b9be15af
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>
Fix 'reverse-region' when less than one line is in region
* lisp/sort.el (reverse-region): Signal a user-error if the region
includes less than one full line, thus avoiding an inadvertent
deletion of text following the current line. Fix the doc string.
Fix comments to start with a capital letter. (Bug#39376)
---
lisp/sort.el | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/lisp/sort.el b/lisp/sort.el
index 40347e6..e4ff2af 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -544,23 +544,30 @@ Use \\[untabify] to convert tabs to spaces before
sorting."
;;;###autoload
(defun reverse-region (beg end)
"Reverse the order of lines in a region.
-From a program takes two point or marker arguments, BEG and END."
+When called from Lisp, takes two point or marker arguments, BEG and END.
+If BEG is not at the beginning of a line, the first line of those
+to be reversed is the line starting after BEG.
+If END is not at the end of a line, the last line to be reversed
+is the one that ends before END."
(interactive "r")
(if (> beg end)
(let (mid) (setq mid end end beg beg mid)))
(save-excursion
- ;; put beg at the start of a line and end and the end of one --
- ;; the largest possible region which fits this criteria
+ (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)
(or (bolp) (forward-line 1))
(setq beg (point))
(goto-char end)
- ;; the test for bolp is for those times when end is on an empty line;
+ ;; The test for bolp is for those times when end is on an empty line;
;; it is probably not the case that the line should be included in the
;; 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))
- ;; the real work. this thing cranks through memory on large regions.
+ ;; The real work. This thing cranks through memory on large regions.
(let (ll (do t))
(while do
(goto-char beg)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- emacs-27 b392c9f: Fix 'reverse-region' when less than one line is in region,
Eli Zaretskii <=