emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org d73688faa4 1/2: org-paste-subtree: Fix pasting when


From: ELPA Syncer
Subject: [elpa] externals/org d73688faa4 1/2: org-paste-subtree: Fix pasting when point is on heading but not at bol
Date: Fri, 19 Apr 2024 09:58:44 -0400 (EDT)

branch: externals/org
commit d73688faa4b5e130e9f92534a947f6f675c4a5ab
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-paste-subtree: Fix pasting when point is on heading but not at bol
    
    * lisp/org.el (org-paste-subtree): When point is on heading, but not
    at bol, paste using heading level minimal between current heading
    level and next visible heading level.
    * testing/lisp/test-org.el (test-org/paste-subtree): Add test cases.
    
    Reported-by: Philipp Kiefer <phil.kiefer@gmail.com>
    Link: https://orgmode.org/list/878rhxtszb.fsf@localhost
---
 lisp/org.el              |  7 +++----
 testing/lisp/test-org.el | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index a53f36d334..b6717066c5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7332,13 +7332,12 @@ When REMOVE is non-nil, remove the subtree from the 
clipboard."
              ((looking-at-p org-outline-regexp-bol) (org-outline-level))))
            (previous-level
             (save-excursion
-              (org-previous-visible-heading 1)
+              (unless (org-at-heading-p) (org-previous-visible-heading 1))
               (if (org-at-heading-p) (org-outline-level) 1)))
            (next-level
             (save-excursion
-              (if (org-at-heading-p) (org-outline-level)
-                (org-next-visible-heading 1)
-                (if (org-at-heading-p) (org-outline-level) 1))))
+              (org-next-visible-heading 1)
+              (if (org-at-heading-p) (org-outline-level) 1)))
            (new-level (or force-level (max previous-level next-level)))
            (shift (if (or (= old-level -1)
                           (= new-level -1)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 8db0bcb3bc..36f4d796b9 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -9372,6 +9372,24 @@ CLOSED: %s
          (org-test-with-temp-text "* H1\n<point>\n** H2"
            (org-paste-subtree nil "* Text")
            (buffer-string))))
+  ;; When point is on heading at bol, insert before
+  (should
+   (equal "* Text\n* H1\n** H2"
+         (org-test-with-temp-text "<point>* H1\n** H2"
+           (org-paste-subtree nil "*** Text")
+           (buffer-string))))
+  ;; When point is on heading but not at bol, use smallest level among
+  ;; current heading and next, inserting before the next heading.
+  (should
+   (equal "* H1\ncontents\n** Text\n** H2"
+         (org-test-with-temp-text "* H1<point>\ncontents\n** H2"
+           (org-paste-subtree nil "*** Text")
+           (buffer-string))))
+  (should
+   (equal "*** H1\ncontents\n*** Text\n* H2"
+         (org-test-with-temp-text "*** H1<point>\ncontents\n* H2"
+           (org-paste-subtree nil "* Text")
+           (buffer-string))))
   ;; When on an empty heading, after the stars, deduce the new level
   ;; from the number of stars.
   (should



reply via email to

[Prev in Thread] Current Thread [Next in Thread]