For example:

* Purpose
Keep some notes to elisp functions.

[[link:elisp-func][elisp-func help]]

I want to open the link via C-c C-o which would show a buffer with help as though I had ran instead:

C-h f elisp-func RET.

I'm not sure what the right format for the link would be though. I'm suspecting it might be elisp itself, but haven't found the right way to do it.


There is. See (info "(org) External Links"):

  • More direct than elisp evaluation and avoids the confirmation question. I forgot about help links. Thanks!
    – NickD
    Nov 14 '20 at 15:52
  • 1
    Sorry, didn't see this before I wrote my answer. :(
    – Omar
    Nov 14 '20 at 18:33

You can execute arbitrary elisp code from a link:

[[elisp:(message "Hello")][Greeting]]

Clicking on the link runs the code and you get a greeting in the echo area.

All you have to do is figure out what code to run. The first step is to find out the keybinding of C-h f, so do C-h c C-h f RET and you see that C-h f is bound to the command describe-function. Now you can do C-h f describe-function RET to get help for this command and find out how to call it. It says that it takes a symbol as argument, e.g. (describe-function 'describe-function) gives you the same help. So you could say:

[[elisp:(describe-function 'find-file)][Help for find-file]]

to do what you asked for.

There are two annoyances:

  • you need a separate link for each separate function whose doc string you want to examine. I don't know about you but I'd rather do C-h f and enter which function I'm interested in. Or put the cursor on the name and do C-h f, so even if I write notes about a function, all I need is the name of the function and the doc string is a couple of keystrokes away.

  • when you click on an elisp link, you are asked for confirmation. That's a security precaution: you want to look at the code and make sure that there is nothing dangerous there (either by design or by accident). Being able to execute arbitrary code at the click of a link is dangerous. You can customize the variable org-link-elisp-confirm-function to modify this behavior, but check its docstring and heed the warning.

  • I did start down this path and did hit both the annoyances you mention. The write up is good. In the end I went with the answer [[help:elisp-func][elisp-func]] suggested below.
    – lucidquiet
    Nov 15 '20 at 20:01
  • Yes, I thought it was the better answer too!
    – NickD
    Nov 15 '20 at 21:54

The built-in help link type is made for this purpose. Your example would be written as: [[help:elisp-func][elisp-func help]].

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.