emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: org-paste-subtree may delete headline at point [9.1.14 (release_9.1.14-961-g5abfde)]
@ 2018-10-04 17:05 Dale Sedivec
  2018-10-04 20:53 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Dale Sedivec @ 2018-10-04 17:05 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bug: org-paste-subtree may delete headline at point [9.1.14 (release_9.1.14-961-g5abfde)]
  2018-10-04 17:05 Bug: org-paste-subtree may delete headline at point [9.1.14 (release_9.1.14-961-g5abfde)] Dale Sedivec
@ 2018-10-04 20:53 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2018-10-04 20:53 UTC (permalink / raw)
  To: Dale Sedivec; +Cc: emacs-orgmode

Hello,

Dale Sedivec <dale@codefu.org> writes:

> 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.

Ouch. Thank you for spotting this and for the analysis. I applied
a patch in the line of what you suggested.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-04 20:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-04 17:05 Bug: org-paste-subtree may delete headline at point [9.1.14 (release_9.1.14-961-g5abfde)] Dale Sedivec
2018-10-04 20:53 ` Nicolas Goaziou

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