2

I'd like my kill ring to remain unaffected when I kill an org-capture invocation.

  1. put a URL in my OS clipboard (and thus kill ring)
  2. org-capture and start to create a bookmarks entry
  3. cancel org-capture for whatever reason with C-c C-k
  4. [CURRENT BAD BEHAVIOR] try again -- uh oh, my kill ring has been polluted by the text of the canceled org-capture session!
  5. [DESIRED GOOD BEHAVIOR] try again with the same clipboard/kill-ring contents I had as of [2]

How do I achieve this in idiomatic org-mode elisp?

2
  • The current behavior is baked-in: see the call to kill-region in org-capture-finalize - kill-region will always add the text to the kill ring. You could change that to delete-region in your copy of org-capture.el but that is probably not a good idea. The function called when you press C-c C-k is org-capture-kill and there is a somewhat cryptic comment that leads me to believe that this is a known ... Commented Oct 16 at 16:15
  • ... problem, so I would suggest that you submit a bug report to the Org mode mailing list with M-x org-submit-bug-report - that might prompt the devs to re-examine the behavior. Commented Oct 16 at 16:17

1 Answer 1

0

My current workaround is to advise org-capture-kill with a function that mutates the kill ring (hopefully) back to the state it was previously.

(defun dl/advice:pop-kill-ring ()
  ;; Motivation: org-capture adds canceled capture text to kill-ring :(
  ;; see https://emacs.stackexchange.com/questions/85137/how-to-configure-org-capture-to-not-add-canceled-capture-text-to-kill-ring
  ;; impl from https://stackoverflow.com/a/13142796/706499
  (when kill-ring
    (setq kill-ring (cdr kill-ring)))
  (when kill-ring-yank-pointer
    (setq kill-ring-yank-pointer kill-ring)))

(advice-add 'org-capture-kill :after #'dl/advice:pop-kill-ring)

If org-mode ever fixes/changes the underlying behavior (and I don't notice) this will of course lead me to pull my hair out in frustration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.