I would like to copy a defined text-link to the clipboard by mouse-1 or C-c,C-o. Something like file+sys: that just does not open the file it should copy the following text to the clipboard. Is a function like that in org-mode or emacs?

Background story: I use Emacs on windows which is a nightmare itself, but due to external conditions I have to use windows. Some month ago I came to the conclusion that cygwin emacs-w32 has some advantages over ntemacs, like working pdf-tools, therfore I use that. But emacs-w32 sees cygwin as it's "OS". This means a lot of w32-stuff like org-outlook gets broken. Fixing all that is beyond my abilities. Now I came to conclusion that a half-automatic, using a copy-text-to-clipboard-link which is pasted manually where I need it, is at least better than nothing at all.

1 Answer 1

  (require 'anaphora) ; for the `awhen' macro
  (require 'dash)) ; for the `->' "threading" macro

(defun ph/org-extract-link-no-kill ()
  "Extract the link location at point."
  (when (org-in-regexp org-bracket-link-regexp 1)

(defun ph/org-extract-link ()
  "Extract the link location at point and put it on the killring."
  (awhen (ph/org-extract-link-no-kill)
    (kill-new it)
    (message "Copied \"%s\"." it)))

(define-key org-mode-map (kbd "C-c o") #'ph/org-extract-link)
  • This works great using interal links. Didn't think that custom functions using external packages are needed to provide that seemingly simple functionality. Thanks for that useful lisp code.
    – Jens Lange
    Commented Jun 25, 2016 at 2:18
  • Strictly speaking those external packages are not necessary -- it is possible to rewrite the code without them. I think the idioms they provide are optimal (easier to write, easier to read) so I try to promote them, hoping others will agree and adopt them too. Commented Jun 26, 2016 at 8:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.