0

I have an org table and I want to take an existing column of org links of the form:

[[http://blah.com/blah/blah/foo][foo]]

And create an adjacent column containing only the description - i.e. foo.

For example using a made-up function:

#+TBLFM: $4='(get-description-from-link $3)

I've looked at How can I get all file links in one org-mode file? and also the function:

org-link-get-parameter

These seem to be doing roughly what I want, but rely on parsing a whole buffer, where I only want to deal with a single column in a single table. Thus the function should take a link as a string of form [[link][desc]] and return desc.

The end goal is to make this a macro that creates the derived column, and copies its contents to another buffer, before deleting the derived column. Most of this seems possible apart from the table formula.

Any ideas?

1 Answer 1

1

You can use org-bracket-link-regexp for extracting the parts of bracket links:

   | link                                   | description                |
   |----------------------------------------+----------------------------|
   | [[http://blah.com/blah/blah/foo][foo]] | foo                        |
   | [[http://missing.description]]         | http://missing.description |
   #+TBLFM: $2='(let ((str $1)) (string-match org-bracket-link-regexp str) (or (match-string 3 str) (match-string 1 str)))

If you want to encapsulate the stuff in a function, just do it:

(defun get-description-from-link (str)
  "Get description from bracket link in STR."
  (string-match org-bracket-link-regexp str) (or (match-string 3 str) (match-string 1 str)))

Therewith the table would look as follows:

| link                                   | description                |
|----------------------------------------+----------------------------|
| [[http://blah.com/blah/blah/foo][foo]] | foo                        |
| [[http://missing.description]]         | http://missing.description |
#+TBLFM: $2='(get-description-from-link $1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.