Often times when doing research for a blog post I will collect a series of URLs that I could potentially use as a link in the post. Nothing new or exciting there; almost every blogger doubtlessly does the same thing.
There’s a minor annoyance though. I use Org mode to write my blog posts and while I’m still in the research phase it’s too early to turn a URL into an Org link. After all, I don’t yet know where the link will end up in the post or what the anchor text associated with it will be. Therefore when I’m actually writing the post I have to either edit the link by hand or snarf & barf the URL into Org mode’s link generation machinery.
To make the process a little easier, I wrote the following bit of Elisp. Putting the cursor on a URL and calling org-linkify will prompt for the anchor text and turn the URL into an Org link.
(defun org-linkify (label) "Turn a URL into an org-mode link." (interactive "sLabel: ") (let ((url (thing-at-point 'url)) (bnds (bounds-of-thing-at-point 'url))) (delete-region (car bnds) (cdr bnds)) (insert (concat "[[" url "][" label "]]"))))
With this code I can collect URLs in the Org mode file associated with the post and then either delete them or turn them into links as I write. I still have to move the URL to the proper place in the text of the post, of course, but org-linkify makes the rest of the process a bit easier.
Update: Daniel points out in the comments that Org mode already handles this use case with the normal link machinery.
I have a similar setup. I use an org-capture template to take whatever
is in the clipboard, download the html page this whatever points to,
(somewhat crudely) extract the content of the title tag and build an
org-link out of that and dump it in my master file.
I exclusively use that to collect a read-later list, but it could be
adapted to your purpose with a query for which buffer to store the
link in.
Additionally, I have a Firefox shortcut (y) to store the current URL
in the clipboard. Probably you could also use org-protocol to make it
even more accessible but I never got that to work.
You should perform `org-link-escape’ on the URL before you store it to buffer. Org performs the reverse `org-link-unescape’ if the link is opened. Otherwise you end up with a broken link if the original link contains percent encoded characters (cf. http://en.wikipedia.org/wiki/Percent-encoding).
Good point. I’d do that but as Daniel points out below, the normal Org link machinery will already handle my use case so the function isn’t needed at all.
Not sure it’s the exact same thing, but I use C-c C-l RET to do it.
I don’t remember the variable name to enable this but all my URLs typed in org-mode are automagically turned into links. So the only things left is to be able to rename that link. I put the point anywhere on the URL and do C-c C-l RET and enter the “Description”.
Nice. I didn’t realize that would work. I guess what happens is that typing the URL makes a link with the URL as the description too. Then when you do the Ctrl+c Ctrl+l it just updates the description. One less function to maintain in my
init.el.