emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* PATCH: Possibility to yank target of link at point to kill ring
@ 2019-01-10 21:37 Ivan Necas
  2019-01-10 22:09 ` Ivan Necas
  0 siblings, 1 reply; 2+ messages in thread
From: Ivan Necas @ 2019-01-10 21:37 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 222 bytes --]

Hi,

I often need to copy target of a link to kill ring, so I decided to
write a small function to do that.
Would it make sense to pull this into org-mode directly?

Thanks for consideration and potential review.

-- Ivan

[-- Attachment #2: 0001-org-Add-org-yank-link-at-point.patch --]
[-- Type: text/x-patch, Size: 1179 bytes --]

From 1f38afd4c26d2a8c6238040c6a40eb7dbd1f32ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ivan=20Ne=C4=8Das?= <necasik@gmail.com>
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 +++++++++
 1 file changed, 9 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)))
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: PATCH: Possibility to yank target of link at point to kill ring
  2019-01-10 21:37 PATCH: Possibility to yank target of link at point to kill ring Ivan Necas
@ 2019-01-10 22:09 ` Ivan Necas
  0 siblings, 0 replies; 2+ messages in thread
From: Ivan Necas @ 2019-01-10 22:09 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 361 bytes --]

I've added a test for the function as well.

-- Ivan

On Thu, 10 Jan 2019 at 22:37, Ivan Necas <necasik@gmail.com> wrote:
>
> Hi,
>
> I often need to copy target of a link to kill ring, so I decided to
> write a small function to do that.
> Would it make sense to pull this into org-mode directly?
>
> Thanks for consideration and potential review.
>
> -- Ivan

[-- Attachment #2: 0001-org-Add-org-yank-link-at-point.patch --]
[-- Type: text/x-patch, Size: 1865 bytes --]

From 28938924eaca1c5835b12e1e92d48eaf3443c058 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ivan=20Ne=C4=8Das?= <necasik@gmail.com>
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][Lin<point>k name]]"
+      (org-yank-link-at-point)
+      (current-kill 0)))))
+
 \f
 ;;; Node Properties
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-10 22:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10 21:37 PATCH: Possibility to yank target of link at point to kill ring Ivan Necas
2019-01-10 22:09 ` Ivan Necas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).