[email protected] archives
 help / color / mirror / Atom feed
From: Ihor Radchenko <[email protected]>
To: jman <[email protected]>
Cc: "Jacob S. Gordon" <[email protected]>, [email protected]
Subject: Re: org-refile confusing refiling
Date: Sun, 20 Jul 2025 13:36:57 +0000	[thread overview]
Message-ID: <87y0sjnfxj.fsf@localhost> (raw)
In-Reply-To: <[email protected]>

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

jman <[email protected]> writes:

> I don't have the context to figure out things further, all I could do was disabling xclip-mode 
> around executing `org-refile`:
>
> --8<---------------cut here---------------start------------->8---
> ;; disable xclip-mode before executing org-refile
> (advice-add 'org-refile :before (lambda (&rest _)
>                                  (when xclip-mode
>                                    (xclip-mode -1))))
>
> ;; enable xclip-mode again after executing org-refile
> (advice-add 'org-refile :after (lambda (&rest _)
>                                  (when (not xclip-mode)
>                                    (xclip-mode t))))
> --8<---------------cut here---------------end--------------->8---
>
> Ihor, any thoughts on this?

Can you try the attached patch?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-refile-Do-not-assume-that-kill-ring-cannot-chang.patch --]
[-- Type: text/x-patch, Size: 2320 bytes --]

From a75e575a0ae8172d0d50c738d67b36f518ad5f98 Mon Sep 17 00:00:00 2001
Message-ID: <a75e575a0ae8172d0d50c738d67b36f518ad5f98.1753018325.git.yantar92@posteo.net>
From: Ihor Radchenko <[email protected]>
Date: Sun, 20 Jul 2025 15:30:33 +0200
Subject: [PATCH] org-refile: Do not assume that kill ring cannot change under
 our feet

* lisp/org-refile.el (org-refile): Store region to be refiled in
variable rather than relying upon it being held as the first entry in
the kill ring.

Reported-by: jman <[email protected]>
Link: https://orgmode.org/list/[email protected]
---
 lisp/org-refile.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/org-refile.el b/lisp/org-refile.el
index 5caed50a6..4bca6ee85 100644
--- a/lisp/org-refile.el
+++ b/lisp/org-refile.el
@@ -484,7 +484,7 @@ (defun org-refile (&optional arg default-buffer rfloc msg)
 	   (region-start (and regionp (region-beginning)))
 	   (region-end (and regionp (region-end)))
 	   (org-refile-keep (if (equal arg 3) t org-refile-keep))
-	   pos it nbuf file level reversed)
+	   pos it nbuf file level reversed tree)
       (setq last-command nil)
       (when regionp
 	(goto-char region-start)
@@ -557,6 +557,9 @@ (defun org-refile (&optional arg default-buffer rfloc msg)
 		  (org-kill-new (buffer-substring region-start region-end))
 		  (org-save-markers-in-region region-start region-end))
 	      (org-copy-subtree 1 nil t))
+            ;; We cannot rely on the kill remaining intact before we
+            ;; paste.  See https://orgmode.org/list/[email protected]
+            (setq tree (current-kill 0))
             (let ((origin (point-marker)))
               ;; Handle special case when we refile to exactly same
               ;; location with tree promotion/demotion.  Point marker
@@ -583,7 +586,7 @@ (defun org-refile (&optional arg default-buffer rfloc msg)
 		     (goto-char (point-min))
 		     (or (outline-next-heading) (goto-char (point-max)))))
 	         (unless (bolp) (newline))
-	         (org-paste-subtree level nil nil t)
+	         (org-paste-subtree level tree nil t)
 	         ;; Record information, according to `org-log-refile'.
 	         ;; Do not prompt for a note when refiling multiple
 	         ;; headlines, however.  Simply add a time stamp.
-- 
2.50.1


[-- Attachment #3: Type: text/plain, Size: 223 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

  parent reply	other threads:[~2025-07-20 13:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-27 22:28 org-refile confusing refiling jman
2025-05-28 17:58 ` Jacob S. Gordon
2025-05-29 18:28   ` jman
2025-05-29 20:02     ` Jacob S. Gordon
2025-05-30 13:53       ` jman
2025-05-30 22:14         ` Jacob S. Gordon
2025-07-20 13:36         ` Ihor Radchenko [this message]
2025-08-07 21:49           ` Jacob S. Gordon
2025-08-10 12:32             ` jman
2025-08-10 13:37               ` Ihor Radchenko
2025-08-13 14:14                 ` Jacob S. Gordon
2025-10-18 15:00                 ` Ihor Radchenko
2025-10-24 22:23                   ` jman via General discussions about Org-mode.
2025-10-25  9:06                     ` Ihor Radchenko
2025-10-26 13:42                       ` jman via General discussions about Org-mode.
2025-10-27 18:41                         ` Ihor Radchenko

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=87y0sjnfxj.fsf@localhost \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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.
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).