From 28938924eaca1c5835b12e1e92d48eaf3443c058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ne=C4=8Das?= Date: Thu, 10 Jan 2019 22:21:38 +0100 Subject: [PATCH] org: Add org-yank-link-at-point * lisp/org.el (org-yank-link-at-point): New function to yank the target of a link at point to kill ring. TINYCHANGE --- lisp/org.el | 9 +++++++++ testing/lisp/test-org.el | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index ea1607d85..6d13d8c92 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9791,6 +9791,15 @@ Use TAB to complete link prefixes, then RET for type-specific completion support ;; Redisplay so as the new link has proper invisible characters. (sit-for 0))) +(defun org-yank-link-at-point () + "Yank target of a link at point" + (interactive) + (if (org-in-regexp org-bracket-link-regexp 1) + (let ((link (match-string-no-properties 1))) + (kill-new link) + (message "Link '%s' yanked" link)) + (user-error "No link found"))) + (defun org-link-try-special-completion (type) "If there is completion support for link type TYPE, offer it." (let ((fun (org-link-get-parameter type :complete))) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 976b7d8d6..82f50cf45 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -2724,6 +2724,15 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/" (equal (format "[[file:%s][file:%s]]" file file) (org-store-link '(16)))))))) +(ert-deftest test-org/yank-link-at-point () + "Test `org-yank-link-at-point' specifications." + (should + (equal + "https://orgmode.org" + (org-test-with-temp-text "[[https://orgmode.org][Link name]]" + (org-yank-link-at-point) + (current-kill 0))))) + ;;; Node Properties -- 2.20.1