5

Is there a function in elisp that will return the description of an internal org-mode link?

I would want this to work for any type of supported link:

[[link][description]]

[[description]]

Etc.

  • org-open-at-point has some goodies (inside) that you may wish to look at -- i.e., M-x find-function ... I tend to avoid most org-mode questions directly nowadays because everyone has a different version and the library is under constant development. – lawlist Jan 23 '18 at 2:31
4

I guess you want something like:

(defun get-description-at-point ()
  (interactive)
  (let ((link (org-element-context)))
    (message "%s" (buffer-substring (org-element-property :contents-begin link)
                                    (org-element-property :contents-end link)))))
1

You can also use regex to extract the link description:

(replace-regexp-in-string "\\(\\[\\[.*\\]\\[\\)\\(.*\\)\\]\\]" "[[\\2]]" "[[link][description]]")

will return [[description]]. If you omit the opening and closing braces in the second argument (that is, \\2), you will get description.

Note: I'm just beginning to use regex, so perhaps there are better solutions to set up the regex.

  • replace-regex-in-string -> replace-regexp-in-string – Hatshepsut Jul 8 '18 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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