I know the reverse is possible. You can insert source code blocks in org files. But how do I do the opposite?

I have figured out a way where I can insert a link to a line in a file in my source file comments. But as my org files grow and content is moved around that is not ideal. I need a nice way to link from source file comments to documentation written in org-mode. Something that links to a structure heading instead of absolute line number would be better.

If the exact opposite of the source code block in org-mode was not possible then some features of org-mode would be useful. I guess I could copy and paste tables from org-mode files. The most missed feature would be more robust links that are not so easily broken by growing and shrinking files.

I ended up adding these shortcuts. Experimenting with this feature I will see how I can improve it.

  (global-set-key (kbd "s-l s") 'org-store-link)
  (global-set-key (kbd "s-l i") 'org-insert-link)
  (global-set-key (kbd "s-l o") 'org-open-at-point)
  • See orgtbl mode and Tables in arbitrary syntax in the Org mode manual for how to deal with tables.
    – NickD
    Commented May 15, 2022 at 2:05
  • If you produce your source files by tangling source blocks in Org mode files, there is a way to add backlinks in comments: see in Extracting source code, the description of the :comments link header arg.
    – NickD
    Commented Apr 25 at 4:03

1 Answer 1


There is no general method for embedding one mode into a section of another mode. Org mode supports source code blocks as you mention, but take note that the content of the source block is not in a different mode. If you put some python into a source block in an org file, the whole buffer is in org-mode and that includes the python code inside the source block.

That said, there are various minor modes that you can activate to get parts of org-mode’s functionality. For example, if you want to use a table in some other mode then you can use orgtbl-mode. See chapter 3.4 The Orgtbl Minor Mode of the Org Mode manual for information about how to turn it on, and how to use it when the table must be embedded inside another syntax.

If you just want links to headlines, that is already a supported feature. In fact, it is the default when you call org-store-link with point on a headline. However, that link will break if you edit the headline or move it to a different file. If you set org-id-link-to-org-use-id then creating a link to a headline will add an ID property to it, if it doesn’t already have one, and then create a link to the ID instead. This link will work even if the headline is edited or moved to another file. See chapter 4.5 Handling Links for all the different types of links that you can create with org-store-link.

As usual you can consult this manual within Emacs. Open the Info viewer with C-h i and it will show you a list of manuals.

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.