emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] [BUG] org.el: Fix first call of `org-paste-subtree'


From: Ihor Radchenko
Subject: Re: [PATCH] [BUG] org.el: Fix first call of `org-paste-subtree'
Date: Wed, 21 Sep 2022 16:27:38 +0800

Max Nikulin <manikulin@gmail.com> writes:

>> The main problem the old code solves is working around user error when
>> kill-ring is empty. We do not really want to err in such cases; just
>> handle empty kill ring specially.
>
>  From my point of view "kill ring is empty" user error clearly describes 
> what happens in such case, so I do not see any point to spit suggestion 
> to try simple yank instead.

>> I agree that (and kill-ring ...) condition misses the system clipboard.
>> The proper way to handle this issue is explicitly catching "Kill ring is
>> empty" error thrown by `current-kill' (i.e. `condition-case').
>
> Why do you believe that just allowing to propagate this error is worse?

I agree with you for `org-paste-subtree', but not for
`org-kill-is-subtree-p' and `org-capture-fill-template'. The two latter
ones also use (and kill-ring ...).

>> We have 3 occurrences of (and kill-ring (current-kill 0)) constructs in
>> the code and may fix the problem either by replacing each instance with
>> `condition-case' or we may create a separate macro/function in org-macs
>> and use it.
>
> Other cases (such as the one at the end of `org-paste-subtree' to 
> determine if yanked text should be folded) require more care.

This particular case, kill-ring test appears to be unnecessary (see
snippet below). current-kill should return non-nil because otherwise
"The kill is not a (set of) tree(s)" error would be thrown earlier.

(when (and (not for-yank) ; in this case, org-yank will decide about folding
                  kill-ring
                  (equal org-subtree-clip (current-kill 0))
                  org-subtree-clip-folded)
         ;; The tree was folded before it was killed/copied
         (org-fold-subtree t))

The other piece (when remove (pop kill-ring)) is indeed trickier and we
may need to test (equal org-subtree-clip (current-kill 0)) like the
above.

-- 
Ihor Radchenko,
Org mode contributor,
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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]