emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] [BUG] org.el: Fix first call of `org-paste-subtree'
Date: Mon, 29 Nov 2021 19:02:35 +0700	[thread overview]
Message-ID: <so2fh1$10kj$1@ciao.gmane.io> (raw)

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

An old bug is living in Org.

=C-c C-x C-y= ~org-paste-subtree~ fails just after Emacs start.
Maybe there are more similar issues.

- Start *new* instance of emacs.
- Copy some text that is Org subtree from some
   *external* application (not Emacs).
   I usually come across this issue when I copy capture
   from my Firefox extension. Alternative:
   #+begin_src elisp :results silent
     (require 'ob-shell)
   #+end_src

   #+begin_src bash :results silent
     printf '%b' '* Heading\n\nbody\n' |
       xclip -in -selection clipborad >/dev/null
       # xsel --input --clipboard
   #+end_src

- Try =C-c C-x C-y= or [[elisp:(org-paste-subtree)]]

   + Actual result is the following message:
     : user-error: The kill is not a (set of) tree(s).  Use ‘C-y’ to 
yank anyway
   + Expected result is a heading pasted at the end of the buffer.
   + The result may be achieved by calling [[elisp:(org-paste-subtree)]] 
once more.

- The problem is ~(and kill-ring (current-kill 0))~ expression
   in the definition of ~org-paste-subtree~.
   Restart emacs and repeat steps above skipping ~org-paste-subtree~.
   Notice that ~(current-kill 0)~ call changes value of ~kill-ring~.
   #+begin_src elisp :results pp
     (list (and kill-ring t) (current-kill 0) (and kill-ring t))
   #+end_src

   #+RESULTS:
   : (nil "* Heading\n\nbody\n" t)

I suppose, it is better to let the error from ~current-kill~ to 
propagate (in the case of empty `kill-ring' and clipboard). I do not 
have Windows machine available to test the change.

There is another occurence of ~(and (current-kill 0))~
in ~org-kill-is-subtree-p~. I would rather transform it
to ~org~subtree-p~ to avoid call of ~current-kill~ inside, but this 
patch does not include such change.

[-- Attachment #2: 0001-org.el-Fix-first-call-of-org-paste-subtree.patch --]
[-- Type: text/x-patch, Size: 1214 bytes --]

From 04bbf6359f370bddb6ca5fff1d8c7737e7ac5ee7 Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Mon, 29 Nov 2021 18:54:43 +0700
Subject: [PATCH] org.el: Fix first call of `org-paste-subtree'

* lisp/org.el (org-paste-subtree): Do not check `kill-ring' before
calling `current-kill' since the latter can pull content of clipboard.

First call of `org-paste-subtree' failed if nothing had been yanked
before since Emacs start but system clipboard had text with valid
subtree originating from other application.  The bug was where since
the commit adding `org-paste-subtree'.

If both `kill-ring' and system clipboard are empty then `current-kill'
generates meaningful error.
---
 lisp/org.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 025513e7a..55953e97b 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7774,7 +7774,7 @@ the inserted text when done.
 
 When REMOVE is non-nil, remove the subtree from the clipboard."
   (interactive "P")
-  (setq tree (or tree (and kill-ring (current-kill 0))))
+  (setq tree (or tree (current-kill 0)))
   (unless (org-kill-is-subtree-p tree)
     (user-error
      (substitute-command-keys
-- 
2.25.1


             reply	other threads:[~2021-11-29 12:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 12:02 Max Nikulin [this message]
2022-09-17 11:07 ` [PATCH] [BUG] org.el: Fix first call of `org-paste-subtree' Max Nikulin
2022-09-20 13:16 ` Ihor Radchenko
2022-09-20 17:11   ` Max Nikulin
2022-09-21  8:27     ` Ihor Radchenko
2022-11-01  1:45       ` Ihor Radchenko
2022-11-01 16:13         ` Max Nikulin

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='so2fh1$10kj$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --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).