Polymode is an emacs package that offers generic support for multiple major modes inside a single emacs buffer.
Polymode provides a framework for editing documents that combine multiple languages in a single file. Typical uses include markdown or LaTeX documents that include source code blocks. Polymode allows the user to edit the markdown or LaTeX text in the appropriate mode (ie., markdown-mode or AucTex), and seamlessly switches to the appropriate programming mode for the source code blocks.
Polymode also provides support for compiling documents, with configurable export functions. This allows the user to export a markdown or LaTeX document, along with its embedded source code, into a pdf or html document that includes the results of running the source code.