branch: externals/org
commit c92769a505c6e16aef2ddbc3dcf0693c23296507
Author: Ihor Radchenko <[email protected]>
Commit: Ihor Radchenko <[email protected]>
org-paste-subtree: Do not leave empty line in place of level indicator
* lisp/org.el (org-paste-subtree): Remove the whole line when level
indicator is provided. Improve check for level indicator.
* testing/lisp/test-org.el (test-org/paste-subtree): Add test.
Reported-by: Philipp Kiefer <[email protected]>
Link:
https://orgmode.org/list/[email protected]
---
lisp/org.el | 7 ++++---
testing/lisp/test-org.el | 13 +++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index f6cad152b5..a7658c3ac4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7100,6 +7100,7 @@ When REMOVE is non-nil, remove the subtree from the
clipboard."
(old-level (if (string-match org-outline-regexp-bol txt)
(- (match-end 0) (match-beginning 0) 1)
-1))
+ level-indicator?
(force-level
(cond
(level (prefix-numeric-value level))
@@ -7107,7 +7108,7 @@ When REMOVE is non-nil, remove the subtree from the
clipboard."
;; headline, use the number of stars as the forced level.
((and (org-match-line "^\\*+[ \t]*$")
(not (eq ?* (char-after))))
- (org-outline-level))
+ (setq level-indicator? (org-outline-level)))
((looking-at-p org-outline-regexp-bol) (org-outline-level))))
(previous-level
(save-excursion
@@ -7129,8 +7130,8 @@ When REMOVE is non-nil, remove the subtree from the
clipboard."
(org-odd-levels-only nil)
beg end newend)
;; Remove the forced level indicator.
- (when (and force-level (not level))
- (delete-region (line-beginning-position) (point)))
+ (when level-indicator?
+ (delete-region (line-beginning-position) (line-beginning-position 2)))
;; Paste before the next visible heading or at end of buffer,
;; unless point is at the beginning of a headline.
(unless (and (bolp) (org-at-heading-p))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 7ed4ffd198..ed56fafab4 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -8617,6 +8617,19 @@ CLOSED: %s
(org-test-with-temp-text "*** <point>"
(org-paste-subtree nil "* Text")
(buffer-string))))
+ ;; Remove the indicator line completely.
+ (should
+ (equal "* Top
+text
+more text
+*** Text
+"
+ (org-test-with-temp-text "* Top
+text
+*** <point>
+more text"
+ (org-paste-subtree nil "* Text")
+ (buffer-string))))
;; Optional argument LEVEL forces a level for the subtree.
(should
(equal "* H\n*** Text\n"