Browse Source

Fix `org-metaup' and `org-metadown' on regions

* lisp/org.el (org-metaup): Do not leave a character behind when
  transposing regions.
(org-metadown): Fix "Transposed regions overlap" error.

Reported-by: Adam Porter <adam@alphapapa.net>
<http://lists.gnu.org/r/emacs-orgmode/2018-06/msg00184.html>
Nicolas Goaziou 2 years ago
parent
commit
b3981d6ad0
1 changed files with 28 additions and 12 deletions
  1. 28 12
      lisp/org.el

+ 28 - 12
lisp/org.el

@@ -19791,12 +19791,20 @@ for more information."
   (cond
    ((run-hook-with-args-until-success 'org-metaup-hook))
    ((org-region-active-p)
-    (let* ((a (min (region-beginning) (region-end)))
-	   (b (1- (max (region-beginning) (region-end))))
-	   (c (save-excursion (goto-char a)
-			      (move-beginning-of-line 0)))
-	   (d (save-excursion (goto-char a)
-			      (move-end-of-line 0) (point))))
+    (let* ((a (save-excursion
+		(goto-char (min (region-beginning) (region-end)))
+		(line-beginning-position)))
+	   (b (save-excursion
+		(goto-char (max (region-beginning) (region-end)))
+		(if (bolp) (1- (point)) (line-end-position))))
+	   (c (save-excursion
+		(goto-char a)
+		(move-beginning-of-line 0)
+		(point)))
+	   (d (save-excursion
+		(goto-char a)
+		(move-end-of-line 0)
+		(point))))
       (transpose-regions a b c d)
       (goto-char c)))
    ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
@@ -19813,12 +19821,20 @@ commands for more information."
   (cond
    ((run-hook-with-args-until-success 'org-metadown-hook))
    ((org-region-active-p)
-    (let* ((a (min (region-beginning) (region-end)))
-	   (b (max (region-beginning) (region-end)))
-	   (c (save-excursion (goto-char b)
-			      (move-beginning-of-line 1)))
-	   (d (save-excursion (goto-char b)
-			      (move-end-of-line 1) (1+ (point)))))
+    (let* ((a (save-excursion
+		(goto-char (min (region-beginning) (region-end)))
+		(line-beginning-position)))
+	   (b (save-excursion
+		(goto-char (max (region-beginning) (region-end)))
+		(if (bolp) (1- (point)) (line-end-position))))
+	   (c (save-excursion
+		(goto-char b)
+		(move-beginning-of-line (if (bolp) 1 2))
+		(point)))
+	   (d (save-excursion
+		(goto-char b)
+		(move-end-of-line (if (bolp) 1 2))
+		(point))))
       (transpose-regions a b c d)
       (goto-char d)))
    ((org-at-table-p) (call-interactively 'org-table-move-row))