Hi, I think I may have found a bug in org-paste-subtree in master branch
where it will delete the content of the headline at point before yanking.
Steps to reproduce:

1. Start a fresh Emacs along the lines of:

mkdir /tmp/fake-home
cd /tmp/fake-home
git clone https://code.orgmode.org/bzg/org-mode.git
(cd org-mode && make autoloads)
HOME=/tmp/fake-home emacs -L /tmp/fake-home/org-mode/lisp

2. Create a new org file with the following contents:

* One
* Two
* Three

3. Move point to the "Two" headline, use C-c C-x C-w to kill it

4. Move point to *the end* of the "One" headline (first line)

5. Try to yank the "Two" headline: C-c C-x C-y (org-paste-special ->
org-paste-subtree)

Expected results (using ~~~~~~ as delimiters here):

~~~~~~
* One
* Two
* Three
~~~~~~

Observed results:

~~~~~~

* Two
* Three
~~~~~~

Note that all content on the "* One" line where we invoked
org-paste-subtree has been deleted.

I suspect the problem may be in org-paste-subtree.  Here's an excerpt that
calculates the value for force-level:

~~~~~~
  (force-level
   (cond
    (level (prefix-numeric-value level))
    ;; When point is right after the stars in an otherwise
    ;; empty headline, use stars as the forced level.
    ((and (looking-at-p "[ \t]*$")
  (string-match-p "^\\*+ *"
  (buffer-substring (line-beginning-position)
    (point))))
     (org-outline-level))
    ((looking-at-p org-outline-regexp-bol) (org-outline-level))))
~~~~~~

The comment says it's trying to identify an "empty headline", but the
combination of the two regexes there seems to simply confirm that point is
at EOL, ignoring white space, and that we're on a headline.  They seem to
do nothing to ensure that there is no content between the headline bullets
and EOL, so force-level becomes non-nil, which causes org-paste-subtree to
delete the contents of the line at point.

Assuming the comment's intent is correct, perhaps the
looking-at-p/string-match-p pair should just be replaced with something
like this?

(string-match-p "^\\*+\\s-*$" (buffer-substring (line-beginning-position)
(point)))

Version info:

Emacs  : GNU Emacs 26.1.50 (build 2, x86_64-apple-darwin17.7.0, NS
appkit-1561.60 Version 10.13.6 (Build 17G65))
 of 2018-08-31
Package: Org mode version 9.1.14 (release_9.1.14-961-g5abfde @
/tmp/orgbug/org-mode/lisp/)

Regards,
Dale

Reply via email to