emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ivan Necas <necasik@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: PATCH: Possibility to yank target of link at point to kill ring
Date: Thu, 10 Jan 2019 23:09:13 +0100	[thread overview]
Message-ID: <CAFmwT7VWxGezGFQe8CpkcUAZn9hsMaZrxbswXh18ELYHzdMoVg@mail.gmail.com> (raw)
In-Reply-To: <CAFmwT7V5mydcZ-nMUok1FXJ0Skj0o0036GOyr2FNnBd7o2wUTg@mail.gmail.com>

[-- 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


      reply	other threads:[~2019-01-10 22:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFmwT7VWxGezGFQe8CpkcUAZn9hsMaZrxbswXh18ELYHzdMoVg@mail.gmail.com \
    --to=necasik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).