emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: emacs-orgmode@gnu.org
Cc: Ihor Radchenko <yantar92@posteo.net>
Subject: [PATCH 1/4] Preserve active region after structure edits
Date: Sun, 15 Jan 2023 12:31:29 +0000	[thread overview]
Message-ID: <eda9909a905fe17e7efa5b7a59f26597d979677f.1673785107.git.yantar92@posteo.net> (raw)
In-Reply-To: <cover.1673785107.git.yantar92@posteo.net>

* lisp/org-list.el (org-list-indent-item-generic):
* lisp/org.el (org-do-promote):
(org-do-demote): Do not deactivate mark after edits.
(org-metadown):
(org-metaup): Do not deactivate mark and do not exchange point and
mark in region.
---
 lisp/org-list.el |  3 ++-
 lisp/org.el      | 64 ++++++++++++++++++++++++++++--------------------
 2 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 1fc99d070..9fa072ce7 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -2688,7 +2688,8 @@ (defun org-list-indent-item-generic (arg no-subtree struct)
                        (no-subtree (1+ (line-beginning-position)))
                        (t (org-list-get-item-end (line-beginning-position) struct))))))
       (let* ((beg (marker-position org-last-indent-begin-marker))
-	     (end (marker-position org-last-indent-end-marker)))
+	     (end (marker-position org-last-indent-end-marker))
+             (deactivate-mark nil))
 	(cond
 	 ;; Special case: moving top-item with indent rule.
 	 (specialp
diff --git a/lisp/org.el b/lisp/org.el
index 59fe3d2d3..58a3434f4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6579,7 +6579,8 @@ (defun org-do-promote ()
   (interactive)
   (save-excursion
     (if (org-region-active-p)
-	(org-map-region 'org-promote (region-beginning) (region-end))
+        (let ((deactivate-mark nil))
+          (org-map-region 'org-promote (region-beginning) (region-end)))
       (org-promote)))
   (org-fix-position-after-promote))
 
@@ -6590,7 +6591,8 @@ (defun org-do-demote ()
   (interactive)
   (save-excursion
     (if (org-region-active-p)
-	(org-map-region 'org-demote (region-beginning) (region-end))
+        (let ((deactivate-mark nil))
+          (org-map-region 'org-demote (region-beginning) (region-end)))
       (org-demote)))
   (org-fix-position-after-promote))
 
@@ -16884,21 +16886,25 @@ (defun org-metaup (&optional _arg)
    ((run-hook-with-args-until-success 'org-metaup-hook))
    ((org-region-active-p)
     (let* ((a (save-excursion
-		(goto-char (region-beginning))
-		(line-beginning-position)))
-	   (b (save-excursion
-		(goto-char (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))))
+                (goto-char (region-beginning))
+                (line-beginning-position)))
+           (b (save-excursion
+                (goto-char (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)))
+           (deactivate-mark nil)
+           (swap? (< (point) (mark))))
       (transpose-regions a b c d)
-      (goto-char c)))
+      (set-mark c)
+      (goto-char (+ c (- b a)))
+      (when swap? (exchange-point-and-mark))))
    ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
    ((and (featurep 'org-inlinetask)
          (org-inlinetask-in-task-p))
@@ -16917,21 +16923,25 @@ (defun org-metadown (&optional _arg)
    ((run-hook-with-args-until-success 'org-metadown-hook))
    ((org-region-active-p)
     (let* ((a (save-excursion
-		(goto-char (region-beginning))
-		(line-beginning-position)))
+                (goto-char (region-beginning))
+                (line-beginning-position)))
 	   (b (save-excursion
-		(goto-char (region-end))
-		(if (bolp) (1- (point)) (line-end-position))))
+                (goto-char (region-end))
+                (if (bolp) (1- (point)) (line-end-position))))
 	   (c (save-excursion
-		(goto-char b)
-		(move-beginning-of-line (if (bolp) 1 2))
-		(point)))
+                (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))))
+                (goto-char b)
+                (move-end-of-line (if (bolp) 1 2))
+                (point)))
+           (deactivate-mark nil)
+           (swap? (< (point) (mark))))
       (transpose-regions a b c d)
-      (goto-char d)))
+      (set-mark (+ 1 a (- d c)))
+      (goto-char (+ 1 a (- d c) (- b a)))
+      (when swap? (exchange-point-and-mark))))
    ((org-at-table-p) (call-interactively 'org-table-move-row))
    ((and (featurep 'org-inlinetask)
          (org-inlinetask-in-task-p))
-- 
2.39.0



  reply	other threads:[~2023-01-15 12:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-15 12:31 [PATCH 0/4] Structure editing when region is active Ihor Radchenko
2023-01-15 12:31 ` Ihor Radchenko [this message]
2023-01-15 12:31 ` [PATCH 2/4] Preserve active region when toggling heading state Ihor Radchenko
2023-01-15 12:31 ` [PATCH 3/4] org-metaup, org-metadown: Move subtrees in active region Ihor Radchenko
2023-01-15 12:31 ` [PATCH 4/4] org-manual.org: Document changes in 8f6fcd709, 5719a8163, and eda9909a9 Ihor Radchenko
2023-01-16  0:24 ` [PATCH 0/4] Structure editing when region is active Samuel Wales
2023-01-16 11:17   ` Ihor Radchenko
2023-01-17  1:45     ` Samuel Wales
2023-01-17  9:46       ` Ihor Radchenko
2023-01-18  1:11         ` Samuel Wales
2023-01-18 10:14           ` Ihor Radchenko
2023-02-04 22:45             ` Samuel Wales
2023-02-05 11:11               ` Ihor Radchenko
2023-02-04 13:54 ` Ihor Radchenko
2023-02-06 21:00   ` Rudolf Adamkovič
2023-02-07 10:56     ` Ihor Radchenko
2023-02-15 18:36       ` Rudolf Adamkovič
2023-02-15 20:35         ` Ihor Radchenko
2023-02-18 21:18           ` Philipp Kiefer
2023-04-02 14:19             ` Ihor Radchenko

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=eda9909a905fe17e7efa5b7a59f26597d979677f.1673785107.git.yantar92@posteo.net \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).