From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dale Sedivec Subject: Bug: org-paste-subtree may delete headline at point [9.1.14 (release_9.1.14-961-g5abfde)] Date: Thu, 4 Oct 2018 12:05:06 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000003d5f0705776a2a88" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g874N-0007xi-No for emacs-orgmode@gnu.org; Thu, 04 Oct 2018 13:05:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g874L-0003Uh-5Z for emacs-orgmode@gnu.org; Thu, 04 Oct 2018 13:05:47 -0400 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]:38589) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g874K-0003RK-Bt for emacs-orgmode@gnu.org; Thu, 04 Oct 2018 13:05:44 -0400 Received: by mail-qt1-x829.google.com with SMTP id l9-v6so10689745qtf.5 for ; Thu, 04 Oct 2018 10:05:43 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --0000000000003d5f0705776a2a88 Content-Type: text/plain; charset="UTF-8" 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 --0000000000003d5f0705776a2a88 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 ya= nking.=C2=A0 Steps to reproduce:

1. Start a fresh Emacs = along the lines of:

mkdir /tmp/fake-home
cd /tmp/fake-home
(cd org-mode && make autoloads)
HOME=3D/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 t= he "Two" headline, use C-c C-x C-w to kill it

4. Move point to *the end* of the "One" headline (first lin= e)

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

<= div>Expected results (using ~~~~~~ as delimiters here):

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

Observed results:

~~= ~~~~

* Two
* Three
= ~~~~~~

Note that all content on the "* One&qu= ot; line where we invoked org-paste-subtree has been deleted.
I suspect the problem may be in org-paste-subtree.=C2=A0 Here&#= 39;s an excerpt that calculates the value for force-level:

~~~~~~
=C2= =A0 (force-level
=C2=A0 = =C2=A0(cond
=C2=A0 =C2=A0= (level (prefix-numeric-value level))
=C2=A0 =C2=A0 ;; When point is right after the stars in an oth= erwise
=C2=A0 =C2=A0 ;; e= mpty headline, use stars as the forced level.
=C2=A0 =C2=A0 ((and (looking-at-p "[ \t]*$")=
=C2=A0 (string-match-p = "^\\*+ *"
= =C2=A0 (buffer-substring (line-beginning-position)
=C2=A0 =C2=A0 (point))))
=C2=A0 =C2=A0 =C2=A0(org-outline-level))
=C2=A0 =C2=A0 ((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.=C2=A0 They seem to do nothing to ensure that there is no= content between the headline bullets and EOL, so force-level becomes non-n= il, which causes org-paste-subtree to delete the contents of the line at po= int.

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=C2=A0 : GN= U Emacs 26.1.50 (build 2, x86_64-apple-darwin17.7.0, NS appkit-1561.60 Vers= ion 10.13.6 (Build 17G65))
=C2=A0of 2018-08-31
Package:= Org mode version 9.1.14 (release_9.1.14-961-g5abfde @ /tmp/orgbug/org-mode= /lisp/)

Regards,
Dale
<= /div>
--0000000000003d5f0705776a2a88--