emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dale Sedivec <dale@codefu.org>
To: emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <CAEj9N4JR8LB+PC_NeaXYAxap6imLUG2nu5piGyjeuLfqk0zU-w@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2327 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 3860 bytes --]

             reply	other threads:[~2018-10-04 17:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 17:05 Dale Sedivec [this message]
2018-10-04 20:53 ` Bug: org-paste-subtree may delete headline at point [9.1.14 (release_9.1.14-961-g5abfde)] Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEj9N4JR8LB+PC_NeaXYAxap6imLUG2nu5piGyjeuLfqk0zU-w@mail.gmail.com \
    --to=dale@codefu.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).