Clickable links for Twitter handles in Emacs

| categories: emacs | tags:

Org-mode has clickable links, and they are awesome. You can make your own links, for example here is a link for twitter handles that opens a browser to the handle, and exports as an html link.

(org-add-link-type "twitter"
 (lambda (handle)
   (browse-url (concat "http://twitter.com/" handle)))
 (lambda (path desc backend)
   (format "<a href=\"http://twitter.com/%s\">%s</a>" path path)))

Check it out here: johnkitchin.

There is another alternative to make clickable text, and that is the button-lock package. You define a regular expression for the text you want to be clickable, and a function to run when it is clicked. Here is an example.

(require 'button-lock)
(global-button-lock-mode)

(button-lock-set-button
 "@\\([-a-zA-Z0-9_:]*\\)"
 (lambda ()
   (interactive)
   (re-search-backward "@")
   (re-search-forward  "@\\([a-zA-Z0-9_]*\\)")
   (let* ((handle (match-string-no-properties 1)))
     (browse-url (concat "http://twitter.com/" handle))))
 :face (list 'org-link))

Check it out: @johnkitchin. Of course, you can make your clicking function more sophisticated, e.g. to give you a menu of options , e.g. to send a tweet to someone, or open the web page, or look them up in your org-contacts. The differences between this and an org-mode link are that this works in any mode, and it has no export in org-mode, so it will go as plain text. Since this is just a feature for Emacs though, that should be fine.

Copyright (C) 2015 by John Kitchin. See the License for information about copying.

org-mode source

Org-mode version = 8.2.10

Discuss on Twitter