A region which contains source code of say Matlab can be marked and then executed. That is achieved by a engine (written in lisp) which connectsto the shell (I don't think this works in MS Windows). I am not sure that this works for other languages, but Matlab has the advantage of being a script language and not needing a compiler.
Isn't this what we can do with Sweave now? JMarc