Is it possible to link to a function definition in a source code file, rather than a fixed line number?

  • Are you referring to external links like file:mysource_file.c:555? How should the link look like when jumping to a function my_function() in mysource_file.c instead of line 555 in that file? Note that the hook org-open-at-point-functions can be used to customize link behavior. Also new link types can be added using the org-add-link-type function Jun 21, 2017 at 20:46

3 Answers 3


Using the suggested global binding C-c l for storing a link when you are visiting any file (not just an org-mode file) and the one for inserting a link into an org file, C-c C-l, should work fine. It does not do the elisp find-function bit that John Kitchin describes in his answer, but it should be adequate for almost all situations. But you need org-context-in-file-links to be set to t: AFAICT that has been the default since 2008, but if you get line numbers instead of context in file links, check the setting of that variable.

  • Thanks for your answer. I already do this, but I'm looking for something more intelligent than a static line number to cope with when functions move around over time.
    – retrodev
    Jun 22, 2017 at 8:33
  • The links I get contain match patterns, not static line numbers. Try setting org-context-in-file-links to t.
    – NickD
    Jun 22, 2017 at 13:39
  • Edited the answer to add the info about org-context-in-file-links.
    – NickD
    Jun 22, 2017 at 14:23

For elisp that is certainly possible. The general strategy might be something like:

[[elisp:(find-function 'describe-function)]]

You could add a description if you wanted to also, e.g.

[[elisp:(find-function 'describe-function)][describe-function]]

For other languages it wouldn't be that easy. You can make a link like this:


which will open that file and search for the contents after the ::. Those contents are escaped.

  • Thanks, John. Is there anyway to capture the contents after::. when I capture the link. Perhaps by highlighting some text?
    – retrodev
    Jun 22, 2017 at 8:34
  • It looks like you can highlight some text in a file, and then type C-c l to store a link to that text. It is still search based. Is that what you mean? Jun 22, 2017 at 12:48

Yes, it is in fact possible to link directly to a help page, which should serve the purpose of linking to a function. Although it's not yet documented on https://orgmode.org/org.html#External-Links, the help: link type works, at least since 2016. For example, [[help:org-link-parameters]] links to the function where the help: link (and many of the other built-in ones) are defined. Furthermore, running org-store-link (C-c l) on a Help page will store a link to the Help page.

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.