TransWikia.com

Copy-text-to-clipboard-link

Emacs Asked by Jens Lange on December 12, 2020

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.

One Answer

(eval-when-compile
  (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)
    (->
      1
      org-match-string-no-properties
      org-link-unescape)))

(defun ph/org-extract-link ()
  "Extract the link location at point and put it on the killring."
  (interactive)
  (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)

Correct answer by Phil Hudson on December 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP