Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

Use Org-Mode Links for Absolutely Anything

The Power of Org-links post series

One little-know feature of org-mode is that you can define new types of links with the aptly named org-add-link-type. The applications of this virtue are many. One might, for instance, write links which search an entire code base for an expression.

(org-add-link-type
 "grep" 'endless/follow-grep-link)

(defun endless/follow-grep-link (regexp)
  "Run `rgrep' with REGEXP as argument."
  (grep-compute-defaults)
  (rgrep regexp "*" (expand-file-name "./")))

Then, when you click on something like the following link in an org-mode buffer, you'll be taken to a list of results.

** TODO Refactor [[grep:OldClassName][OldClassName]] into NewClassName 

LINK header arguments

As /u/blue1_ points out, for links that are simple URL substitutions you can also use #+LINK headers.

#+LINK: isbn http://www.amazon.com/dp/%s

Tag Searches

For another use case, the following code defines links which search your headlines for specific tags.

(org-add-link-type
 "tag" 'endless/follow-tag-link)

(defun endless/follow-tag-link (tag)
  "Display a list of TODO headlines with tag TAG.
With prefix argument, also display headlines without a TODO keyword."
  (org-tags-view (null current-prefix-arg) tag))

Then, merely write your links as

[[tag:work+phonenumber-boss][Optional Description]]

The syntax allowed, described here, is the same used for the org-tags-view command.

comments powered by Disqus