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 <phil.kiefer@gmail.com>
Link: https://orgmode.org/list/a2cc49d3-7f65-5f6a-8f05-21e5056335b3@gmail.com
This commit is contained in:
Ihor Radchenko 2023-01-20 13:05:08 +03:00
parent cf1ccc7154
commit c92769a505
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 17 additions and 3 deletions

View File

@ -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))

View File

@ -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"